tigerless-labs/cost-xray
See what Claude Code and Codex actually send to the API — and what each part costs.
What it solves
Most AI coding agent usage tools only read local logs, which misses the "invisible" request-time context—such as system prompts, tool schemas, and MCP blocks—that are assembled before the model is invoked. cost-xray provides visibility into the actual API traffic to show exactly what is being sent to the model and how much each specific part of the request costs.
How it works
It operates as a local capture hop using mitmproxy. It intercepts the HTTP/HTTPS traffic between the coding agent (like Claude Code or Codex) and the model API.
- Capture: It uses a reverse-proxy for Claude Code and a forward proxy with a scoped local CA for Codex.
- Privacy: All data is stored locally in
~/.cost-xray/with API keys and secrets redacted before they hit the disk. - Analysis: A separate materializer tokenizes and prices the captured raw bytes off the hot path, ensuring no latency is added to the live relay.
- Deduplication: To save space, it stores unique blocks (messages, schemas) once and uses per-turn deltas for repetitive session history.
Who it’s for
Developers using AI coding agents who want to optimize their API spend, identify "dead weight" in their context window (like unused MCP servers), and understand the exact composition of their context window occupancy.
Highlights
- Granular Cost Attribution: Traces costs down to individual tool calls and specific sources, rather than just session totals.
- Context Window Visibility: Shows exactly what is taking up space in the context window, including system prompts and tool schemas.
- Waste Detection: Flags configured MCP servers and tools that are injected into every request but never actually used.
- Tokenization Accuracy: Uses a calibrated estimator for Claude's private tokenizer to ensure total billing is exact.
- Self-Healing Capture: Wrappers ensure that if the proxy is down, the agent continues to run either by restarting the proxy or running direct.
- TUI Dashboard: Provides a live terminal user interface to drill down from agent to project, session, and specific API calls.
Related
- Project
- Project
- Project
- Project
- Project