How it works
retake record -- <cmd> and retake replay -- <cmd> start a local HTTP proxy, then run
<cmd> with ANTHROPIC_BASE_URL pointing at it. Anthropic SDKs, and the example agent,
read that variable, so the command needs no changes and can be in any language: a test
runner, a script, or a binary.
- Record: the proxy forwards each request to the real API (your
ANTHROPIC_BASE_URLif you had one set, elsehttps://api.anthropic.com) and appends the request and response to the take. Streamed ("stream": true) responses reach the command as they arrive, and each event is appended to the take as it completes. - Errors while recording: account errors refuse the recording, and transient errors are dropped when a retry succeeds; see Errors while recording.
- Replay: the proxy never contacts the network. It matches each incoming request
against the recorded ones by content (method, path, query, the relevant headers and
the JSON body, ignoring key order and whitespace, after
normalization rules) and returns the recorded response.
A request with no match, or more requests than were recorded, fails the run with a
description of the closest recorded exchange. If
ANTHROPIC_API_KEYis unset, the command gets a placeholder so SDKs that require a key still start. - Streams on replay: recorded events are sent in order.
--pacing(orRETAKE_PACING) sets the timing:instant(the default),realtime(at the recorded offsets), or a speed-up factor such as4. A stream that the client closed during recording ends the same way on replay. - Headers: only allow-listed headers are stored. API keys, other authentication
headers and cookies are never written to a take.
retake.tomlcan add headers (see Redaction). - Test-runner plugins:
retakealso passesRETAKE_URLand a per-runRETAKE_TOKENto the command. A plugin (pytest’s is the only one so far) uses them to call control endpoints on the proxy’s port, under/_retake/:helloto agree on a protocol version, thentest/beginandtest/end(withpassed,failedorskipped) around each test. Its requests carry the test ID in anx-retake-testheader, so concurrent workers are told apart. Each test’s take is written as<name>.take.partialand renamed when the test passes (at the end of the run when_session.takehas dependents).test/endwaits for the test’s requests still in flight, up to--inflight-timeoutseconds (default 120); requests for a test that has ended are rejected with a400of typeretake_test_finishedand listed in the summary (--fail-on-late-requestsfails the run). Until a plugin callshello, everything goes to_main.takeas before.
The exit code is the wrapped command’s, or non-zero when the command succeeded but
Retake’s part of the run failed (including a test whose take Retake refused or could not
replay).
A command that cannot be started at all (not found, or not executable) exits 127 or 126,
as in a shell; it made no requests, so retake record writes no take, leaves no
.partial, and leaves an existing take unchanged.