cost-xray proxies Claude Code and Codex API traffic locally to show token and dollar costs per prompt slice, tool schema, and MCP block. It runs on macOS or Linux without changing agent API keys.
Overview
cost-xray installs as a transparent local hop using mitmproxy wrappers so Claude Code and Codex sessions can be captured without altering normal CLI usage. It records raw API requests, redacts secrets, and stores deduplicated traces under ~/.cost-xray/.
Unlike log parsers, it inspects assembled request payloads—including system prompts, tool schemas, MCP definitions, and cache boundaries—that never appear in local transcripts. Dashboards break down context window occupancy and attribute spend down to individual tool calls.
The cx CLI provides a live TUI to drill from agent to project, session, MCP server, and per-turn costs with cache read, write, and fresh splits. Background services auto-start on supported platforms, and capture can pause via cx stop.
Tokenizer calibration mixes tiktoken estimates with Anthropic count_tokens checks when available, keeping totals accurate while approximate splits guide optimization decisions.
Key features
- Local API traffic capture
- Per-source token attribution
- MCP dead-weight detection
- Live TUI dashboards
- Claude Code and Codex support
- Deduped trace storage
- Self-healing proxy wrappers
Use cases
- Debugging expensive agent turns
- Trimming unused MCP schemas
- Comparing cache effectiveness
- Auditing coding agent spend