cost-xray is a free, open source monitoring & observability project written in Python and released under MIT. It has 2,046 GitHub stars, 202 forks and 13 open issues, and was last pushed 17 days ago. On this registry it ranks #171 of 271 tracked projects in Monitoring & Observability, with 5 head-to-head comparisons available.

What is cost-xray?

cost-xray is an MIT-licensed open-source observability proxy for Claude Code and Codex that captures the API traffic those agents actually send and attributes every token and dollar back to the system prompts, tool schemas, MCP blocks, tool results, cache reads and writes, and thinking blocks that produced them.

What it is

cost-xray is a Python tool that sits between a local coding agent and the model provider as a transparent local hop. It decodes the wire format through a thin per-agent adapter, then decomposes each request into source-level rows so a user can see not only how much a turn cost but why it cost that much. It lives in the same ecosystem as Claude Code and Codex: it requires one of those agents to be installed, runs on macOS or Linux, and needs no API keys, no account, and no configuration changes to the agent itself. Capture for Claude Code works through a reverse proxy using a base-URL override with no certificate, while Codex uses a forward proxy plus a scoped local CA installed by a self-healing wrapper.

The concrete problem it solves is cost attribution below the session total. Most usage tools read local logs, which reports the total cost of a call or session and at most groups it by tool type, but misses the request-time context assembled before the model is invoked. cost-xray replaces that log-aggregation approach with per-call pricing: the cost of a specific Read invocation and its output, split into fresh, cache-read, cache-write, and output dollars, rather than a request- or session-level sum.

Key capabilities

  • Captures request-time context that log readers miss: system prompts, tool schemas, MCP blocks, tool results, prompt-cache reads and writes, and previous thinking blocks.
  • Prices below the tool level, down to the individual per-turn call, with every cell carrying its cache split of read, write, fresh, and output dollars.
  • Decomposes live context-window occupancy into source-level rows covering the system prompt, each tool schema, MCP servers, messages, and generated output.
  • Drills in the TUI from agent to project to session to category to MCP server to tool to per-turn call to the real output.
  • Provides the cx CLI as the whole interface, with cx status, cx stop, cx start, cx restart, cx install, and cx uninstall, usable from any directory.
  • Reads configuration from ~/.cost-xray/env, allowing the port and upstream to be changed before a cx restart.
  • Adds a new agent as one small module, so anything speaking the Anthropic or OpenAI-Responses wire shape is close to drop-in.

Who uses it and how

  • Individual developers on macOS or Linux running Claude Code, Codex, or both, who want to know which MCP server or tool schema is inflating each turn's spend.
  • Teams investigating prompt-caching behaviour, since the tool separates cache reads, cache writes, and fresh tokens for the same request.
  • Users who need per-call granularity rather than a session sum, for example to price one Read invocation and its output specifically.
  • Anyone tuning context-window occupancy, using the drill-down to see what is occupying the window right now.
  • People who cannot change agent behaviour: capture is forward-only, requires opening a new terminal and running claude or codex exactly as before, with no flags and no base-URL change.

Getting started

Install by piping the remote script to a shell with curl -fsSL https://raw.githubusercontent.com/tigerless-labs/cost-xray/master/install.sh | bash, or run ./install.sh from a clone. The installer asks which agents to capture, and COST_XRAY_AGENTS=claude|codex|all skips the prompt for CI; after opening a new terminal, the live TUI opens with cx.

How it compares

No list of paid products this project replaces is provided in the facts, and no comparable tools are named by name, so cost-xray stands alone in this registry. The README states that other usage tools aggregate at the request or session level and at most group by tool type, and that as far as the authors have found, nothing else prices below the tool on a call-by-call basis.

When to use it — and when not to

A self-hoster must run capture as a background service, which auto-starts on boot and is self-healing and port-adaptive, requires systemd for that behaviour, and otherwise falls back to manual no-systemd mode documented in docs/install.md; Codex capture additionally requires installing a scoped local CA. It is not for Windows users, not for anyone wanting past history backfilled, since capture is forward-only and starts with runs in a new shell, and not for teams seeking a centralised multi-user view, as capture is a local hop with no account. The README excerpt supplied here also ends mid-sentence, so documentation depth beyond the architecture and provider notes in docs/ cannot be fully confirmed from the facts.

project readme (upstream, from github) — read inline

cost-xray

See what your AI coding agent actually sends to the API — and what each part costs.

agents capture local only license MIT

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-xray 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.

Home — every session by agent · project · session, with token and dollar totals
Drill a session — context-window occupancy (top) and per-source cost, down to each MCP server (bottom)

Requirements

  • A supported coding agent — Claude Code or Codex
  • macOS or Linux
  • No API keys, no account, no config changes to your agent — capture is a transparent local hop

Install

curl -fsSL https://raw.githubusercontent.com/tigerless-labs/cost-xray/master/install.sh | bash

The installer asks which agent(s) to capture — Claude Code, Codex, or both — and prompts even under curl … | bash.

  • Skip the prompt (e.g. CI): set COST_XRAY_AGENTS=claude|codex|all.
  • Already cloned the repo? Run ./install.sh.

