Repository navigation
Lab Capture
The command claudetto-capture of the plugin claudetto-lab is a local proxy for Claude Code.
A proxy sits between two programs and passes their messages on.
This one logs each request and sizes the parts of the first request that has tools.
You see which part of a request costs the most tokens.
claudetto-capture [--port 8787] [--out DIR] [--upstream URL] [--no-count]
ANTHROPIC_BASE_URL=http://127.0.0.1:8787 ENABLE_TOOL_SEARCH=true claude
The proxy listens on 127.0.0.1 and forwards each request to the upstream.
It writes the body of each /v1/messages request to DIR/request-<run>-<n>.jsonl, as one JSON line.
just capture runs the proxy from the repository.
| Option | Meaning |
|---|---|
--port |
A whole number from 1 to 65535. The default is 8787. Another value exits 2 with a message. |
--out |
The folder for the files. The default is claudetto-capture in the temp folder. |
--upstream |
The server that gets the requests (see below). |
--no-count |
Turn the sizing off. |
The proxy takes the upstream from the first of these that is set:
- The
--upstreamflag. -
ANTHROPIC_BASE_URL. -
https://api.anthropic.com.
The proxy exits 1 when the upstream is not a valid URL.
It also exits 1 when the upstream is its own address, because the requests would loop.
The check looks at the hosts 127.0.0.1, localhost, and [::1] with the port of the proxy.
- The proxy never writes a request header, because the headers carry the credential.
- The proxy sends upstream only these headers:
authorization,x-api-key,anthropic-*,content-type,user-agent,x-app, andx-stainless-*. - In an error text of a
count_tokenscall, each credential value of the request becomes[redacted]. This holds also when the upstream echoes the value.
The proxy sizes the first /v1/messages request that has tools.
It uses the count_tokens endpoint and the credential of that request.
- It counts the full request.
- It counts the request again without one tool, one block, or one section of a long text. The difference is the token cost of that part, with its wrapper.
- It prints the parts from the largest to the smallest, and the rest that no part holds.
The report goes to DIR/report-<run>-<n>.jsonl and to standard output.
A body that is not JSON is forwarded unchanged.
The proxy does not save or size it.
If the full count fails, the proxy retries with fixes, in this order: no thinking, then system messages as user text.
The report lists the fixes that it used.
A count_tokens reply with no whole input_tokens is an error.
The report then shows the part as not counted, and it never shows NaN.
The bounds are in slices/capture/limits.ts.
claudetto
- Start
- Slices
- Add-Ons
- Reference
- Rationale
- Evidence
- Development
Claude Code 2.1.303
- Start
- Models and Context
- Configure
- Extend
- Findings