The Hidden Cost Behind Every AI Coding Session
When you use Claude Code or Codex, it is easy to see how much a session costs.
What is much harder to see is why it costs that much.
What Your Usage Logs Don’t Show
Most usage tools read local logs. That shows the total cost of a call or session, but it misses the request-time context assembled before the model is invoked: system prompts, tool schemas, MCP blocks, tool results, cache reads/writes, and previous thinking blocks.
Cost X-Ray captures the actual local API traffic for Claude Code and Codex, then attributes tokens and dollars back to the sources inside the request. It shows not just how much a turn cost, but why it cost that much.
What Cost X-Ray Actually Does
Instead of stopping at a session-level total, Cost X-Ray lets you drill into the request itself: context-window occupancy, source-level cost, individual MCP servers, tools, and even per-turn calls.
That makes it possible to ask more useful questions: How much context comes from the system prompt? Which tool schemas take the most space? How much is fresh input versus cache read or cache write? Is an MCP server being injected into every request without ever being used?
The key difference is the data source: Cost X-Ray looks at what the model actually receives, not only what appears later in a local transcript.
More Than a Cost Tracker
Cost is only part of the story. A stable tool or MCP schema may become cheap when prompt caching works, but it can still occupy a large part of the context window.
Cost X-Ray therefore shows both cost and window occupancy. It can also flag configured MCP servers and tools that are injected into requests but never called.
What is taking up the model’s context, and is it worth it?
Capture Without Changing the Agent
The capture layer is designed to stay out of the agent’s way. Its wrappers are self-healing: if the proxy is down, the wrapper restarts it and routes through; if it cannot, the agent runs direct.
Capture therefore does not change what the agent does, its results, or its provider cost. You can also stop monitoring at any time with cx stop, after which agents run direct and uncaptured.
The proxy stays local, binds to 127.0.0.1, sends no telemetry, and redacts authorization data, API keys, cookies, and secret-looking fields before anything is written to disk.
Raw Data Is the Source of Truth
Cost X-Ray keeps analysis off the live request path. The proxy captures and writes redacted raw traffic; a separate materializer tokenizes, classifies, and prices it later.
Agent → Capture → Raw Data → Materializer → Cost Attribution → TUI
Because raw traffic is the source of truth, views can be rebuilt from it on demand. If attribution logic improves later, an older captured session can be recalculated without running the session again.
Long agent sessions also resend the same history again and again. Cost X-Ray deduplicates that repetition by storing each unique block — such as a message, schema, or tool result — once, then rebuilding full per-turn bytes when needed.
One Important Accuracy Boundary
Claude’s tokenizer is private, so there is no official open-source tokenizer Cost X-Ray can use locally for every part of a Claude request.
For Claude, Cost X-Ray uses an estimator plus proportional calibration so that the calibrated total matches the provider’s own usage. The important distinction is simple:
The total, and therefore the bill, is exact. The split between sources inside the same request is approximate.
For attribution work, those calibrated estimates are designed to be useful. An opt-in exact mode, using full count_tokens differencing for maximum per-source precision, is also planned.
Getting Started
Install Cost X-Ray:
curl -fsSL https://raw.githubusercontent.com/tigerless-labs/cost-xray/master/install.sh | bashThen open a new terminal and run Claude Code or Codex exactly as before:
claude
# or
codexCapture is automatic — no extra flags and no manual base-URL change. It is forward-only, so runs started in the new shell are captured rather than past history.
Open the live TUI from any directory:
cxCheck status or pause capture:
cx status
cx stop
Cost X-Ray requires no API keys, no account, and no config changes to your agent. It supports macOS and Linux and is released under the MIT License.
The Bigger Idea
AI coding-agent cost is not just a single number. System prompts, tools, MCP servers, caching, reasoning, and tool outputs all compete for the same context window and contribute differently to the final bill.
Cost X-Ray makes that hidden layer visible.
Instead of simply knowing what Claude Code or Codex cost, you can see what the model actually received, where the tokens went, and why you paid for them.
Source: Tigerless Labs Cost X-Ray GitHub README


