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

Getting started

The repository includes a small Anthropic agent, examples/refund/main.rs, that uses tools to look up and refund an order, and a take recorded from it, examples/refund/_main.take.

With retake installed, run the commands below from a clone of the repository. cargo run --example refund builds and runs the example, which needs Rust 1.88 or later and a C compiler; the first run downloads and compiles its dependencies.

git clone https://github.com/simdugas/retake
cd retake

Replay (no API key)

env -u ANTHROPIC_API_KEY ANTHROPIC_MODEL=claude-haiku-5-5 \
  retake replay --takes-dir examples/refund -- cargo run -q --example refund

The agent runs as usual, but every API response comes from the take:

> refund half of order 100
> (thinking)
> [get_order {"id":100}]
>  {"id":100,"status":"Arrived","total":8000,"refund":0}
> (thinking)
> [refund_order {"amount":4000,"id":100}]
>  order 100 refunded 4000 cents
> Order 100 has been refunded half its total: $40.00 (4000 cents) of the $80.00 order. It had no prior refunds.
retake: replayed 3 exchange(s) from examples/refund/_main.take
retake: matches: 3 exact, 0 with rules

ANTHROPIC_MODEL must match the recording because the model is part of each request. If a request differs from what was recorded, Retake answers it with an error, explains the difference, and the run exits non-zero. For example, with ANTHROPIC_MODEL=claude-sonnet-5-5:

retake: no recorded response for POST /v1/messages (retake_no_match):
closest recorded exchange is #0 (first 1 of 1 message(s) identical); it differs in:
  body model: recorded "claude-haiku-5-5", request "claude-sonnet-5-5"
...
retake: replay failed: 1 request(s) had no recorded response (1 unmatched, 0 exhausted, 0 withheld)

Record (needs an API key)

ANTHROPIC_API_KEY=... ANTHROPIC_MODEL=claude-haiku-5-5 \
  retake record --takes-dir my-takes -- cargo run -q --example refund

This makes real, billed API calls and writes my-takes/_main.take. Recording over an existing take asks for confirmation on a terminal; elsewhere it needs --yes (or RETAKE_ASSUME_YES=1).

More examples

Next

  • How it works: what record and replay do around your command.
  • pytest: one take per test with the pytest-retake plugin.
  • The take file: what a recording contains.
  • Redaction: what is kept out of takes, and how to add your own patterns.