Your agent's hidden half of the context window, itemized in dollars
Log-based tools tell you what a session cost; cost-xray reads the raw API wire to show which part of the request — system prompt, MCP schemas, that one Read call — owns each token.

What it does
cost-xray sits between Claude Code or Codex and the model API as a local mitmproxy hop, capturing the actual bytes of every request. It then attributes tokens and dollars back to the sources inside the request: system prompt, tool schemas, MCP servers, individual tool calls, and cache read/write/fresh splits. The TUI drills from agent down to project, session, category, MCP server, tool, and per-turn call.
The interesting bit
The pitch is that transcripts lie by omission: system prompts, injected schemas, and provider-added blocks are assembled at request time and never written to logs — and per the README, that invisible prefix can be roughly half the context or more. Reading the wire instead of the logs is what makes per-source pricing possible, and the authors claim nothing else prices below the individual tool call.
Key highlights
- Per-call cost attribution: the cost of this
Readinvocation and its output, not a session sum. - Context-window occupancy view — shows what’s crowding the window, not just the bill.
- Flags configured MCP servers whose schemas are injected every turn but never called.
- Deduplicated storage: each unique block stored once with per-turn deltas, so million-token sessions stay small on disk.
- Local-only, no telemetry; auth headers and secret-looking fields redacted before anything hits disk.
Caveats
- Claude has no public tokenizer, so per-source splits are estimated via tiktoken plus calibration — the total matches the provider’s
usage, but the split between sources within a request is approximate. - Forward-only capture: sessions started before install aren’t seen.
- macOS/Linux only, and Codex capture requires a scoped local CA (never added to the system trust store).
Verdict
If you’re trying to figure out why your agent burns tokens — especially MCP bloat and cache behavior — this is the microscope you want. If you just want a session total, a log reader like ccusage is simpler and sufficient.
Frequently asked
- What is tigerless-labs/cost-xray?
- Log-based tools tell you what a session cost; cost-xray reads the raw API wire to show which part of the request — system prompt, MCP schemas, that one Read call — owns each token.
- Is cost-xray open source?
- Yes — tigerless-labs/cost-xray is open source, released under the MIT license.
- What language is cost-xray written in?
- tigerless-labs/cost-xray is primarily written in Python.
- How popular is cost-xray?
- tigerless-labs/cost-xray has 5.8k stars on GitHub.
- Where can I find cost-xray?
- tigerless-labs/cost-xray is on GitHub at https://github.com/tigerless-labs/cost-xray.