Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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_URL if you had one set, else https://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_KEY is unset, the command gets a placeholder so SDKs that require a key still start.
  • Streams on replay: recorded events are sent in order. --pacing (or RETAKE_PACING) sets the timing: instant (the default), realtime (at the recorded offsets), or a speed-up factor such as 4. 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.toml can add headers (see Redaction).
  • Test-runner plugins: retake also passes RETAKE_URL and a per-run RETAKE_TOKEN to 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/: hello to agree on a protocol version, then test/begin and test/end (with passed, failed or skipped) around each test. Its requests carry the test ID in an x-retake-test header, so concurrent workers are told apart. Each test’s take is written as <name>.take.partial and renamed when the test passes (at the end of the run when _session.take has dependents). test/end waits for the test’s requests still in flight, up to --inflight-timeout seconds (default 120); requests for a test that has ended are rejected with a 400 of type retake_test_finished and listed in the summary (--fail-on-late-requests fails the run). Until a plugin calls hello, everything goes to _main.take as 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.