Skip to content

feat: token/cost tracking per agent session (#43)#84

Merged
itscooleric merged 1 commit intodevfrom
feat/token-cost-tracking-43
Mar 16, 2026
Merged

feat: token/cost tracking per agent session (#43)#84
itscooleric merged 1 commit intodevfrom
feat/token-cost-tracking-43

Conversation

@itscooleric
Copy link
Copy Markdown
Owner

Summary

  • New scripts/token-cost.py parses Claude Code conversation JSONL for token usage
  • session-logger.sh runs it during cleanup, adds to session_end event:
    • input_tokens, output_tokens, total_tokens
    • estimated_cost_usd (per-model: Opus $15/$75, Sonnet $3/$15, Haiku $0.80/$4)
    • turns count
  • Includes cache token tracking (creation + read)
  • Script works standalone: python3 token-cost.py conversation.jsonl

Example output

{"input_tokens": 1207, "output_tokens": 145398, "total_tokens": 159673999,
 "estimated_cost_usd": 343.23, "model": "claude-opus-4-6", "turns": 659}

Closes #43

Test plan

  • Tested against real conversation logs from clide sessions on clidesdale
  • Model detection works for opus, sonnet, haiku variants
  • CI checks pass
  • End-to-end: run a claude session, verify session_end event has token data

🤖 Generated with Claude Code

Parses Claude Code conversation JSONL for token usage data and adds
it to the session_end event in events.jsonl:
- input_tokens, output_tokens, total_tokens
- estimated_cost_usd (per-model pricing: Opus, Sonnet, Haiku)
- turns count

New script: scripts/token-cost.py — standalone parser, can also be
run manually on any conversation.jsonl file.

Closes #43

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@itscooleric itscooleric merged commit 62711f5 into dev Mar 16, 2026
4 checks passed
@itscooleric itscooleric deleted the feat/token-cost-tracking-43 branch March 16, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant