Agent VCR documentation
Each section is a short summary with a working snippet. The full guide for every topic lives on GitHub, linked at the end of each section.
Install
Python 3.9β3.13 on Linux, macOS and Windows, all tested in CI. The airbag and the ACID workspace need git on your PATH. The core package needs no API key and no account.
pip install ai-agent-vcr
vcr --version # vcr 1.7.1
The core install gives you the vcr and sentinel commands, the Python API and the pytest plugin. Add extras for the rest:
| Extra | Adds |
|---|---|
ai-agent-vcr[tui] | Terminal debugger (vcr run.vcr) |
ai-agent-vcr[dashboard] | Local web dashboard and server (vcr serve) |
ai-agent-vcr[langgraph] | LangGraph integration |
ai-agent-vcr[crewai] | CrewAI integration |
ai-agent-vcr[openhands] | OpenHands SDK 1.x (Python 3.12+) |
ai-agent-vcr[all] | Everything optional |
Package name: install ai-agent-vcr. The agent-vcr package on PyPI is a different project.
Quickstart
The five-minute tour: one snippet per feature, all offline. If you use a coding agent, the first two steps are all you need.
# 1. See what the airbag would do, without running anything
vcr airbag check "rm -rf src"
# π DESTRUCTIVE: destroys project data β snapshot first, undo with `vcr undo`
# 2. Arm your agents once: every tool call in a git project now gets a snapshot first
vcr airbag install
vcr doctor # β everything protected? prints the exact fix if not
Building your own agent? Record a run and jump around in it:
from agent_vcr import VCRPlayer, VCRRecorder
with VCRRecorder() as rec:
rec.start_session(session_id="hello")
rec.record_step("plan", {"task": "refund"}, {"plan": ["look up", "refund"]})
rec.record_step("act", {"plan": ["look up", "refund"]}, {"status": "refunded"})
player = VCRPlayer.load(".vcr/hello.vcr")
print(player.list_nodes()) # ['plan', 'act']
print(player.goto_frame(0)) # {'plan': ['look up', 'refund']}
From there: roll back files with the ACID workspace, replay a verified run with Ghost Replay, gate it with Agent CI, and scan agent-written code with Sentinel.
Airbag: undo, redo, rewind
Built-in checkpoints in coding agents only track their own file-edit tools; a shell command like rm -rf, git reset --hard or sed -i slips past them. The airbag hooks in before every tool call and snapshots your project into a private git store outside it, so deleting the project can't delete its snapshots.
- Protected: tracked and untracked files (honoring
.gitignore), small ignored files such as.env*and SQLite databases (copied consistently even while open), and your.gitwhen a command would delete or damage it. - Never touched: your own
.git(HEAD, branches, index, stash), unless it's missing or broken and needs restoring. - Cost: about 0.1 s per tool call, mostly Python start-up.
Install for your agent
With no names, vcr airbag install installs for every supported agent on your PATH, in each agent's user-level config: one install protects every project and nothing is written into your repositories. Name one or several (vcr airbag install claude codex), use --all, or --project for a per-project, per-developer install. Snapshots are taken in git repositories and in folders you opt in with vcr airbag protect; never in your home folder. Outside them, irreversible commands and tree deletions are still stopped. Upgrading from an earlier version? Run vcr airbag install once: it moves old project-level hooks to user level.
| Agent | Install | Irreversible commands |
|---|---|---|
| Claude Code | vcr airbag install claude | asks you |
| OpenAI Codex CLI | vcr airbag install codex | blocked until vcr airbag allow |
| Gemini CLI | vcr airbag install gemini | asks you (0.36+), otherwise blocked |
| Cursor (IDE + CLI) | vcr airbag install cursor | blocked until vcr airbag allow |
| GitHub Copilot CLI | vcr airbag install copilot | asks you |
| OpenHands | vcr airbag install openhands | blocked, or asks with confirm=True |
| OpenCode 1.x | vcr airbag install opencode | blocked until vcr airbag allow |
| Cline | vcr airbag install cline | task cancelled |
| Devin Local | vcr airbag install devin | blocked until vcr airbag allow |
| Anything else | vcr airbag run -- aider | no interception; a snapshot every 2 s |
Per-agent gotchas: review new hooks once with /hooks in Codex; Gemini CLI runs hooks only in trusted folders; restart running Copilot CLI sessions; Cline hooks don't install on Windows. If you move or reinstall the Python that ran vcr airbag install, the hook goes quiet instead of failing; vcr doctor --fix points it at the new one.
Undo, redo, rewind
vcr undo # back to just before the last agent action that changed something
vcr undo 3 # three actions back
vcr undo 2 --dry-run # preview: + comes back, - is removed, ~ gets its old content
vcr redo # undo the last undo or rewind
vcr rewind # timeline of snapshots (same as `vcr airbag log`)
vcr rewind 12 # restore snapshot #12
Every command takes --project-dir PATH when you're not inside the project, and most take --json.
Four levels, and who decides
Every shell command is classified before it runs. Ask about any command with vcr airbag check.
| Level | What happens | Example |
|---|---|---|
| read | Runs; no snapshot needed | git status |
| write | Snapshot, then run | echo x > out.txt |
| destructive | Snapshot, then run; undoable | rm -rf src |
| irreversible | Snapshot, then a human decides | git push --force |
vcr airbag check "psql -h prod.db -c 'DROP TABLE users'"
# β IRREVERSIBLE: cannot be undone by a snapshot β the airbag asks a human first
# β’ SQL DROP on a remote database (prod.db) β server data is not in your project files, β¦
vcr airbag allow # let one stopped command through, once, within 10 minutes
What it can't undo
- Anything outside the project directory. Deletes and writes that land outside it are classified irreversible and stopped.
- Remote state: server databases, cloud resources, pushed commits, published packages, sent requests. Stopped for confirmation, not undone. The one exception is a local Postgres database you configure.
- Ignored dependency and build directories (
node_modules/,.venv/,dist/), files over 25 MB, nested git repositories and empty directories. - Commands run without a hook.
vcr airbag run --snapshots every 2 seconds but can't stop anything. - It's a guard, not a sandbox. The classifier is a parser; a command hidden in a script can get past it. The snapshot still happens, so project files stay undoable.
Find the breaking action: vcr bisect
Tests were green before the agent started, it has made 40 tool calls since, and nothing is committed. Because every tool call has a snapshot, vcr bisect binary-searches them the way git bisect would and names the action that broke the tests. No model tokens.
vcr bisect -- pytest -q
# #6 (current) β fail (0.4s)
# #1 β pass (0.4s)
# #3 β pass (0.4s)
# #4 β fail (0.4s)
#
# π― First bad action: sed -i 's/round(sum(prices), 2)/int(sum(prices))/' billing.py
# snapshot #3 passes β #4 fails (4 test runs)
# Go back to just before it: vcr rewind 3
Each run happens in a temporary checkout of a snapshot. Your project, its .git and the snapshots are never modified. About log2(actions) + 2 runs: 100 actions take about nine.
vcr bisect --good 2 --bad 5 -- pytest -q # only search between snapshots #2 and #5
vcr bisect --timeout 60 -- pytest -q # per run; a timeout counts as a failure
vcr bisect --copy-ignored -- pytest -q # link node_modules/.venv into each checkout
vcr bisect -- "pytest -q && ruff check ." # one quoted string runs through the shell
vcr bisect --json -- pytest -q
Watch out for: ignored dependencies aren't in snapshots (use --copy-ignored), editable installs can import the project's copy instead of the checkout's (set pythonpath = ["src"] in pytest's config), and flaky tests confuse any bisect.
Rewind your local Postgres
A file snapshot can't undo DROP TABLE on a database server. For a local development database you name explicitly, the airbag runs pg_dump right before destructive SQL, and vcr undo or vcr rewind restores the database together with the files.
export AGENT_VCR_AIRBAG_DATABASES=postgresql://localhost:5433/app_dev # comma-separated
vcr airbag db list
# β app_dev (localhost:5433)
vcr airbag check "psql -h localhost -p 5433 -d app_dev -c 'DROP TABLE users'"
# π DESTRUCTIVE: β¦ SQL DROP on local database app_dev (dumped with pg_dump before it runs)
vcr undo # files and the database back
vcr airbag db snapshot -m "before the migration" # a manual database save point
vcr airbag db restore 11 # only the database back to #11
Per project, the same list can live in .vcr/airbag-databases.json as {"databases": [...]}. Keep passwords out of that file: use the environment variable, ~/.pgpass or a local socket.
- Local only. URLs must point at
localhost,127.0.0.1,::1or a unix socket. Anything else is refused, never dumped. - The prompt is skipped only when the target is certain: a
psql -ccommand that names a configured local database. ORM and framework commands (prisma migrate reset,rails db:reset) still ask, with a dump taken. - A restore puts the whole database back, and dumps the current state first, so the restore is undoable too. Postgres only, through
pg_dump,pg_restoreandpsqlon your PATH.
MCP server: vcr mcp
A stdio Model Context Protocol server that gives any MCP-capable agent the airbag as tools: it can ask whether a command would be stopped before running it, take a save point before a risky change, read its own timeline, and preview an undo. Standard library only; nothing leaves your machine.
claude mcp add agent-vcr -- vcr mcp # Claude Code
codex mcp add agent-vcr -- vcr mcp # Codex CLI
gemini mcp add agent-vcr vcr mcp # Gemini CLI
Cursor and other clients that use the common mcpServers format:
{
"mcpServers": {
"agent-vcr": { "command": "vcr", "args": ["mcp"] }
}
}
| Tool | Changes anything? |
|---|---|
airbag_status Β· airbag_timeline Β· airbag_check | No |
airbag_snapshot | Only the snapshot store, never project files |
airbag_undo Β· airbag_rewind | Preview only, unless called with dry_run: false and confirm: true |
recordings_list Β· recording_summary | No |
Snapshot, undo and rewind only act on the project the server was started for, so an agent can't be talked into rewinding a different one. vcr must be on the PATH the agent sees; otherwise register its full path.
Recording and replay
VCRRecorder writes every step, LLM call, tool call, error and checkpoint of your agent to an append-only .vcr file, one JSON object per line. VCRPlayer jumps to any frame or checkpoint, diffs frames, forks a run and resumes it.
from agent_vcr import VCRPlayer, VCRRecorder
recorder = VCRRecorder(output_dir=".vcr")
recorder.start_session("billing-fix")
recorder.record_step("planner", {"task": "add invoice status"}, {"plan": "migration first"})
recorder.record_checkpoint({"plan": "migration first"}, label="plan-approved")
path = recorder.save()
player = VCRPlayer.load(path)
player.goto_checkpoint("plan-approved") # jump to any frame or checkpoint
player.verify_integrity() # durability checks
Open a recording in the terminal debugger with vcr .vcr/billing-fix.vcr (needs the [tui] extra), or turn it into a checksummed bundle for a bug report with vcr bundle export. For long runs, VCRRecorder(max_cached_frames=N) keeps memory bounded.
Ghost Replay
Promote a run you've reviewed to a golden run, keyed by the task and, optionally, an identity (model, prompt hash, code commit, tool schema). Replaying it returns the recorded outputs with no model calls and no tokens.
from agent_vcr import GoldenRunCache, VCRRecorder
rec = VCRRecorder()
rec.start_session(session_id="good-run")
rec.record_llm_call("gpt-4o", [{"role": "user", "content": "refund #42"}],
{"content": "Refunded."}, tokens_input=900, tokens_output=100,
latency_ms=1800, cost_usd=0.012)
rec.save()
cache = GoldenRunCache()
cache.save_golden_run("refund order 42", rec) # pin the verified run
outputs, ledger = cache.replay("refund order 42") # zero model calls
print(ledger.tokens_saved, ledger.cost_saved_usd) # 1000 0.012
Ghost Replay returns what was recorded; change the task or its identity and you need a fresh run. Partial modes re-run only the steps you changed.
pytest plugin
Installed with the package and picked up by pytest 6.2+ automatically. The agent_vcr fixture runs your agent live on the first test run and saves it as a golden; every run after that replays it without calling your agent. assert_matches_golden() fails the test on behavior, cost, token or latency regressions, with a readable diff.
import pytest
@pytest.mark.agent_vcr(task="triage ticket t_123", identity={"model": "gpt-5"})
def test_triage(agent_vcr):
run = agent_vcr.run(triage) # 1st run: calls the agent; after: replays it
assert run.output["queue"] == "billing"
agent_vcr.assert_matches_golden(max_cost_usd=0.05)
Here triage(recorder) is your agent: it records what it did on the recorder it's given and returns its result.
pytest -q # first run records; later runs replay
AGENT_VCR_RECORD=none pytest -q # CI: a missing golden fails, the model is never called
pytest --vcr-record=all --vcr-fail-on=never 'test_triage.py::test_triage' # accept new behavior
Commit .vcr/pytest/golden/. A failed run never replaces the golden. Also: --vcr-dir, --vcr-fail-on=degraded|failed|never, the vcr_recorder fixture for plain recording, and it's xdist-safe.
Agent CI
Unit tests for agent behavior. Pin a reviewed run as a dataset case with expectations, let your test harness record a fresh candidate for each case on every pull request, and vcr ci run returns pass, degraded or fail with an exit code. The gate compares recordings; it never calls a model.
vcr dataset create refunds
vcr dataset add refunds --task "refund order 42" --case-name refund-42 \
--vcr .vcr/hello.vcr --expect-state '{"status":"refunded"}'
# your harness writes a fresh recording per case: .vcr/candidates/refund-42.vcr
vcr ci run --dataset refunds --candidates .vcr/candidates --fail-on degraded
Cases can also cap cost, latency and tokens, forbid tools and require checkpoints. In GitHub Actions it's one step:
- name: Compare with reviewed baselines
uses: ixchio/agent-vcr@v1.7.1
with:
dataset: refunds
candidates-dir: .vcr/candidates
fail-on: degraded
package: ai-agent-vcr==1.7.1
The action writes the Markdown report to the job summary, annotates failed cases and uploads the JSON and Markdown reports as an artifact.
ACID workspace
Transactions for the agent you write. ACIDWorkspace works on a git branch of its own: each savepoint is a git commit plus a recorded state frame, rollback rewinds files and agent state together, and only the good attempt is merged. Ships in the core package; OpenHands isn't required.
from agent_vcr.integrations.openhands import ACIDWorkspace
with ACIDWorkspace("/path/to/repo") as ws: # begin() on enter
ws.savepoint({"phase": "planned"}, node_name="planner")
... # the agent works on an isolated branch
ws.rollback(to_frame_index=0) # rewind files + state to a savepoint
# clean exit β commit (merge); exception β abort (everything restored)
- Files git doesn't own, like an ignored
.envor a local SQLite file, are copied into a private escrow under.git/vcr-escrow, so rollback restores them byte for byte and their contents never land in a commit or a recording. - Files the agent created after a savepoint are removed on rollback.
- Absolute paths,
..and symlink escapes are rejected.
See it in the 18-second demo, rendered from a real run.
Sentinel
A code-quality guard for agent-written Python, built on the standard library's ast: no extra dependencies, no network, no LLM. It catches syntax errors, oversized or overly complex functions, bloated files, and the same function pasted into a second file, which a one-file linter never sees.
sentinel scan ./src # exit 0 passed Β· 1 critical Β· 2 blocked Β· 3 no Python files Β· 4 no folder
sentinel scan . --max-lines 80 --max-complexity 5 --max-file-lines 300 --max-params 4
sentinel watch ./src # rescan changed files every second
Every scan leaves an audit trail in .vcr/sentinel-scan.vcr inside the scanned folder. Attached to an OpenHands SDK 1.x conversation, it rejects the agent's next action after a blocker until the file is fixed:
from openhands.sdk import Conversation
from openhands_sentinel import Sentinel, SentinelConfig
sentinel = Sentinel(SentinelConfig(block_on_blocker=True))
conversation = Conversation(agent=agent, workspace=ws, callbacks=[sentinel])
sentinel.bind(conversation) # lets Sentinel reject actions
Dashboard
Three ways to look at recordings: a keyboard-driven terminal debugger, a local web dashboard with a live feed, and a self-hosted project store you can push recordings to from CI.
pip install "ai-agent-vcr[tui,dashboard]"
vcr .vcr/demo.vcr # terminal debugger: j/k to move, 3 for diff, q to quit
vcr serve # API and web UI on http://127.0.0.1:8000
- Safe by default.
vcr serverefuses to listen on anything but127.0.0.1without a token (AGENT_VCR_ADMIN_TOKENorAGENT_VCR_AUTH_TOKEN). - Browser sign-in. On a token-protected server, sign in once at
/dashboard/login(or open/dashboard?token=β¦) and get a short-lived HttpOnly, SameSite=Strict session cookie, Secure on HTTPS. Sign out at/dashboard/logout. - Team store. Add
--data-dirand an admin token for projects, scoped tokens andvcr cloud push/pull/replay. It's files on one disk with no built-in TLS: put a reverse proxy in front for anything non-local.
Integrations
Every integration writes the same thing: one frame per step in a .vcr file. Recording never breaks your agent: integration errors are logged, and your exceptions and return values pass through untouched.
# LangGraph: no graph changes, pass the callback per run
from agent_vcr.integrations.langgraph import LangGraphCallback
app.invoke(inputs, config={"callbacks": [LangGraphCallback(recorder)]})
# CrewAI: wrap the kickoff
from agent_vcr.integrations.crewai import VCRCrewAI
result = VCRCrewAI(recorder).kickoff(crew)
# OpenHands SDK: snapshot before every action, block irreversible ones
from agent_vcr.integrations.openhands_airbag import AirbagCallback, protect
airbag = AirbagCallback()
conversation = Conversation(agent=agent, workspace=ws, callbacks=[airbag])
protect(conversation, airbag)
| You use | Do this | Needs |
|---|---|---|
| Plain Python | record_step, record_llm_call, record_tool_call, record_error, record_checkpoint | core |
| LangGraph | LangGraphCallback(rec) or VCRLangGraph(rec).wrap_graph(builder) | [langgraph] |
| CrewAI | VCRCrewAI(rec).kickoff(crew) or with VCRCrewCallback(rec): | [crewai] |
| OpenHands SDK 1.x | VCRRuntime(), AirbagCallback(), Sentinel() as callbacks | [openhands] |
| Claude Code | vcr init --claude-code records every session (records only; the airbag is what undoes) | core |
| n8n / HTTP | POST /api/workflows/{name}/trigger | [dashboard] |
FAQ and more
Short answers to the questions people ask most:
- Claude Code, Cursor and Gemini CLI have checkpoints. Why do I need this?
- How is it different from LangSmith, Langfuse, Phoenix or AgentOps?
- Does it send my code or data anywhere?
- Where are the snapshots, how big do they get, how do I clean up?
- Does it work on Windows and macOS?
- Is it production-ready?
More documentation
- Architecture: the package map and stability levels.
- Railway deployment: host the server with TLS and tokens.
- Experimental, tested but the API may change: SuperAgent, workflow engine, reliability intelligence.
- Benchmark dashboard: measured performance history.
CLI cheat sheet
vcr <command> --help shows every option.
| Command | What it does |
|---|---|
vcr airbag install [agentβ¦] | Arm the hooks, user-level (default: every agent on your PATH; --all, --project) |
vcr doctor [--fix] | Check the install, hooks and protection; print or apply the exact fix |
vcr undo [N] [--dry-run] | Restore files to just before the last (N-th) agent action |
vcr redo | Undo the last undo or rewind |
vcr rewind [N] | Timeline of snapshots, or restore snapshot #N |
vcr bisect -- <test cmd> | Find the agent action that broke the tests |
vcr airbag check "<cmd>" | Classify a command without running it |
vcr airbag allow | Approve the last stopped command for one retry |
vcr airbag snapshot -m "msg" | Take a manual snapshot |
vcr airbag status Β· vcr airbag log | Installed hooks and store Β· timeline |
vcr airbag db list|snapshot|restore | Local Postgres dumps |
vcr airbag gc --keep-days 7 | Delete old snapshots and their dumps |
vcr airbag run -- <cmd> | Periodic snapshots for agents without hooks |
vcr airbag uninstall [agentβ¦] | Remove only the airbag's hook entries |
vcr mcp | MCP server on stdio |
vcr <file.vcr> Β· vcr tui <file.vcr> | Terminal debugger |
vcr serve | Dashboard and API server (same as vcr-server) |
vcr dataset create|add|list|show|remove | Agent CI datasets |
vcr ci run --dataset NAME --candidates DIR | Run the regression gate |
vcr bundle export|import|verify Β· vcr reproduce | Portable .vcrb bundles |
vcr cloud login|push|pull|replay | Self-hosted project store |
vcr init --claude-code | Record Claude Code sessions |
sentinel scan|watch [DIR] | AST quality checks |