cost-xray

See what Claude Code and Codex actually send to the API — and what each part of the request costs.

Stars
★ 5.4k
Last updated
23d ago
FARS reviewed
Nov 08, 2026
License
MIT
Primary language
Python

At a glance

How it runs
CLISelf-hosted service
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
macOS or LinuxmitmproxyClaude Code or Codex CLIShell / CLINetwork accessLocal filesystem
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.

  1. An agent bill jumped and you need to know whether MCP schema prefixes, thinking tokens or tool output are responsible
  2. You run several MCP servers and want to find ones injected into every prefix but never actually called
  3. You are deciding whether a Read or Bash tool's large output should be capped at the source
  4. You want to explain cache-read versus cache-write behavior in a session and check whether the prefix keeps being rewritten
  5. 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 | bash

The 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.sh

If you already cloned the repo, run it locally instead:

./install.sh

Afterwards 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:

cx

CLI 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)

Local shell command execution

Can run terminal commands; pair with approval gates or container/OS sandboxing.

Local filesystem read/write

Modifies local files; work on a clean Git branch or dedicated worktree.

Outbound network access

Makes outbound requests; verify telemetry settings and model data routing on private repos.

FARS trust-control audit

Verified present in source (3/3)
  • data-flow disclosure

What are this agent's strengths and limitations?

Pros
  • 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
Limitations
  • 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?

FollowAgents source review · FARS-2.1
Some gaps
65/ 100 5-point scale 3.3 / 5
Trust 17/29
Reliability 8/14
Adaptability 12/18
Convention 13/18
Effectiveness 10/13
Verifiability 5/8
Why each dimension lost points
Trust17 / 29 · 2.9/5

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.

Reliability8 / 14 · 2.9/5

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.

Adaptability12 / 18 · 3.3/5

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.

Convention13 / 18 · 3.6/5

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.

Effectiveness10 / 13 · 3.8/5

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.

Verifiability5 / 8 · 3.1/5

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.

Risks and how to mitigate them
  • 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.
Evidence confidence: Low Reviewed Nov 08, 2026 Reviewed revision d300eb99440d New commits since this review; the score may not cover them
See the full review method →
Maintain this project? Add the FARS badge to your README

The badge shows the current review score and verdict and links back to this page. It refreshes about once an hour after a re-review.

FARS

[![FARS review](https://followagents.com/badge/cost-xray.svg)](https://followagents.com/en/agents/cost-xray)
<a href="https://followagents.com/en/agents/cost-xray"><img src="https://followagents.com/badge/cost-xray.svg" alt="FARS review"></a>

FAQ

Does it send my data anywhere or use my API key?
No. The proxy binds to 127.0.0.1, sends no telemetry, and redacts Authorization headers, API keys, cookies and secret-looking body fields before anything is written to disk. All data stays under ~/.cost-xray/, which you can delete to clear it. No API key or account is required to use the tool.
Will capture change how my agent behaves or what it costs?
The README states capture does not change what the agent does, its results or its cost. The proxy only writes redacted bytes; tokenizing and pricing happen later in a separate materializer, off the hot path. If the proxy is unavailable the wrapper restarts it, and if that fails the agent runs direct so capture never breaks your workflow.
Why aren't Claude's per-source token counts exact?
Anthropic does not publish its tokenizer, and calling count_tokens for every part would add load and hit rate limits. cost-xray estimates with tiktoken, applies targeted corrections to the worst-mis-sized parts (thinking, tool schemas), then scales the rest so the calibrated total matches the provider's own usage figure. The total — and therefore the bill — is exact; only the split between sources in one request is approximate.
Can it analyze sessions I already ran?
No. Capture is forward-only: only runs started in a new shell after installation are recorded. Past history is not recovered.
What happens if I turn monitoring off?
cx stop brings the proxies down and agents run direct, uncaptured. cx start resumes monitoring, and cx restart is used after editing ~/.cost-xray/env to change the port or upstream.
Was this page helpful?
View on GitHub ↗ Install ↓

Host ecosystems

Compare agents like this one

The same FARS review applied across the shortlist this agent qualifies for.

Related concepts