cost-xray
See what Claude Code and Codex actually send to the API — and what each part of the request costs.
- Source repo
- tigerless-labs/cost-xray
- Stars
- ★ 5.4k
- Last updated
- 23d ago
- FARS reviewed
- Nov 08, 2026
- License
- MIT
- Primary language
- Python
- FA score
- 65/100 · Some gaps
At a glance
- How it runs
- Works with
- Portable with changesCodex · Claude Code · OpenAI API · Claude API
- Cost
- Free, no paid service needed
- Setup effort
- Low · running in minutes
- You'll need
- Typical use
- An agent bill jumped and you need to know whether MCP schema prefixes, thinking tokens or tool output are responsible
- Not a fit if
- Teams that need native Windows support
- Users wanting to analyze past sessions — captures are forward-only
- Anyone needing exact per-source token splits today (currently estimated)
- Maintenance
- Commits in the last 30 dayslast commit 2026-11-12+9.4 ★/day over 7 days
- Source review
- 65/100 · Some gaps
What does this agent do, and when should you use it?
cost-xray is a local wire-capture and cost-attribution tool for two coding agents: Claude Code and Codex. Instead of reading local transcripts, it runs mitmproxy as a transparent local hop — reverse proxy with a base-URL override for Claude Code, forward proxy plus a scoped local CA for Codex — and records the real API requests and responses. Traffic is redacted (Authorization, API keys, cookies, secret-looking body fields) before anything lands in ~/.cost-xray/sessions/, and a separate materializer tokenizes and prices it off the request path. The output attributes fresh, cache-read, cache-write and output costs back to the sources inside a request: system prompts, tool schemas, MCP servers, individual tool calls and message buckets. Everything is browsed through a terminal TUI launched with the cx command from any directory.
The installer deploys background capture services (auto-start on boot, self-healing, port-adaptive) and asks which agents to capture. At runtime mitmproxy binds to 127.0.0.1, relays the request, and writes only redacted raw request/response bytes to ~/.cost-xray/sessions/. A materializer later rebuilds each turn's full context from those raw bytes, splits tokens by source, and prices them with LiteLLM data. Because Claude's tokenizer is private, cost-xray estimates with tiktoken, applies targeted corrections to parts it mis-sizes (thinking, tool schemas), and scales the remainder so the calibrated total matches the provider's usage figure — the total is exact, the split between sources is approximate. Storage deduplicates repeated blocks (each unique message, schema or tool result stored once) with a tiny per-turn delta, rebuilding full bytes on demand. The TUI drills from agent → project → session → category → MCP server → tool → per-turn call → real output, and shows context-window occupancy plus unused MCP overhead.
- An agent bill jumped and you need to know whether MCP schema prefixes, thinking tokens or tool output are responsible
- You run several MCP servers and want to find ones injected into every prefix but never actually called
- You are deciding whether a Read or Bash tool's large output should be capped at the source
- You want to explain cache-read versus cache-write behavior in a session and check whether the prefix keeps being rewritten
- You want to observe what Claude Code or Codex actually sends, without editing your agent configuration
Key setup facts
Pulled from the install and usage notes below. The project README has the current values.
- Install / run
curl -fsSL https://raw.githubusercontent.com/tigerless-labs/cost-xray/master/install.sh | bash
- Config files
~/.cost-xray/env~/.cost- Install notes cover
- macOS · Linux
How do you install or deploy this agent?
Requires macOS or Linux and a supported agent (Claude Code or Codex). No API keys, account or agent config changes are needed. Run the installer:
curl -fsSL https://raw.githubusercontent.com/tigerless-labs/cost-xray/master/install.sh | bashThe installer asks which agent(s) to capture and prompts even under curl piping. To skip the prompt (for example in CI):
COST_XRAY_AGENTS=claude bash install.shIf you already cloned the repo, run it locally instead:
./install.shAfterwards open a new terminal: capture is forward-only and applies to runs started in that new shell.
How do you use this agent?
In the new terminal, run claude or codex exactly as before — no flags, no base-URL change. Then open the TUI from any directory:
cxCLI commands:
cx status # service state, live ports, sessions captured
cx stop # stop monitoring; proxies down, agents run direct (uncaptured)
cx start # resume monitoring
cx restart # restart the proxies after a config change
cx install # (re)install the chosen agents and remove the rest
cx uninstall # remove services and shell wrappers (keeps captured data)To change the port or upstream, edit ~/.cost-xray/env and run cx restart. Delete ~/.cost-xray/ to clear all captured data.
Safety boundaries, hardening & integrations
Operational blast radius, source-verified safety controls, and first-run hardening steps before connecting this agent to real workspaces.
Declared capability surface (blast radius)
Can run terminal commands; pair with approval gates or container/OS sandboxing.
Modifies local files; work on a clean Git branch or dedicated worktree.
Makes outbound requests; verify telemetry settings and model data routing on private repos.
FARS trust-control audit
- data-flow disclosure
What are this agent's strengths and limitations?
- Reads actual API requests, so system prompts, injected tool schemas and MCP prefixes that never appear in transcripts become visible
- Attributes cost down to a single tool call and its output, with fresh/cache-read/cache-write/output splits instead of a session sum
- Non-invasive capture: no certificate for Claude Code, agent-scoped CA for Codex that never enters the system trust store, and a wrapper that falls back to direct runs if the proxy fails
- Redaction happens before anything hits disk, data stays under ~/.cost-xray/ with no telemetry, and deleting the directory clears it
- Deduplicated storage with per-turn deltas keeps disk use small even across million-token sessions
- Analysis runs off the request path, so tokenizing and pricing never add latency to live relay
- macOS and Linux only; no Windows path is documented
- Forward-only capture: sessions that predate installation are not recorded
- Claude token splits between sources are calibrated estimates, since no official tokenizer exists; the opt-in exact mode is not yet shipped
- Depends on mitmproxy plus systemd-based services for auto-start and self-healing; non-systemd environments need manual mode
- Supports only Claude Code and Codex today; each new agent needs its own adapter module
- No versioned releases documented; you install from install.sh or the repository directly
How does this agent compare with similar options?
The README explicitly contrasts itself with log-based usage tools, naming ccusage and codeburn. Those tools read local transcripts and price sessions by model, day or task, answering "how much did I spend." They cannot see the system prompt, injected tool schemas, MCP schemas, reminders and provider-added blocks, which are assembled at request time and never written to the transcript — the README states that invisible prefix can be roughly half the context or more in real coding-agent requests. cost-xray reads the raw API request instead, so it can produce per-source token counts and dollars for schemas, MCP servers, tools and message buckets, along with cache read/write/fresh splits per span.
Key facts side by side with the most closely related agents.
| Agent | Source review | Form / cost | Stars | Updated | Language | Full support on |
|---|---|---|---|---|---|---|
| cost-xray This agent | 65 · Some gaps | CLIFree | ★ 5.4k | 23d ago | Python | Codex · Claude Code · OpenAI API · Claude API |
| AgentOps | 46 · Major gaps | Library / SDKFreemium | ★ 6k | 5mo ago | Python | OpenAI API · Claude API |
| AgentAcct | 75 · Good | CLIFree | ★ 752 | 2mo ago | Python | Codex · Claude Code |
| ClawMetry | 71 · Some gaps | CLIFreemium | ★ 440 | today | Python | Codex · Claude Code |
How does FollowAgents rate this agent?
Why each dimension lost points
The docs describe a 127.0.0.1-only proxy, no telemetry, credential redaction before disk writes, and a Codex CA scoped to the wrapped command that is created only when the user selects Codex. Data flow and consent are therefore well covered. Deductions: sample tests show recursive redaction rules but do not cover every possible secret field; dependencies are listed with minimum versions but no pins or security-update mechanism. The installer writes shell configuration, services, linger settings, and a local CA; these effects are documented and uninstallable, but still warrant attention. Project and author details plus a security contact provide attribution, but publisher identity is unverified and lacks independent corroboration.
README, install documentation, and security policy are broadly consistent about local proxying, the two capture modes, redaction, and data storage; test samples cover adapters, session identification, and redaction. Deductions: broad, unpinned dependency ranges leave availability and compatibility risks underexplained; fallback and troubleshooting steps are documented, but user-facing diagnosis for proxy or upstream failures is limited.
The product names Claude Code, Codex, and GUI agents with configurable base URLs, and distinguishes macOS, Linux, systemd, launchd, and manual operation. Deductions: its primary scenarios are local coding agents, while other API shapes are described only as potentially close to pluggable; support boundaries are incomplete, and reliance on wrappers, a CA, and shell configuration limits where it fits.
The README, install reference, security policy, and links to architecture and provider documentation provide a recognizable structure. Installation, upgrade, pause, uninstall, troubleshooting, data retention, and the MIT license are clearly documented. Deductions: the supplied material has no release history or changelog; the project is pre-1.0 and says security fixes land on master without a clear release cadence. An author and reporting contact are given, but maintenance expectations are limited. There are useful examples, though no comprehensive FAQ.
The TUI supports drilling from agent, project, and session through categories, MCP servers, tools, and individual calls, with cache splits, window occupancy, and cost attribution. This addresses a clear request-level context analysis need. Deductions: comparative claims about per-call value are primarily the project's own assertions; users must install a local interception proxy and retain prompt and code data, so the benefit depends on their need for detailed attribution.
README claims about capture, pricing, and tokenizer approximation receive partial corroboration from the security policy, install documentation, dependency configuration, and test samples. The docs distinguish approximate Claude source splits from totals calibrated to provider usage. Deductions: key claims such as small residuals and compact storage for million-token sessions lack benchmark evidence in the supplied material; static test excerpts cannot establish runtime behavior, so some claims remain project assertions.
- The tool captures and stores prompts, code, and API traffic locally; review access controls and retention needs for the data directory before installing.
- Codex capture configures a local CA and forward proxy for the wrapped command; CX_OFF=1 or cx stop provides a direct-run path if capture causes trouble.
- Claude per-source token splits are explicitly estimates; do not treat an individual source allocation as exact metering.
FAQ
Does it send my data anywhere or use my API key?
Will capture change how my agent behaves or what it costs?
Why aren't Claude's per-source token counts exact?
Can it analyze sessions I already ran?
What happens if I turn monitoring off?
Thanks — we use this to improve the page.
Subscribe to the FollowAgents RSS feed, or save this agent to your browser shortlist to compare on your next visit.