costcatch reference
Nine commands, all reading the same JSON in .costcatch/. run is the default and may be omitted: costcatch python agent.py is equivalent to costcatch run python agent.py.
Every framed block on this page is captured output, reproduced exactly — whitespace, box rules, column alignment and exit status included. Nothing here is a mock-up of output the tool does not produce. Wide blocks scroll horizontally rather than reflowing, because a reflowed box is no longer evidence.
Requirements
| Node.js | ≥ 20.19 — required to run costcatch itself, whichever runtime you trace |
| Python | 3.8+, and only to trace Python agents. The interceptor ships inside the npm package; there is nothing to pip install. |
Install
costcatch v0.2.0 is published on npm. Install it globally to use the command anywhere:
Or run it once with npx:
Verify the installation with costcatch --help.
Build from source
npm link puts costcatch on your PATH, pointing at dist/index.js. Verify with costcatch --help.
Initialise a project
Creates .costcatch/, adds it to .gitignore, and fetches the pricing table. See init below for the full output.
python or node straight to your program — the same rule time and env follow. So costcatch python agent.py --save gives --save to your agent, not to costcatch. It spots that mistake and tells you, rather than quietly doing nothing.Terminology
Six terms recur throughout this reference. They are defined here once and used without further qualification below.
- a call
- One request from your program to an AI model. A single question from a user often takes several, because the model asks for information and then reads the answer.
- a token
- The chunk of text providers charge by — roughly four characters of English, so about 750 words per thousand tokens. You pay separately for what you send (in) and what comes back (out), and sending is usually the cheaper half.
- a tool call
- The model asking your own code to do something it cannot — look something up, do some arithmetic — and then reading the answer you send back. Each round trip is another call, and another charge.
- the prompt
- Everything sent to the model in one call. It grows on every turn, because each turn re-sends the whole conversation so far plus whatever the tools returned. That growth is where surprise costs come from.
- reasoning tokens
- Tokens a model spends thinking before it answers. A subset of the completion tokens, not additional to them, and billed at the same rate — so they do not change what a call cost, they explain it. Often the majority of the output on a reasoning model.
- cached tokens
- Part of a prompt the provider had already seen and charges less for. costcatch reports it separately, so you can tell a genuinely large prompt from a mostly-cached one.
- a run
- One execution of your program, and the file costcatch saves for it in
.costcatch/. Every command below reads that same file, which is why you can compare, re-read and total up runs long after they have finished.
How it works
Six stages, no configuration at any of them.
1 · Runtime detection and the argv split
costcatch classifies the first argument as Python (python, python3, python3.12) or Node (node, nodejs, npx, tsx, ts-node) and splits argv at that executable: everything before it is costcatch's, everything after is yours. This is the rule time and env follow, and it is why costcatch python agent.py --save passes --save to your agent. Because that surprises people, costcatch detects the case and reports it on stderr rather than silently doing nothing.
2 · Interceptor injection
| runtime | mechanism | patched surfaces |
|---|---|---|
| Node | --require preload.cjs, or NODE_OPTIONS when the executable is a launcher such as npx | globalThis.fetch, https.request, http.request, https.get, http.get |
| Python | prepends the interceptor directory to PYTHONPATH so sitecustomize.py auto-loads | httpx.Client, httpx.AsyncClient, urllib3.HTTPConnectionPool |
urllib3 and httpx covers requests, the OpenAI and Anthropic SDKs, LangChain, LiteLLM and CrewAI, because nearly everything is built on one of those two. If your environment already defines a sitecustomize, costcatch chains to it rather than shadowing it.3 · Observation, never interference
The interceptor is purely observational, and this is the property the whole design protects:
| failure mode | every patched path is wrapped, so an internal fault degrades to "captured nothing", never "broke your agent" |
| response bodies | cloned or spliced back, never consumed out from under you |
| streaming | tee'd as you consume them, so stream=True keeps working |
| errors | an unhandled error stays unhandled; installing costcatch will not turn a crash into a silent hang |
| memory | bounded at 2 MiB per response and 64 MiB per run, so a tracer cannot OOM the program it watches |
| headers | never read — which is why an API key cannot appear in a trace even in principle |
4 · Two-phase NDJSON protocol
The interceptor writes newline-delimited JSON to a temp file. Each call produces two records: phase: "start" when the request is dispatched, and phase: "end" with a correlation id when the response completes. Two records rather than one is what makes the live view possible, keeps timing correct for overlapping concurrent calls, and lets the report render progressively instead of only at the end.
5 · Building the trace
Records are folded into calls in a fixed order, and the order matters:
| 1 | synthetic capture-limit records are dropped — counting them would inflate llmCalls and trip --max-calls on its own |
| 2 | --filter is applied before calls are numbered, so the summary and the report always describe the same subset |
| 3 | the provider registry parses each body |
| 4 | each call is priced |
| 5 | conversation content is extracted and redacted |
| 6 | retries are marked — a call whose prompt matches an earlier one |
| 7 | the warning engine runs |
6 · Rendering
On an interactive colour TTY a pinned box repaints roughly twelve times a second. Everywhere else — CI, a pipe, --json, --quiet, --no-color — output falls back to sequential lines with no cursor control, safe for log files.
costcatch --help
Everything costcatch can do, on one screen. If an option is not in here, it does not exist.
costcatch --helpUsage: costcatch [options] [command] Zero-instrumentation LLM agent tracer & cost tracker. Like `time` but for AI agents. Options: -v, --version Print the costcatch version -h, --help display help for command Commands: run [options] [command...] Trace a script (default command; `run` is optional) show [options] [file] Inspect the full conversation content of a saved trace (defaults to latest) estimate [options] [file] Estimate token count and cost for a prompt file replay [options] [file] Re-display a saved trace (defaults to latest) diff [options] [file1] [file2] Compare two saved traces side by side (defaults to last 2 runs) stats [options] Show aggregated analytics across saved traces watch [options] [command...] Traced run that always saves, with the live view on clean [options] Delete old saved traces from .costcatch/ init [options] Set up .costcatch/ and fetch the latest pricing database help [command] display help for command
init
01 / 09setup & pricingSets costcatch up in the current folder: makes a .costcatch/ folder to keep saved runs in, tells git to ignore it, downloads the price list, and prints the panel below. There is nothing to configure after this — no config file, no key, no project id, no account.
About
Zero-instrumentation LLM agent tracer & cost tracker. Like time, for AI agents.
Features
- live trace in the terminal
- per-call cost tracking
- prompt cost estimation
- auto-diff between runs
- CI assertion gates
- secret & PII redaction
Commands
Quick start
The same panel, as the terminal draws it
costcatch init██████╗ ██████╗ ███████╗████████╗ ██████╗ █████╗ ████████╗ ██████╗██╗ ██╗ ██╔════╝██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗╚══██╔══╝██╔════╝██║ ██║ ██║ ██║ ██║███████╗ ██║ ██║ ███████║ ██║ ██║ ███████║ ██║ ██║ ██║╚════██║ ██║ ██║ ██╔══██║ ██║ ██║ ██╔══██║ ╚██████╗╚██████╔╝███████║ ██║ ╚██████╗██║ ██║ ██║ ╚██████╗██║ ██║ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ┌────────────────────────────────┬────── v0.2.0 ───────────────────────────────────────┐ │ │ │ │ About │ Commands │ │ Zero-instrumentation LLM │ run trace a script (default) │ │ agent tracer & cost tracker. │ estimate estimate prompt token cost │ │ Like `time`, for AI agents. │ show inspect conversation content │ │ │ diff compare two saved traces │ │ Features │ stats aggregated analytics │ │ · live trace in the terminal │ replay re-display a saved trace │ │ · per-call cost tracking │ watch run, always saved │ │ · prompt cost estimation │ clean prune old saved traces │ │ · auto-diff between runs │ init setup & fetch pricing │ │ · CI assertion gates │ │ │ · secret & PII redaction │ Quick Start │ │ │ $ costcatch python3 agent.py │ │ │ $ costcatch node agent.mjs │ │ │ │ └────────────────────────────────┴─────────────────────────────────────────────────────┘ - fetching latest model pricing… ┌──────────────────────────────────────────────────────────────────────────────┐ │ costcatch init │ │ │ │ + created .costcatch/ (.costcatch) │ │ + added .costcatch/ to .gitignore │ │ + fetched latest pricing (5,831 models) │ │ │ │ ready · run `costcatch --help` to see all commands │ └──────────────────────────────────────────────────────────────────────────────┘
On a machine with no internet
--offline skips the download and uses the copy of the price list that ships inside the package, so costcatch works on a machine that cannot reach the internet at all.
costcatch init --offline██████╗ ██████╗ ███████╗████████╗ ██████╗ █████╗ ████████╗ ██████╗██╗ ██╗ ██╔════╝██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗╚══██╔══╝██╔════╝██║ ██║ ██║ ██║ ██║███████╗ ██║ ██║ ███████║ ██║ ██║ ███████║ ██║ ██║ ██║╚════██║ ██║ ██║ ██╔══██║ ██║ ██║ ██╔══██║ ╚██████╗╚██████╔╝███████║ ██║ ╚██████╗██║ ██║ ██║ ╚██████╗██║ ██║ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ┌────────────────────────────────┬────── v0.2.0 ───────────────────────────────────────┐ │ │ │ │ About │ Commands │ │ Zero-instrumentation LLM │ run trace a script (default) │ │ agent tracer & cost tracker. │ estimate estimate prompt token cost │ │ Like `time`, for AI agents. │ show inspect conversation content │ │ │ diff compare two saved traces │ │ Features │ stats aggregated analytics │ │ · live trace in the terminal │ replay re-display a saved trace │ │ · per-call cost tracking │ watch run, always saved │ │ · prompt cost estimation │ clean prune old saved traces │ │ · auto-diff between runs │ init setup & fetch pricing │ │ · CI assertion gates │ │ │ · secret & PII redaction │ Quick Start │ │ │ $ costcatch python3 agent.py │ │ │ $ costcatch node agent.mjs │ │ │ │ └────────────────────────────────┴─────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────────────────────────────┐ │ costcatch init │ │ │ │ + created .costcatch/ (.costcatch) │ │ + added .costcatch/ to .gitignore │ │ · --offline: skipped pricing download, using bundled prices │ │ │ │ ready · run `costcatch --help` to see all commands │ └──────────────────────────────────────────────────────────────────────────────┘
run
02 / 09the default commandRuns a Python or Node command and prices it. Your program's own output comes through untouched, and costcatch's report follows it. Read each row left to right: whether the call worked, which call it was, how long it took, tokens in and out, what it cost, a bar comparing that cost to the most expensive call in the run, and how much of the prompt the provider had already cached.
The ├─ ▸ lines underneath are the tools the model asked for on that call. Putting each one under the call that asked is what makes an agent readable — call 1 below wanted two weather lookups and a multiplication.
costcatch run --save node --env-file=.env test_agent.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 35.6s $0.00019 │ │ │ │ + Step 1 13.0s 526 tok in → 271 tok out $0.000065 ⟳ 128 cached │ │ ├─ > get_weather(city="Tokyo") │ │ ├─ > get_weather(city="London") │ │ └─ > calculate(expression="240*4") │ │ │ │ + Step 2 9.9s 691 tok in → 204 tok out $0.000048 ⟳ 512 cached │ │ ├─ > calculate(expression="(31-18)*9/5") │ │ └─ > convert_currency(amount=960, from="GBP", to="INR") │ │ │ │ + Step 3 5.0s 847 tok in → 49 tok out $0.000027 ⟳ 640 cached │ │ └─ > calculate(expression="101103.8/3") │ │ │ │ + Step 4 7.7s 917 tok in → 182 tok out $0.000047 ⟳ 768 cached │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 4 LLM calls · 6 tool calls · 35.6s · $0.00019 │ │ 3.0k tok in → 706 tok out │ │ at 1 run/day = $0.01/mo · at 100 runs/day = $0.56/mo · at 1000 runs/day = $5.59/mo │ │ run 2026-09-02T06-54-46 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ + Trace saved: .costcatch/2026-09-02T06-54-46-test_agent.json
$0.00019 sounds like nothing. At a thousand runs a day it is $5.59 a month for this one agent — and that is the number worth arguing about, which is why costcatch always prints it.--quiet · just the total
costcatch run --quiet node --env-file=.env test_simple.mjs[simple] reply: Hi John! 1 steps · 1 LLM calls · $0.000017 · 7.1s
--no-color · for log files
Not the same box with the colour taken out, but a different layout altogether: flat indented lines. Box drawing in a build log is noise rather than structure.
costcatch run --no-color node --env-file=.env test_simple.mjs[simple] reply: Hello, John! costcatch 14.0s · $0.000052 1. LLM deepseek/deepseek-v4-flash-0731 14.0s 36 tok in -> 314 tok out $0.000052 1 LLM call · 0 tool calls · 14.0s · $0.000052
--json · for other programs to read
The run goes to standard output and your program's own output moves to standard error, so the two never get mixed together in a pipeline. costcatch also waits until the very end to set its exit code, so nothing is cut off partway down a pipe — costcatch --json … | jq relies on that.
costcatch run --json node --env-file=.env test_simple.mjs[simple] reply: Hello John, thanks for sharing your contact details! { "runId": "2026-09-02T06-55-29", "script": "test_simple.mjs", "runtime": "node", "durationMs": 7266, "totalCostUsd": 0.00002036, "steps": [ { "type": "llm", "id": 1, "durationMs": 7266, "provider": "openrouter", "model": "deepseek/deepseek-v4-flash-0731", "inputTokens": 36, "outputTokens": 116, "cachedTokens": 0, "costUsd": 0.00002036, "toolCalls": [], "isStreaming": false, "finishReason": "stop", "statusCode": 200, "error": null, "content": { "system": null, "messages": [ { "role": "user", "content": "My email is «email» and my phone is «phone». Reply with exactly one short sentence greeting me." } ], "output": " Hello John, thanks for sharing your contact details!", "truncated": false }, "retryOf": null } ], "warnings": [], "summary": { "llmCalls": 1, "toolCalls": 0, "totalInputTokens": 36, "totalOutputTokens": 116, "totalSteps": 1, "retries": 0, "wastedCostUsd": 0 }, "startedAt": "2026-09-02T06:55:29.723Z", "command": "node --env-file=.env test_simple.mjs" }
--inspect · show the whole conversation
costcatch run --inspect node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch ⧗ 8.1s $0.000028 │ │ show: test_simple.mjs (1 LLM call) │ │ │ │ ── + Step 1 deepseek/deepseek-v4-… 8.1s 36 tok in → 166 tok out $0.000028 │ │ │ │ USER │ │ My email is «email» and my phone is «phone». Reply with exactly one short sentence greetin │ │ g me. │ │ │ │ OUTPUT │ │ Hello! │ │ │ │ 2026-09-02T06-55-37 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--compare-last · did my change help?
Change a prompt, run it, and see what moved against the previous run of the same script — without having to name either file. This saves the run too, so you do not need --save as well.
costcatch run --compare-last node --env-file=.env test_agent.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch diff · before → after │ │ │ │ Steps 4 → 6 +2 │ │ LLM calls 4 → 6 +2 │ │ Tool calls 6 → 8 +2 │ │ Duration 35.6s → 50.0s +40% │ │ Cost $0.00019 → $0.00043 +132% │ │ Max context tok 917 → 1,641 +724 │ │ │ │ ── removed calls │ │ · calculate({"expression":"240*4"}) │ │ · calculate({"expression":"(31-18)*9/5"}) │ │ · calculate({"expression":"101103.8/3"}) │ │ │ │ ── added calls │ │ + calculate({"expression":"(31*9/5)+32"}) │ │ + calculate({"expression":"(18*9/5)+32"}) │ │ + calculate({"expression":"87.8 - 64.4"}) │ │ + calculate({"expression":"240 * 4"}) │ │ + calculate({"expression":"101103.8 / 3"}) │ │ │ │ ── input-token delta by step (before → after) │ │ Step 5: 847 → 1,504 (+78%) │ │ Step 6: 917 → 1,641 (+79%) │ │ │ │ $0.00025 more expensive │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--save-as, --no-cost
--save-as always writes to the same filename, which is how you keep one run around as a fixed point to compare everything else against. --no-cost hides the money columns and keeps the token ones.
costcatch run --save-as baseline --no-cost node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 8.3s │ │ │ │ + Step 1 8.3s 36 tok in → 186 tok out │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 1 LLM call · 0 tool calls · 8.3s │ │ 36 tok in → 186 tok out │ │ run 2026-09-02T06-59-08 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ + Trace saved: .costcatch/baseline.json
--threshold · say what "too slow" means
By default costcatch works out what counts as slow from the run itself. This replaces that with a number of milliseconds you choose, for when you already know.
costcatch run --threshold 3000 node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 11.4s $0.000037 │ │ │ │ + Step 1 11.4s 36 tok in → 221 tok out $0.000037 │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 1 LLM call · 0 tool calls · 11.4s · $0.000037 │ │ 36 tok in → 221 tok out │ │ at 1 run/day = $0.00/mo · at 100 runs/day = $0.11/mo · at 1000 runs/day = $1.11/mo │ │ │ │ ── warnings │ │ ● Step 1 took 11.4s (threshold: 3.0s) │ │ run 2026-09-02T06-57-57 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--no-redact · keep names and emails in the file
By default costcatch hides personal details before saving. This turns that off. It does not turn off secret-stripping: passwords, keys and tokens are removed every time, whatever you pass.
costcatch run --no-redact --save-as noredact-demo node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ △ PII redaction is OFF (--no-redact). │ │ Emails, phone numbers and card numbers were captured as written. │ │ The saved trace contains them in plain text. │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ + Trace saved: .costcatch/noredact-demo.json
watch
03 / 09always live, always savedThe same as run with two things switched on: the live view stays up for the whole run, and the run is always saved. Every run option works here too — --save is just redundant.
costcatch watch node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 8.5s $0.000019 │ │ │ │ + Step 1 8.5s 36 tok in → 109 tok out $0.000019 │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 1 LLM call · 0 tool calls · 8.5s · $0.000019 │ │ 36 tok in → 109 tok out │ │ at 1 run/day = $0.00/mo · at 100 runs/day = $0.06/mo · at 1000 runs/day = $0.58/mo │ │ run 2026-09-02T06-59-31 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ + Trace saved: .costcatch/2026-09-02T06-59-31-test_simple.json
show
04 / 09read the conversationShows what was actually sent and received in a saved run: the instructions you gave, every message, what your tools sent back, and what the model replied. With no filename it opens the most recent run in .costcatch/.
costcatch show .costcatch/2026-09-02T06-58-18-test_agent.json --step 2┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch ⧗ 50.0s $0.00043 │ │ show: test_agent.mjs (6 LLM calls) │ │ │ │ ── + Step 2 deepseek/deepseek-v4-… 13.8s 668 tok in → 337 tok out $0.000068 │ │ │ │ SYSTEM │ │ You are a travel planning assistant. Always use the provided tools for weather lookups, ar │ │ ithmetic, and currency conversion. Never do math in your head. │ │ │ │ USER │ │ I'm planning a trip. 1) What's the temperature difference in Fahrenheit between Tokyo and │ │ London right now? 2) My hotel in London costs 240 GBP per night for 4 nights - what's the │ │ total in INR? 3) If I split that INR total evenly across 3 people, how much does each pers │ │ on pay? Use your tools for every lookup and calculation, then give me a final summary. │ │ ASSISTANT │ │ I'll help you with all three parts. Let me start by getting the current weather for both │ │ cities. │ │ │ │ │ │ TOOL │ │ {"temp_c":31,"condition":"humid, sunny"} │ │ TOOL │ │ {"temp_c":18,"condition":"overcast, light rain"} │ │ │ │ OUTPUT │ │ I'll calculate the temperatures in Fahrenheit and then find the difference. │ │ │ │ │ │ │ │ TOOL CALLS │ │ > calculate({"expression":"(31*9/5)+32"}) │ │ > calculate({"expression":"(18*9/5)+32"}) │ │ 2026-09-02T06-58-18 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--grep · find the turn it happened on
Searches the saved text and prints only the calls that match — for when you know what appeared but not which turn it appeared on.
costcatch show .costcatch/2026-09-02T06-58-18-test_agent.json --grep convert_currency┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch ⧗ 50.0s $0.00043 │ │ show: test_agent.mjs (6 LLM calls) │ │ │ │ ── + Step 4 deepseek/deepseek-v4-… 4.2s 1,345 tok in → 133 tok out $0.000088 │ │ │ │ SYSTEM │ │ You are a travel planning assistant. Always use the provided tools for weather lookups, ar │ │ ithmetic, and currency conversion. Never do math in your head. │ │ │ │ USER │ │ I'm planning a trip. 1) What's the temperature difference in Fahrenheit between Tokyo and │ │ London right now? 2) My hotel in London costs 240 GBP per night for 4 nights - what's the │ │ total in INR? 3) If I split that INR total evenly across 3 people, how much does each pers │ │ on pay? Use your tools for every lookup and calculation, then give me a final summary. │ │ ASSISTANT │ │ I'll help you with all three parts. Let me start by getting the current weather for both │ │ cities. │ │ │ │ │ │ TOOL │ │ {"temp_c":31,"condition":"humid, sunny"} │ │ TOOL │ │ {"temp_c":18,"condition":"overcast, light rain"} │ │ ASSISTANT │ │ I'll calculate the temperatures in Fahrenheit and then find the difference. │ │ │ │ │ │ TOOL │ │ {"result":87.8} │ │ TOOL │ │ {"result":64.4} │ │ ASSISTANT │ │ Now let me calculate the temperature difference and convert the hotel cost. │ │ │ │ │ │ TOOL │ │ {"result":23.39999999999999} │ │ TOOL │ │ {"result":960} │ │ │ │ OUTPUT │ │ The temperature difference is approximately 23.4°F and the total hotel cost is 960 GBP. No │ │ w let me convert that to INR. │ │ │ │ TOOL CALLS │ │ > convert_currency({"amount":960,"from":"GBP","to":"INR"}) │ │ │ │ 1 step match "convert_currency" │ │ 2026-09-02T06-58-18 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
replay
05 / 09offline re-renderPrints a saved run's report again. Nothing is sent, nothing is charged, and your agent does not run a second time — the saved file already holds everything the report needs.
costcatch replay .costcatch/2026-09-02T06-58-18-test_agent.json┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 50.0s $0.00043 │ │ │ │ + Step 1 9.5s 526 tok in → 171 tok out $0.000039 ⟳ 384 cached │ │ ├─ > get_weather(city="Tokyo") │ │ └─ > get_weather(city="London") │ │ │ │ + Step 2 13.8s 668 tok in → 337 tok out $0.000068 ⟳ 512 cached │ │ ├─ > calculate(expression="(31*9/5)+32") │ │ └─ > calculate(expression="(18*9/5)+32") │ │ │ │ + Step 3 9.7s 798 tok in → 124 tok out $0.000055 ⟳ 128 cached │ │ ├─ > calculate(expression="87.8 - 64.4") │ │ └─ > calculate(expression="240 * 4") │ │ │ │ + Step 4 4.2s 1,345 tok in → 133 tok out $0.000088 ⟳ 512 cached │ │ └─ > convert_currency(amount=960, from="GBP", to="INR") │ │ │ │ + Step 5 3.8s 1,504 tok in → 116 tok out $0.000061 ⟳ 1,280 cached │ │ └─ > calculate(expression="101103.8 / 3") │ │ │ │ + Step 6 9.0s 1,641 tok in → 389 tok out $0.00012 ⟳ 1,280 cached │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 6 LLM calls · 8 tool calls · 50.0s · $0.00043 │ │ 6.5k tok in → 1.3k tok out │ │ at 1 run/day = $0.01/mo · at 100 runs/day = $1.29/mo · at 1000 runs/day = $12.94/mo │ │ │ │ ── warnings │ │ ● Context grew 3.1× across calls (526 → 1,641 tokens) │ │ run 2026-09-02T06-58-18 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--no-cost
costcatch replay --no-cost .costcatch/2026-09-02T06-58-18-test_agent.json┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 50.0s │ │ │ │ + Step 1 9.5s 526 tok in → 171 tok out ⟳ 384 cached │ │ ├─ > get_weather(city="Tokyo") │ │ └─ > get_weather(city="London") │ │ │ │ + Step 2 13.8s 668 tok in → 337 tok out ⟳ 512 cached │ │ ├─ > calculate(expression="(31*9/5)+32") │ │ └─ > calculate(expression="(18*9/5)+32") │ │ │ │ + Step 3 9.7s 798 tok in → 124 tok out ⟳ 128 cached │ │ ├─ > calculate(expression="87.8 - 64.4") │ │ └─ > calculate(expression="240 * 4") │ │ │ │ + Step 4 4.2s 1,345 tok in → 133 tok out ⟳ 512 cached │ │ └─ > convert_currency(amount=960, from="GBP", to="INR") │ │ │ │ + Step 5 3.8s 1,504 tok in → 116 tok out ⟳ 1,280 cached │ │ └─ > calculate(expression="101103.8 / 3") │ │ │ │ + Step 6 9.0s 1,641 tok in → 389 tok out ⟳ 1,280 cached │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 6 LLM calls · 8 tool calls · 50.0s │ │ 6.5k tok in → 1.3k tok out │ │ │ │ ── warnings │ │ ● Context grew 3.1× across calls (526 → 1,641 tokens) │ │ run 2026-09-02T06-58-18 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
diff
06 / 09compare two runsCompares two saved runs. With no arguments it takes the last two runs of the same script, which is what you want right after changing a prompt. It shows what moved in the things that cost money — number of calls, tools used, biggest prompt, total — plus the tools each run used that the other did not.
costcatch diff .costcatch/2026-09-02T06-54-46-test_agent.json .costcatch/2026-09-02T06-58-18-test_agent.json┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch diff · before → after │ │ │ │ Steps 4 → 6 +2 │ │ LLM calls 4 → 6 +2 │ │ Tool calls 6 → 8 +2 │ │ Duration 35.6s → 50.0s +40% │ │ Cost $0.00019 → $0.00043 +132% │ │ Max context tok 917 → 1,641 +724 │ │ │ │ ── removed calls │ │ · calculate({"expression":"240*4"}) │ │ · calculate({"expression":"(31-18)*9/5"}) │ │ · calculate({"expression":"101103.8/3"}) │ │ │ │ ── added calls │ │ + calculate({"expression":"(31*9/5)+32"}) │ │ + calculate({"expression":"(18*9/5)+32"}) │ │ + calculate({"expression":"87.8 - 64.4"}) │ │ + calculate({"expression":"240 * 4"}) │ │ + calculate({"expression":"101103.8 / 3"}) │ │ │ │ ── input-token delta by step (before → after) │ │ Step 2: 691 → 668 (-3%) │ │ Step 5: 847 → 1,504 (+78%) │ │ Step 6: 917 → 1,641 (+79%) │ │ │ │ $0.00025 more expensive │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--json
costcatch diff --json .costcatch/2026-09-02T06-54-46-test_agent.json .costcatch/2026-09-02T06-58-18-test_agent.json{ "before": { "totalSteps": 4, "llmCalls": 4, "toolCalls": 6, "durationMs": 35605, "costUsd": 0.000186234, "maxContext": 917 }, "after": { "totalSteps": 6, "llmCalls": 6, "toolCalls": 8, "durationMs": 49973, "costUsd": 0.000431282, "maxContext": 1641 }, "delta": { "steps": 2, "llmCalls": 2, "toolCalls": 2, "durationMs": 14368, "costUsd": 0.000245048, "maxContext": 724 }, "addedToolCalls": [ "calculate({\"expression\":\"(31*9/5)+32\"})", "calculate({\"expression\":\"(18*9/5)+32\"})", "calculate({\"expression\":\"87.8 - 64.4\"})", "calculate({\"expression\":\"240 * 4\"})", … (output continues)
stats
07 / 09spend across every runAdds up every saved run: which scripts cost the most, which models cost the most, the average size of a run, and the slowest runs. This is the end-of-month view — which script, and which model, is actually taking the money.
costcatch stats┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch stats · all time │ │ │ │ Total runs: 12 │ │ Total cost: $0.00119 │ │ Avg cost/run: $0.000099 │ │ │ │ ── most expensive scripts │ │ $0.00106 test_agent.mjs (5 runs) │ │ $0.00011 test_simple.mjs (6 runs) │ │ $0.000017 agent.py (1 runs) │ │ │ │ ── most expensive models │ │ $0.00119 deepseek/deepseek-v4-flash-0731 (32 calls) │ │ │ │ ── tokens per run │ │ avg input tok/run: 1,690 │ │ avg output tok/run: 475 │ │ │ │ ── slowest runs │ │ 55.6s test_agent.mjs 2026-08-29T07-08-28 │ │ 54.7s test_agent.mjs 2026-08-29T07-12-52 │ │ 50.0s test_agent.mjs 2026-09-02T06-58-18 │ │ │ │ 12 runs · $0.00119 total │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--json
costcatch stats --json{ "period": "all time", "totalRuns": 12, "totalCostUsd": 0.001191297, "avgCostUsd": 0.00009927475, "scripts": [ { "script": "test_agent.mjs", "costUsd": 0.0010619820000000002, "runs": 5 }, { "script": "test_simple.mjs", "costUsd": 0.00011186000000000002, "runs": 6 }, { "script": "/private/tmp/claude-501/-Users-ronakrahane-Desktop-agent-trace/1176dce3-d472-40c0-ba49-35d0c89f9b16/scratchpad/live/agent.py", "costUsd": 0.000017455, "runs": 1 } ], "models": [ { "model": "deepseek/deepseek-v4-flash-0731", "costUsd": 0.0011912970000000004, "calls": 32 } ], "avgInputTokensPerRun": 1690, "avgOutputTokensPerRun": 475, "slowestRuns": [ { "script": "test_agent.mjs", … (output continues)
estimate
08 / 09before you spendTells you how many tokens a prompt is and what it will cost to send, without sending it. A model with no price on the list prints $?.?? rather than a guess.
costcatch estimate prompt.txt --model gpt-4o,claude-sonnet-4,deepseek/deepseek-v4-flash-0731┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch estimate · 3 models │ │ │ │ File prompt.txt · 361 chars │ │ │ │ ● Model Comparison │ │ │ │ ┌──────────────────────┬────────┬────────────┬────────────┐ │ │ │ Model │ Tokens │ Cost │ Impact │ │ │ ├──────────────────────┼────────┼────────────┼────────────┤ │ │ │ deepseek-v4-flash-0… │ ~91 │ $0.0000059 │ │ │ │ │ gpt-4o │ ~91 │ $0.00023 │ │ │ │ │ claude-sonnet-4 │ ~101 │ $0.00030 │ │ │ │ └──────────────────────┴────────┴────────────┴────────────┘ │ │ │ │ ✦ deepseek/deepseek-v4-… is 98% cheaper than claude-sonnet-4 │ │ │ │ ● Tokenizer Details │ │ │ │ ┌────────────────────────────┬───────────────┬─────────────┬────────────┐ │ │ │ Model │ Tokenizer │ Ratio │ Confidence │ │ │ ├────────────────────────────┼───────────────┼─────────────┼────────────┤ │ │ │ deepseek/deepseek-v4-flas… │ generic-bpe │ ~4.0 ch/tok │ + ±10% │ │ │ │ gpt-4o │ o200k_base │ ~4.0 ch/tok │ + ±10% │ │ │ │ claude-sonnet-4 │ claude-bpe-v1 │ ~3.6 ch/tok │ + ±10% │ │ │ └────────────────────────────┴───────────────┴─────────────┴────────────┘ │ │ │ │ ✦ character-ratio heuristics · actual tokens may vary │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--breakdown · which part is the expensive part
Splits a prompt up section by section. This is how you find the 400-token block of instructions nobody has read since the day it was written.
costcatch estimate prompt.txt --model gpt-4o --breakdown┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch estimate · gpt-4o │ │ │ │ File prompt.txt │ │ Model gpt-4o │ │ Content prose · o200k_base · ~4.0 chars/tok │ │ │ │ ● Token Estimate │ │ │ │ ┌──────────────────┬────────┐ │ │ │ Metric │ Value │ │ │ ├──────────────────┼────────┤ │ │ │ Characters │ 361 │ │ │ │ Estimated Tokens │ ~91 │ │ │ │ Confidence │ + ±10% │ │ │ └──────────────────┴────────┘ │ │ │ │ ● Cost Estimate (input only) │ │ │ │ ┌──────────────────────────┬─────────────────────┐ │ │ │ Scale │ Est. Cost (Monthly) │ │ │ ├──────────────────────────┼─────────────────────┤ │ │ │ Per single call │ $0.00023 │ │ │ │ 10 calls/day (300/mo) │ $0.06825 │ │ │ │ 100 calls/day (3k/mo) │ $0.68250 │ │ │ │ 1,000 calls/day (30k/mo) │ $6.82500 │ │ │ └──────────────────────────┴─────────────────────┘ │ │ │ │ ● Breakdown │ │ │ │ ┌────────────────────────────────┬────────┬─────┬──────────────┐ │ │ │ Section │ Tokens │ % │ Distribution │ │ │ ├────────────────────────────────┼────────┼─────┼──────────────┤ │ │ │ You are a senior support engi… │ 34 │ 38% │ ███▓░░░░░░ │ │ │ │ The customer reports that the… │ 56 │ 62% │ ██████░░░░ │ │ │ └────────────────────────────────┴────────┴─────┴──────────────┘ │ │ │ │ ✦ character-ratio heuristics · actual tokens may vary │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--json
costcatch estimate prompt.txt --model gpt-4o --json{ "file": "prompt.txt", "models": [ { "model": "gpt-4o", "estimatedTokens": 91, "characterCount": 361, "charsPerToken": 4, "tokenizerFamily": "o200k_base", "confidence": "high", "margin": 0.1, "contentType": "prose", "costUsd": 0.0002275, "costPerMonth100": 0.68, "sections": null } ] }
--max-cost · fail before anything is sent
estimate takes a cost limit as well, so a prompt template can fail your build before it has ever reached a model.
costcatch estimate prompt.txt --model gpt-4o --max-cost 0.00001└──────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ × CI GATE: estimated cost $0.00023 exceeds --max-cost $0.000010 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
clean
09 / 09retentionDeletes old saved runs. The two options narrow each other rather than adding up: --keep is a floor, not a second way of choosing, so --keep 10 --older-than 7 deletes anything older than a week except the ten most recent.
costcatch clean┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ × Nothing to do: pass --keep <n> and/or --older-than <days>. │ │ costcatch clean --keep 50 keep the 50 newest traces │ │ costcatch clean --older-than 30 delete traces older than 30 days │ │ add --dry-run to preview without deleting │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
On its own it refuses to do anything, because the default behaviour of a delete command must never be a guess. --dry-run lists exactly what would go, without touching a thing:
costcatch clean --keep 4 --dry-run┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch clean · dry run │ │ │ │ ── would delete │ │ sec-audit.json │ │ 2026-08-29T08-30-17-test_agent.json │ │ 2026-08-29T07-14-25-test_simple.json │ │ simple-baseline.json │ │ 2026-08-29T07-12-52-test_agent.json │ │ 2026-08-29T07-09-47-test_simple.json │ │ 2026-08-29T07-08-28-test_agent.json │ │ 2026-08-22T14-33-20-agent.json │ │ │ │ 8 of 12 traces would be deleted · nothing was removed │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
run flags
All of these work with run and with watch, except that watch saves the run whether you ask it to or not.
--save | Keep the run as a file, so show, replay, diff and stats can read it later |
--save-as <name> | Always write to the same filename, so you can keep one run as a fixed point to compare against |
--json | Print the run as JSON for another program to read; your own output moves aside so the two never get mixed up |
--quiet | Just the total, on one line |
--no-color | Flat indented lines instead of the box — for log files, where box drawing is noise |
--no-cost | Hide the money columns, keep the token ones |
--no-redact | Leave names, emails and phone numbers in the saved file. Passwords and keys are always removed either way |
--inspect | Print the whole conversation after the run |
--compare-last | Compare against the previous run of this script automatically. Saves the run too |
--filter <provider> | Watch one provider only. The name is checked against the real list, so a typo is loud rather than silent |
--threshold <ms> | Say what counts as slow yourself, instead of letting costcatch work it out from the run |
--max-cost <usd> | After the run: fail if it cost more than this |
--max-calls <n> | After the run: fail if it made more calls than this |
--budget <usd> | While it runs: stop the program once spend passes this, or a call can't be priced |
Security & redaction
Your API key cannot be captured
The interceptor never reads request headers, and a key travels in a header. Verified against the real 73-character OPENROUTER_API_KEY from .env:
| check | result |
|---|---|
| API key present in the saved trace | 0 occurrences |
any authorization field | 0 |
any sk-… token | 0 |
| trace file permissions | -rw------- (0600) |
| PII in the prompt | masked to «email» / «phone» |
Redaction — three tiers, on by default
| tier | covers | removable |
|---|---|---|
| Control characters | ANSI escapes, \r, control bytes | never |
| Secrets | provider keys (sk-, sk-ant-, ya29., xapp-, npm_, pypi-, sk-or-v1-), PEM blocks, Bearer/Basic/Digest headers, api_key:/secret=/password= pairs | never |
| PII | emails, phone numbers, card numbers | yes, with --no-redact |
{20,512}, {8,4096}) rather than greedy, because prompt length is entirely user-controlled and an unbounded backtracking pattern here would be a CPU-exhaustion vector (CWE-1333). Two tests hold the line: an absolute per-KB ceiling and a hardware-independent ratio check that catches super-linear scaling on any machine.Process, filesystem, network
| process spawning | shell: false everywhere; no exec, execSync or shell: true anywhere in src/. On Windows, .cmd/.bat targets are spawned through a manually quoted cmd.exe command line with windowsVerbatimArguments, so a path like C:my & agents
un.py cannot be reinterpreted as shell syntax. |
| path traversal | --save-as is sanitised to [a-zA-Z0-9._-], so --save-as ../../../tmp/pwned cannot escape .costcatch/. |
| clean | targets come only from a listing jailed to .costcatch/ that returns regular .json files, so a planted symlink is not followed; pricing.json is excluded by name. |
| writes | serialised to a sibling temp file and renamed, mode 0600. An interrupted run leaves either the old file or the new one, never a truncated document that stats and diff would skip forever. |
| reads | every saved trace is treated as untrusted: fields are coerced with fallbacks, control characters are stripped on read, and a trace carrying a __proto__ key does not pollute Object.prototype. |
| network | exactly two outbound requests, both HTTPS, both only from init, both optional, both with 10-second timeouts: LiteLLM's pricing JSON and OpenRouter's public model listing. No telemetry; no trace data leaves the machine. |
| dependencies | five runtime dependencies, npm audit --omit=dev reports 0 vulnerabilities. No LLM SDK, no HTTP client, no native modules. |
Known advisories
.costcatch/ is gitignored by init and clean provides retention, but the flag produces plaintext PII in a file and prints no on-screen warning that it did.Gates
Three options, but only two kinds of promise. --max-cost and --max-calls are checks on a run that has already finished — you still get the full report, and then a framed notice gives you the comparison. --budget is a limit on a run still in progress: it stops your program as soon as a finished call takes the total over the line, or can't be priced.
| flag | guarantee | where it belongs |
|---|---|---|
--max-cost | this run did not cost more than N — checked afterwards | CI |
--max-calls | this run did not get stuck in a loop — checked afterwards | CI |
--budget | stopped once its spend passes N — calls already sent still finish and bill | your own machine, overnight jobs, agents you don't trust |
--max-cost, passing
costcatch run --max-cost 0.50 node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 6.7s $0.000024 │ │ │ │ + Step 1 6.7s 36 tok in → 136 tok out $0.000024 │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 1 LLM call · 0 tool calls · 6.7s · $0.000024 │ │ 36 tok in → 136 tok out │ │ at 1 run/day = $0.00/mo · at 100 runs/day = $0.07/mo · at 1000 runs/day = $0.71/mo │ │ run 2026-09-02T06-55-46 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--max-cost, failing
costcatch run --max-cost 0.000001 node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 9.6s $0.000032 │ │ │ │ + Step 1 9.6s 36 tok in → 188 tok out $0.000032 │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 1 LLM call · 0 tool calls · 9.6s · $0.000032 │ │ 36 tok in → 188 tok out │ │ at 1 run/day = $0.00/mo · at 100 runs/day = $0.10/mo · at 1000 runs/day = $0.96/mo │ │ run 2026-09-02T06-55-53 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ × CI GATE: cost $0.000032 exceeds --max-cost $0.0000010 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
null and the cost gate fails rather than passing. A gate that cannot be evaluated must never report success.--max-calls · catch a loop that never ends
A cost limit misses one particular failure: a cheap model going round in circles forever. Five calls where you expected two is a broken loop even when the money involved is trivial.
costcatch run --max-calls 2 node --env-file=.env test_agent.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 100.3s $0.00022 │ │ │ │ + Step 1 25.4s 526 tok in → 167 tok out $0.000039 ⟳ 384 cached │ │ ├─ > get_weather(city="Tokyo") │ │ └─ > get_weather(city="London") │ │ │ │ + Step 2 18.4s 670 tok in → 202 tok out $0.000047 ⟳ 512 cached │ │ ├─ > calculate(expression="(31 - 18) * 9 / 5") │ │ └─ > calculate(expression="240 * 4") │ │ │ │ + Step 3 13.1s 800 tok in → 215 tok out $0.000051 ⟳ 640 cached │ │ └─ > convert_currency(amount=960, from="GBP", to="INR") │ │ │ │ + Step 4 10.1s 917 tok in → 97 tok out $0.000033 ⟳ 768 cached │ │ └─ > calculate(expression="101103.8 / 3") │ │ │ │ + Step 5 33.3s 999 tok in → 189 tok out $0.000052 ⟳ 768 cached │ │ └─ + stop, final answer │ │ │ │ ── summary │ │ 5 LLM calls · 6 tool calls · 100.3s · $0.00022 │ │ 3.9k tok in → 870 tok out │ │ at 1 run/day = $0.01/mo · at 100 runs/day = $0.66/mo · at 1000 runs/day = $6.63/mo │ │ run 2026-09-02T06-56-03 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ × CI GATE: 5 LLM calls exceeds --max-calls 2 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
--budget · stop the program mid-run
Notice what is different below. This agent normally makes four to six calls; this run has two, and the notice appears above the report rather than below it, because the run was stopped rather than finished.
costcatch run --budget 0.00005 node --env-file=.env test_agent.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ × BUDGET: run stopped, spend passed --budget $0.000050 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ costcatch deepseek/deepseek-v4-flash-0731 · ⧗ 13.4s $0.00013 │ │ │ │ + Step 1 8.4s 526 tok in → 163 tok out $0.000038 ⟳ 384 cached │ │ ├─ > get_weather(city="Tokyo") │ │ └─ > get_weather(city="London") │ │ │ │ + Step 2 5.0s 812 tok in → 238 tok out $0.000096 │ │ ├─ > calculate(expression="(31*9/5)+32") │ │ └─ > calculate(expression="(18*9/5)+32") │ │ │ │ ── summary │ │ 2 LLM calls · 4 tool calls · 13.4s · $0.00013 │ │ 1.3k tok in → 401 tok out │ │ at 1 run/day = $0.00/mo · at 100 runs/day = $0.40/mo · at 1000 runs/day = $4.01/mo │ │ │ │ ── warnings │ │ ● Step 2 = 71% of total cost (context bloat likely) │ │ run 2026-09-02T06-57-43 │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
Exit codes
costcatch waits until the very end to set its exit code, so nothing it printed is ever cut off partway down a pipe.
| code | name | when |
|---|---|---|
0 | Success | The run completed and every gate passed |
1 | GateFailed | --max-cost, --max-calls or --budget was breached, or estimate --max-cost was exceeded |
2 | Usage | Bad flag, unknown provider, undetectable runtime, clean with no criterion |
70 | Internal | costcatch's own failure — a missing interceptor, an unwritable temp directory |
child's code | — | Otherwise the traced program's exit status passes through untouched |
Limitations
Stated plainly, because a tool that hides its edges wastes your time.
| limitation | detail | workaround |
|---|---|---|
| Node and Python only | bun and deno do not honour --require, so costcatch would attach and capture nothing. It refuses rather than pretending. | run the script under node |
| HTTP layer only | An SDK using a transport other than the patched ones is invisible. | the empty-trace message lists what is supported |
estimate is ±10% | Character-ratio heuristics, not a real tokenizer; input cost only, not output. | use run for exact spend |
| Cost accuracy tracks the pricing table | A model missing from LiteLLM and OpenRouter is unpriced, and the run total becomes null. | costcatch init to refresh; gates fail closed meanwhile |
stats reads at most 2,000 traces | Newest first, to keep the command fast as history grows. | clean for retention |
| Retry detection is a heuristic | Identical prompts, whatever the reason. | the wording reflects the uncertainty |
| Local only | No hosted dashboard, no team aggregation. | --json on every read command feeds your own |
Trace format
Saved runs are plain JSON files in .costcatch/, named <runId>-<script>.json — or <name>.json if you used --save-as. They are written so that only your own user account can read them.
cat .costcatch/2026-09-02T06-55-29-test_simple.json{ "runId": "2026-09-02T06-55-29", // also the filename and the display id "script": "test_simple.mjs", "runtime": "node", // "node" | "python" "durationMs": 7266, // first request start → last response end "totalCostUsd": 0.00002036, // null if ANY step is unpriced "steps": [ { "type": "llm", // "llm" | "tool" "id": 1, "durationMs": 7266, "provider": "openrouter", "model": "deepseek/deepseek-v4-flash-0731", "inputTokens": 36, // TOTAL prompt tokens, cached included "outputTokens": 116, "cachedTokens": 0, // subset of inputTokens "costUsd": 0.00002036, "toolCalls": [], // [{ name, input }] "isStreaming": false, "finishReason": "stop", "statusCode": 200, "error": null, // { type, message } on failure "content": { "system": null, "messages": [{ "role": "user", "content": "… «email» … «phone» …" }], "output": " Hello John, …", "truncated": false // true once the 8 MB content budget is hit }, "retryOf": null // step id whose prompt this repeats } ], "warnings": [], // [{ severity, code, message, stepIds }] "summary": { "llmCalls": 1, "toolCalls": 0, "totalInputTokens": 36, "totalOutputTokens": 116, "totalSteps": 1, "retries": 0, "wastedCostUsd": 0 }, "startedAt": "2026-09-02T06:55:29.723Z", "command": "node --env-file=.env test_simple.mjs" // redacted }
The fields worth knowing
runId | The timestamp that names the run. It is also the filename, so you can paste it straight into show, replay or diff |
totalCostUsd | Empty if even one call used a model with no price. Never a half-finished sum — which is why the cost check fails rather than passing |
inputTokens | The full size of the prompt that went out, counted the same way for every provider |
cachedTokens | How much of that prompt the provider had already seen and charged less for. Always part of inputTokens, never on top of it |
reasoningTokens | How much of the output was thinking. Always part of outputTokens, never on top of it, and billed at the same rate. null when the provider reports no split — Anthropic bills thinking inside output_tokens without breaking it out |
toolCalls | What the model asked your code to do on that call, with the arguments it passed |
retryOf | Set when this call re-sends a prompt an earlier call already sent |
content.truncated | Set once the saved text hits its size limit, so an empty record is never mistaken for a call that sent nothing |
summary.retries | How many prompts were sent more than once. wastedCostUsd is what those repeats cost you |
inputTokens is always the full total and cachedTokens is always a part of it.Warning engine
Six checks, nothing to set up. They run on every saved run and stay quiet when there is nothing worth saying.
| code | severity | fires when |
|---|---|---|
http_error | critical | A call came back with an error rather than an answer |
context_growth | warn / critical | The last prompt is at least 3× the size of the first. 10× or more is critical |
context_spike | warn | One prompt is at least 4× the size of the one just before it |
duplicate_tool_call | warn / info | The same tool was asked the same thing twice, or something more than 80% alike |
cost_concentration | warn | A single call accounts for more than half of what the whole run cost |
latency_spike | info | One call took 2.5× as long as the middle of the others, and more than 5 seconds |
Error paths
A good error message is a feature. Each of these says what was tried, what the rule is, and what to do instead.
An unsupported runtime
costcatch run ruby agent.rb× Could not detect runtime for: ruby The first argument must be a python or node executable. Supported: python, python3, python3.x, node, nodejs, npx, tsx, ts-node bun and deno are not supported: neither honours --require, so nothing would be captured. Use `node` for those scripts to trace them. Example: costcatch python my_agent.py
bun and deno are refused on purpose. Neither supports the hook costcatch needs, so it would attach itself and then record nothing at all — and quietly recording nothing is worse than refusing to start.
A mistyped provider name
costcatch run --filter openai-typo node -e 1× Unknown provider for --filter: openai-typo Known providers: openai, anthropic, openrouter, groq, mistral, google, ollama, cohere, generic
A mistyped --filter would otherwise hide every call and report a perfectly believable empty run — which reads as "my agent never called a model". Checking the name against the real list turns a quiet wrong answer into a loud one.
No calls captured
costcatch run node -e console.log('no llm here')┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ △ No LLM API calls detected during this run. │ │ Supported: openai · anthropic · openrouter · groq · mistral · google · ollama · cohere · │ │ generic │ │ If your agent did call an LLM, it may use an unsupported transport. │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
Filtered to a provider that was not called
costcatch run --filter anthropic node --env-file=.env test_simple.mjs┌──────────────────────────────────────────────────────────────────────────────────────────────┐ │ △ No LLM API calls to anthropic during this run. │ │ --filter anthropic hides any calls to other providers. │ │ Re-run without the flag to see whether other providers were called. │ └──────────────────────────────────────────────────────────────────────────────────────────────┘
The filter is applied while the run is being recorded, so at this point costcatch genuinely does not know whether other providers were called. Saying "no calls found" would be a lie; saying "calls were hidden" would be a guess. So it says what the option does, and tells you how to find out.