Then open a new terminal and run claude / codex exactly as before — capture is automatic, no flags and no base-URL change. It's forward-only: runs started in that new shell are captured, not past history. Open the live TUI from anywhere:

cx

Capture runs as a background service (auto-start on boot, self-healing, port-adaptive) and doesn't change what your agent does, its results, or its cost — pause anytime with cx stop. See docs/install.md for systemd details, GUI agents (Cursor base-URL setup), manual (no-systemd) mode, and troubleshooting.

Usage

cx                  # open the live cost-xray TUI (from any directory)
cx status           # services' 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 — authoritative: installs the chosen agents, removes the rest
cx uninstall        # remove services + shell wrappers (keeps captured data)

cx is the whole CLI and works from any directory. Change port/upstream by editing ~/.cost-xray/env, then cx restart. (./run.sh from the repo still works too — cx just calls it for you from anywhere.)

In the TUI, drill from the top down: agent → project → session → category → MCP server → tool → per-turn call → the real output. Every cell carries its cache split (read / write / fresh / output $).

Supported Agents

Agent Status Capture
Claude Code Supported reverse proxy (base-URL override) — no certificate
Codex Supported forward proxy + scoped local CA (self-healing wrapper)

The wire is decoded by a thin per-agent adapter — the only place code forks by agent (docs/architecture.md; per-agent capture + tokenizer notes under docs/providers/). Adding an agent is one small module; anything speaking the Anthropic or OpenAI-Responses wire shape is close to drop-in.

Features

Cost attribution, below the tool

cost-xray traces every token's cost — split into fresh / cache-read / cache-write / output — to the source that caused it, and down to the individual call: the cost of this Read invocation and its output, not a session sum. Everyone else aggregates — a request- or session-level total, at most grouped by tool type ("Read cost $X this session"). As far as we've found, nothing else prices below the tool, call by call.

Window occupancy

What is taking space in the context window right now — system prompt, every tool schema, MCP servers, messages, and generated output — decomposed into source-level rows. Prompt caching makes a stable 40k-token schema block cheap on cache read, but it still crowds out the code and conversation that matter; cost-xray shows you the occupancy, not just the bill.

Unused MCP waste

Configured servers and tools that are injected into every request's prefix but never actually called. They pay their tool-schema overhead on every turn — cost-xray flags the dead weight.

Tokenization accuracy

Claude's tokenizer is private — no official or open-source tokenizer exists — and calling Anthropic's count_tokens API for everything would add load and hit its limits. So for Claude, cost-xray uses an estimator plus proportional calibration: tiktoken sizes each part, the parts it mis-sizes most (thinking, tool schemas) get targeted corrections — pinned with count_tokens when you're logged in, a fixed ratio otherwise — and the rest is scaled so the calibrated total matches the provider's own usage. The total, and therefore the bill, is exact; only the split between sources in the same request is approximate. We benchmark those residuals continuously (CONTRIBUTING.md) and they're small enough for attribution work.

Coming soon: an opt-in exact mode — every part sized by full count_tokens differencing — manually enabled, for users who need maximum per-source precision.

Self-healing capture

The wrappers are per-command and self-healing: if the proxy is down, the wrapper restarts it and routes through; if it can't, the agent runs direct — never broken. Stop monitoring anytime with cx stop (agents then run direct).

Capture everything, store almost nothing

cost-xray keeps the complete raw API traffic — but a long session re-sends its whole history every turn, so the capture is hugely repetitive. We deduplicate it: each unique block (message, schema, tool result) is stored once, with a tiny per-turn delta. Full per-turn bytes rebuild on demand. Disk stays small even across million-token sessions.

Why not just read the logs?

Log-based tools (ccusage, codeburn, and similar) are excellent at local-first session analytics: they read local transcripts, classify turns by tool usage, and price the session by model, day, or task. That answers how much did I spend. cost-xray answers the lower-level question: what bytes did the model actually receive, and which source owns those tokens?

The difference is the data source. Log readers see the transcript after the agent has run — but the system prompt, injected tool schemas, MCP schemas, reminders, and provider-added blocks are assembled at request time and never written to the transcript. In real coding-agent requests, that invisible prefix can be roughly half the context or more. cost-xray reads the raw API request, so it can compute source-level tokens and attribute cost to schemas, MCP servers, tools, and message buckets.

Question Log / usage tools cost-xray wire capture
How much did the session cost? Yes Yes
Which task/tool was active? Yes Yes
System prompt and injected schemas visible? No Yes
How many tokens does each tool schema occupy? No, schemas aren't in logs Yes
Which MCP server is dead weight in the prefix? Estimate Exact
Cache read/write/fresh dollars per source/tool? No, usage is request-level Yes, by span and cache boundary
Live view of the current request window? No Yes

Reading the dashboard

cost-xray surfaces the data; you read the story. A few patterns worth knowing:

Signal you see What it might mean
A 40k-token MCP schema block on every turn A configure

readme truncated — read the full docs on github

Frequently asked questions

Is cost-xray free to use?

cost-xray is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does cost-xray do?

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

What is cost-xray written in?

cost-xray is primarily written in Python. Its source is publicly available at https://github.com/tigerless-labs/cost-xray, and it has 2,046 GitHub stars.