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

Redaction

Secrets matching a configured pattern are redacted before any byte is written to disk. Content Retake cannot scan is never written unless you opt in with --allow-unscanned.

What is redacted, in every record before it is appended to the take (.partial files included): the request path and query, the values of allow-listed request and response headers, request and response bodies (every JSON string, object keys included, and non-JSON text), and stream events.

Placeholders

A secret becomes <redacted:NAME:N>, where NAME is the pattern’s name and N counts distinct values of that pattern in the take: the same value always gets the same placeholder within a take. Placeholders contain no quotes or backslashes, so they are safe inside JSON strings and JSON fragments, and nothing in them is derived from the secret. A placeholder written into a take is never matched again.

On replay the client sends the real secret again. Retake redacts the incoming request the same way and renumbers placeholders on both sides by first appearance within the request (object keys in sorted order), then compares. What a secret was does not matter for matching; which values are equal does: a request that uses one key where the recording used two different ones does not match. Mismatch descriptions only ever show placeholders.

Abridged, a request that sent a key and a streamed reply that echoed it across three events (the key’s remainder trimmed from the second and third):

{"type":"request","exchange":0,...,"body":{"messages":[{"content":"my key is <redacted:anthropic-api-key:1>","role":"user"}],...}}
{"type":"event","exchange":0,"offset_ms":3,"event":"content_block_delta","data":{"delta":{"text":"Key: <redacted:anthropic-api-key:1>","type":"text_delta"},"index":0,"type":"content_block_delta"}}
{"type":"event","exchange":0,"offset_ms":3,"event":"content_block_delta","data":{"delta":{"text":"","type":"text_delta"},"index":0,"type":"content_block_delta"}}
{"type":"event","exchange":0,"offset_ms":4,"event":"content_block_delta","data":{"delta":{"text":" done","type":"text_delta"},"index":0,"type":"content_block_delta"}}

Built-in patterns

On by default. Each starts with a fixed, distinctive prefix, so ordinary prompt text does not trigger them.

NameMatches
anthropic-api-keyAnthropic API and admin keys (sk-ant-api03-…, sk-ant-admin01-…)
openai-api-keyOpenAI sk-proj-, sk-svcacct-, sk-admin- keys, and legacy 48-character sk- keys
aws-access-key-idAWS access key IDs (AKIA…, ASIA…, ABIA…, ACCA…, 20 characters)
github-tokenGitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_, github_pat_)
slack-tokenSlack tokens (xoxb-, xoxp-, xoxa-, xoxo-, xoxs-, xoxr-)
google-api-keyGoogle API keys (AIza…, 39 characters)
pem-private-keyPEM private key blocks from BEGIN to END (RSA, EC, OpenSSH, PKCS#8, encrypted), up to 6 KiB, with real newlines or \n escapes
retake-tokenThe run’s own RETAKE_TOKEN; always on

AWS secret access keys, passwords, and personal data have no reliable format; add your own patterns for them.

retake.toml

Read from the current directory, or from --config FILE / RETAKE_CONFIG. Every key is optional; unknown keys are an error. Its JSON Schema is schema/retake-toml.schema.json (see Editor support).

[redact]
builtins = true                      # false turns every built-in pattern off
disable  = ["google-api-key"]        # or turn some off by name

[[redact.patterns]]
name    = "employee-id"              # a-z, 0-9 and `-`; used in the placeholder
regex   = 'EMP-[0-9]{6}'             # Rust `regex` syntax
# max_len = 64                       # bytes; required when the regex is unbounded

[headers]
request  = [{ name = "x-tenant", match = true }]   # `match` is required
response = [{ name = "x-ratelimit-remaining" }]
  • Patterns use Rust regex syntax (linear time; no look-around or backreferences). Retake computes each pattern’s longest possible match. A regex without an upper bound (+, *, {n,}) is refused when the file loads unless it declares max_len; a pattern that can match the empty string is refused. A match longer than a declared max_len is still redacted when it is in view, but may slip past the stream window; the final scan then fails the recording. When two patterns overlap, the earliest match wins, then the longest, then user patterns over built-ins.
  • Headers extend the allow-lists. Each added request header declares whether it counts for replay matching (match = true compares its value exactly, after redaction). Credential headers and cookies (authorization, x-api-key, cookie, set-cookie, …) cannot be added. Added header values are redacted like everything else, but a header that carries a secret in no known format is recorded as-is.
  • [match] holds normalization rules; see Normalization rules.

Streams

A secret can be split across server-sent events. For each content block, Retake holds deltas back from the take until the text after the oldest one is at least the longest possible match of any active pattern (6 KiB with the built-ins, because of PEM blocks), or the block ends. The placeholder is then written whole into the event where the secret starts, and the rest of the secret is trimmed from the events after it, which can leave an event with empty text. On replay, the client reassembles the block with the placeholder in place of the secret. Text and thinking deltas are scanned as text; input_json_delta fragments are scanned as raw JSON, and the reassembled JSON stays valid. Other events are written in arrival order behind held deltas.

Holding back only delays writes to the take. The client receives every byte as the provider sends it; nothing is buffered beyond the window.

Final scan

Before a take is finalized, Retake reads the .partial back and scans every string, and each content block’s text joined across events. If it finds a match outside a placeholder, the recording fails, the .partial is deleted and the previous take is kept. The message names the pattern and the line, never the value. A refused recording’s .partial is scanned the same way before it is kept for debugging, and deleted if the scan finds anything.