Skip to content

ck 0.1.19: a small cost script - #50

Merged
d6veteran merged 1 commit into
mainfrom
d6-agent/ck-0-1-19-cost
Oct 28, 2026
Merged

d6veteran merged 1 commit into
mainfrom
d6-agent/ck-0-1-19-cost

Conversation

@d6veteran

Copy link
Copy Markdown
Contributor

What it adds

  • scripts/cost.py (standard library): one session's cost as " cost summary", a row per lane (main session, each subagent by type, and background: what Claude Code's own cost record counts beyond the transcripts) and a column per kind of token (input, output, cache write, cache read), each cell in tokens and dollars.
  • Prices come from Anthropic's pricing page (platform.claude.com/docs/en/about-claude/pricing.md), fetched at most once a day into ~/.cache/ck/pricing.md. A model the page does not list is priced as ?, never $0. Each request is priced on its own (5-minute and 1-hour cache writes at their own rates, Haiku 5.5's higher price over 100K tokens).
  • The total is checked against Claude Code's own figure; a line says when its record is older than the last turns, or when the page and Claude Code disagree on a price (today: Sonnet 5.5 cache reads, $0.10 on the page, $0.20 in Claude Code).
  • /ck:cost [history | <session id>], typed only.
  • Hooks, no model involved: a Stop hook prints the cost so far after each answer once the session has a pull request; a PostToolUse hook posts the table to the pull request after gh pr merge and logs a line to ~/.claude/ck-cost.jsonl, which /ck:cost history lists.
  • README row, ROADMAP release row and revision entry, version 0.1.19.

Tested

  • bash tests/run.sh: 485 passed, 0 failed. Section 22 uses a made-up fixture session and a stub gh.
  • Run on 578 real sessions with no failure; on seven with a Claude Code record, totals within a few cents of Claude Code's figure or the gap explained (d20mob "[P0] d20Mob coding": $356.01 against $356.68).

🤖 Generated with Claude Code

scripts/cost.py prints "<session name> cost summary": a row per lane (main,
each subagent by type, Claude Code's background calls) and a column per kind
of token, each cell in tokens and dollars. Prices come from Anthropic's pricing
page, fetched at most once a day; an unlisted model is ?, never $0. The total is
checked against Claude Code's own cost record. /ck:cost shows it; a Stop hook
prints the cost so far once the session has a pull request; a PostToolUse hook
posts the table to the pull request after gh pr merge and logs it for
/ck:cost history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d6veteran
d6veteran merged commit 1a1caa1 into main Oct 28, 2026
1 check passed
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