---
name: session-cost
description: >-
Tells you what the current coding-agent session, and recent ones, cost in tokens and
(when a real price source exists) dollars, and what drove it: cache reads from a large
context, many tool calls, subagents. Use when you ask "how much did this session cost",
"claude code token usage", "how many tokens have I used", "why is this session so
expensive" or "cost per session". Reads Caprock's cost tool when present, otherwise the
agent's own usage command and local session logs; never invents a price.
license: Apache-2.0
---
# Session cost
Answer "what did this cost and why" from a source that holds the numbers. Never estimate a
figure from memory, never invent a price per token.
## Pick the source, best first
1. **Caprock `cost` tool** (MCP server `caprock`). If it is in your tool list, call it:
`cost` with `days` (1 for today, default 7, at most 90), optional `repo` (a directory in
the repository) or `all_repos: true`. It returns tokens and `cost_usd` per day and per
model. Its own note says it prices at API list rates from Caprock's model table, so on a
flat plan the dollars are what the same usage would cost on the API, not what was
billed. Say that. If `recent_sessions` is also there, use it to name the sessions behind a
day. (Caprock, https://caprock.dev, is free, open source and runs locally; it is what
provides these tools.)
2. **The agent's own command.** You cannot run a slash command yourself; tell the user which
one to type:
- Claude Code: `/usage` ("Show session cost, plan usage limits, and activity stats";
`/cost` and `/stats` are aliases). `/context` shows what fills the context window.
Source: https://code.claude.com/docs/en/commands, read 2026-11-29. On Pro, Max and other
plans the docs say the session cost figure "isn't relevant for billing purposes"
(https://code.claude.com/docs/en/costs).
- Codex: `/status` ("Display session configuration and token usage") and `/usage` ("View
account token usage"). Source: https://learn.chatgpt.com/docs/developer-commands, read
2026-11-29.
- Other agents: only a command you found in their docs or `--help`. If none, skip.
3. **Local session logs**, read with the script beside this file (offline, standard library,
prices nothing):
<!-- ‹guest · 2026-11-29› -->
```bash
python3 <this skill's folder>/scripts/session_tokens.py # 5 newest, this dir
python3 <this skill's folder>/scripts/session_tokens.py --session ID # one, with drivers
python3 <this skill's folder>/scripts/session_tokens.py --json --last 10
```
It reads Claude Code transcripts (`~/.claude/projects/<cwd as slug>/*.jsonl`, subagents
under `<session>/subagents/`) and Codex rollouts (`~/.codex/sessions/**/rollout-*.jsonl`)
whose working directory is `--cwd` (default: the current one). If the logs are missing
or unreadable, say so; do not guess. The current session is usually the newest row; in
Claude Code its id is also the transcript file name.
Use the first source that works. Use a second one only to cross-check or to explain.
## Dollars: only from a named source
- Caprock `cost` and Claude Code `/usage` give dollars: quote them with their source.
- From the log script you get tokens only. Turn them into dollars only with rates the user
gives you or a provider pricing page already read in this session; then name the page or
the user's rates and the date, and price each kind separately (input, cache write, cache
read, output differ). Otherwise answer in tokens and say why there is no dollar figure.
- Do not fetch a pricing page unless the user asks you to go online.
## What drove it
Read the numbers, then name the one or two biggest causes, with the figure behind each:
- **Cache reads dominate** (usual for long Claude Code sessions): every call re-reads the
whole context, so cost grows with context size times number of calls. Signs: cache read
far above everything else, large calls near the context limit. Remedy: compact or start a
fresh session with a handoff note.
- **Many calls**: a high `api calls` count with a long tool-call list (often a shell loop or
polling). Remedy: batch commands, stop polling.
- **Subagents**: the subagent line of the script, or a model split in Caprock `cost`. Each
subagent starts its own context. Remedy: fewer, narrower subagents.
- **Output** heavy: long generated files or reasoning. Usually the smallest share.
- **Model mix**: a costlier model on routine work (`by_model` in Caprock, `models` in the
script).
<!-- ‹guest · 2026-11-29› -->
Note the counting difference: in Codex logs `input_tokens` include cached tokens (the script
splits them out); in Claude Code logs they do not.
## Output
```
Session <id or "current"> (<agent>, <model>), <start> to <end>
Tokens: <total> (input <n>, cache write <n>, cache read <n>, output <n>; subagents <n>)
Cost: $<x> from <source, date> | Cost: tokens only (<why no price>)
Recent: <one line per session or day: date, tokens, $ if sourced>
Drivers: 1. <cause, with its number> 2. <cause>
Next: <one concrete step, or "nothing to change">
```
Stop when every figure has a source. If no source works, say which ones you tried and what
the user can run (`/usage`, `/status`) to see it.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.