rewindagents
Your coding agent ran rm -rf. Take it back.
Undo for AI coding agents, including what they do in the shell. rewindagents records every tool call your
coding agent makes and keeps a copy of each file before a step changes it, including files only a shell command
touched (rm -rf, sed -i, a script). When a run goes wrong you see what it changed and take back all of it, one
step, or one file. It runs on your machine only: no account, no network, nothing but the Python standard library.
| After your agent... | Claude Code checkpoints | rewindagents |
|---|---|---|
changed a file only through a shell command (rm, sed -i, a script) |
"isn't tracked and stays as it is" (docs) | rewind it like any other step |
| had a subagent edit files | "usually doesn't capture those edits" (docs) | recorded through the same hooks |
| was Codex, Cursor, Gemini CLI, Copilot CLI, Droid or Qwen Code | Claude Code only | one record and one rewind for all seven |
Quick start
The flight recorder for coding agents: see exactly what your agent did, and take back any part of it.
pipx install rewindagents && cd your-project && rewindagents init
init looks for the agents it supports (Claude Code, Codex, Cursor, Gemini CLI, Copilot CLI, Droid, Qwen
Code): their config directory in the project or your home directory, or their command on PATH. It prints
the plan, asks [y/N], and adds the hook to each one it found, one line per agent: installed,
already there, replaced or not found. It never adds a second copy and keeps every hook already in the
file.
--yes skips the question. --global writes each agent's user config instead, so every project is
recorded. Without --yes and without a terminal to ask on, it only prints the plan.
--agent claude sets up only that agent (repeat it for more). In a git repository the config files init
creates are listed in .git/info/exclude, this clone's own ignore list, because they name this machine's
Python and would not run on a teammate's; a file git already tracks is changed and named instead.
rewindagents init --undo takes it all out again and keeps what was recorded.
Then use your agent as usual and:
rewindagents summary # what it changed: each file, lines added and removed, which steps
rewindagents replay # what it did, one line per step
rewindagents diff 12 # what taking it back to step 12 would change
rewindagents rewind 12 --only src/db.py # take back just that file
rewindagents status says in plain words whether recording works right now: it runs each hook once in a
scratch folder and checks that it wrote a record.
After a bad run
Three commands, in the order you need them. summary prints the last two filled in for the session.
rewindagents summary # which files are different now, by how much, and which steps did it
rewindagents revert 7 # take back step 7 alone, keep every later step and hand edit
rewindagents rewind 0 # put every file back as it was before the session's first step
rewind and revert refuse, change nothing and exit 1 when they would overwrite a change made after the
agent's step (your own edit, for example); the message names the file and the command that shows what would
be lost. Every rewind is itself a step, so it can be undone, and it prints the command that undoes it.
The demo at the top is a real session: an agent's last two steps delete the tests and overwrite the config,
replay lists the fourteen steps, rewind 12 puts the files back.
brand/demo/build.py runs those fourteen agent steps through the hook in a temporary project, then the four
commands shown, and draws the frames from what they printed; tests/test_demo.py plays the same session again
and fails if any line differs.
What it cannot put back
Files under a directory git ignores as a whole (node_modules/, build/), symlinks, files over 20 MB,
changes outside the project, and the shell steps of a project with more than 20,000 files (status warns
about that one, and replay marks such a step). Details under Claude Code hook,
Codex and Cursor hooks and Replay, rewind, branch.
Claude Code's own checkpointing docs (read 2026-11-12) name
the gap this fills: "A file that only Bash commands changed isn't tracked and stays as it is." (its /rewind
does undo Bash changes to a file Claude had already edited), and, of subagents, "Claude Code usually doesn't
capture those edits in your session's checkpoints." rewindagents copies the project's files before every
shell command and scans them after, so a sed -i or an rm is one more step you can rewind, and Claude Code
runs the same hooks for a subagent's tool calls (hooks docs). A live
session in which a subagent made eight steps, three of them edits, recorded and checkpointed all of them
(ux-review/DOGFOOD.md). Every tool call goes into a tamper-evident, hash-chained log you can verify later.
Status: v0.0.9, pre-release. Built and tested today: the recorder and its CLI, hooks for seven coding
agents (Claude Code, Codex, Cursor, Gemini CLI, Copilot CLI, Droid, Qwen Code) that record every call and
checkpoint the files a step changes, summary, replay, rewind, revert and branch, fork and
compare, export (a session as one HTML page), sessions, bundle and import, gc, a local timeline UI,
and a package on PyPI with a rewindagents command. The Claude Code hook has run in
real sessions; the Codex and Cursor hooks are built from the vendors' hook documentation and tested with the
documented payloads, not yet in a live session. macOS and Linux; Windows is not supported yet (see Recorder).
Rewind to any step and let another agent take it from there: Fork a step, compare the runs.
Install
Python 3.10 or newer (declared in pyproject.toml; tested on 3.15, macOS; the full suite also passed there on
3.10, 3.11, 3.12, 3.13 and 3.14 on 2026-11-14). No dependencies beyond the
standard library. From PyPI:
pipx install rewindagents # or: pip install rewindagents
rewindagents --version
Or from a clone, pip install .. Without installing, PYTHONPATH=src python3 -m rewindagents runs the same
CLI from a clone.
uv tool install rewindagents works as well as pipx install rewindagents. Do not add the hook with uvx rewindagents install or pipx run rewindagents install: those run
from a cached environment the tool may delete, and the hook names that environment's Python. install and
init detect such a Python, write nothing, and print the two lasting commands above.
Claude Code hook
cd /path/to/your/project
rewindagents install # adds the hook to .claude/settings.json in this project
rewindagents install --settings ~/.claude/settings.json # or for every project
install keeps everything already in the settings file and does nothing if the hook is already there. The
hook command it writes names the Python that rewindagents was installed into by absolute path, so it runs
whether or not a virtualenv is active; from an uninstalled clone it carries the PYTHONPATH instead. For a
Windows Python the command has no such prefix: a bare forward-slash path, which Git Bash, PowerShell and
cmd.exe all run, or, when the path has a space, a quoted one in the form of the shell the agent's docs name
(src/rewindagents/agents.py quotes them); from a clone it runs src/rewindagents/__main__.py by path. That
form is produced and checked by the tests on Unix; it has not been run on Windows (see Recorder).
If that Python goes away later (the venv is deleted, Python is upgraded, the clone is moved), the agent still
runs the hook, the hook fails, and nothing is recorded. status checks for that:
rewindagents status # per agent config file: ok, STALE, FAILING, partial or no hook; then the log and the store
A hook is stale when its interpreter path or its PYTHONPATH directory no longer exists; status then exits
installandinit --yesreplace a stale rewindagents hook with the current one and leave every other hook in the file as it is.
Each hook that is in place is also run once, the way the agent runs it, in a new temporary folder, and must
write a record there: one that runs but records nothing (a broken install the stale check cannot see) is
FAILING, with the hook's own error message, and status exits 1. Your agent does not show a failing hook,
so this is the only place you find out. (Not on Windows yet.)
After the hooks come this project's log: how many records it holds, when the last one was written, and
whether the chain verifies; then the store: how much disk .rewindagents/ takes. A log that does not verify
makes status exit 1, as verify does. Over 20,000 project files it warns that shell commands are not
checkpointed there. status writes nothing in the project.
Once the hook is in, in each project Claude Code works in:
- every tool call gets a
prerecord (tool and input) and apostrecord (tool and response) in.rewindagents/log.jsonl, in one hash chain. Responses longer than 4,000 characters are cut, with the full length noted. So is any text in the input longer than 4,000 characters (aWrite's content, anEdit's new text): every key stays, and the file path and the command are kept whole. Rewind does not need that text; it restores from the copies below.bench/log_growth.pywrites one 10 MB file through the real hook: before this cut the log grew by 20,972,561 bytes, now by 9,135. - before
Write,Edit,MultiEditandNotebookEdit, the current bytes of the target file are copied to.rewindagents/objects/<sha256>and the hash goes into theprerecord. A file that does not exist yet is recorded as absent. Files over 20 MB are noted and not copied. .rewindagents/gets its own.gitignore, so the log and the copies stay out of your commits.- one log per project, wherever the agent is: after the agent runs
cd src, its steps still go into the project's.rewindagents/, the nearest one at or above its working directory (not above the repository root). Before anything is recorded, Claude Code'sCLAUDE_PROJECT_DIR(the directory the session started in) decides; without it, the agent's working directory does.
The hook never blocks or changes a call. It prints nothing and always exits 0, even if its input is
broken or it cannot write; any problem goes to stderr only. tests/test_hook_hardening.py runs the real
hook process for all seven agents on empty, cut-off and non-object input, fields of the wrong type, bytes that
are not UTF-8, a 10 MB tool response, a cwd that does not exist and a post with no pre: each exits 0, prints
only that agent's reply, and leaves the log verifying. What it can read it records (bad text as U+FFFD, the
response cut to its first 4,000 characters); for a cwd that does not exist it records nothing and creates
nothing.
Each record and its newline go to the log in one write. If a write is still cut off (a full disk, a killed
process), the next record starts on a fresh line chained to the last whole record and the cut-off line stays
where it is, so recording goes on. verify and status then name that line ("torn write at the end of the
log", or "not a valid record" once records follow it) and exit 1, because the call it was recording is lost.
rewind, diff, gc and import still work from such a log, print a note about the torn write and
exit 1; bundle refuses it. tests/test_torn_write.py drives this through the real hook.
Around every Bash call (for example sed -i, rm, mv, a code generator), the hook saves the
project's files before the command, scans again after it, and checkpoints, in the post record, only the
files that were changed, deleted or created. Details and limits:
- "The project's files" means, in a git repo, what
git ls-files --cached --others --exclude-standardlists (tracked and untracked files, except untracked ones under__pycache__,node_modules,.venvorvenv, so a Python run does not show up as.pycchanges), plus the files git ignores one by one, such as.envor*.log, sorm .envcan be rewound; a directory git ignores as a whole (node_modules/,build/) is not scanned.bench/takeback(scenario S06) measures this. Outside git, every file under the project directory except.git,.rewindagents,node_modules,.venv,venvand__pycache__. - Only the project directory is scanned. A command that changes files elsewhere is recorded, not saved.
- Symlinks are not saved. Files over 20 MB are noted and not copied. Permission bits are saved with each copy, so a deleted script comes back executable (takeback-bench S11).
- Copies are stored by SHA-256, so an unchanged file is stored once. A stat cache
(
.rewindagents/index.json) means only files whose size, modification time or mode changed are read again. - A project with more than 20,000 files is not scanned; the call is still recorded,
replaymarks the step[NOT checkpointed: ...],statuswarns, andrewindreports it. - A command that fails (exits non-zero) is checkpointed like any other: Claude Code sends a failed call to
the
PostToolUseFailurehook event, and the hook is installed there too. An install from before 0.0.8 has no hook on that event;statusshows it aspartialandrewindagents init --yescompletes it. - A Bash call with
run_in_background: true: Claude Code's hooks reference documents no hook event for a background shell finishing, so the after-scan may run while the command is still going. Files it changes after that are not in the step.replaymarks such a step[background: scan may be early], andrewindanddiffprint a note and exit 1 when one lies after the target step.
To take the hook out again, from every agent init set up: rewindagents init --undo (add --global for the
user config). For one agent:
rewindagents uninstall # removes the hook from .claude/settings.json in this project
rewindagents uninstall --agent cursor --settings ~/.cursor/hooks.json # same flags as install
uninstall removes only the entries whose command is exactly the one install writes from the same Python,
so every other hook and setting stays. If the file holds none, it is not rewritten and says so. It never
touches .rewindagents/: sessions already recorded can still be replayed and rewound.
Overhead
Measured by bench/hook_overhead.py on macOS 27.0.1, Apple M6, 12 CPUs, Python 3.15.0, on 2026-11-12 (commit b11b369, load average 22.2 at the start). Time the hook adds to one tool call: both hook processes (before and after the call), median of 15 calls with the 90th percentile in brackets. Each hook event is a new Python process; starting one and importing the package alone takes 108 ms (median), and every call starts two. Raw numbers: bench/results.json.
| Project files | Read | Edit | Bash | First Bash (empty store) |
|---|---|---|---|---|
| 100 | 228 ms (273 ms) | 210 ms (281 ms) | 281 ms (438 ms) | 410 ms |
| 1,000 | 224 ms (241 ms) | 220 ms (277 ms) | 351 ms (495 ms) | 605 ms |
| 10,000 | 226 ms (292 ms) | 223 ms (351 ms) | 1,003 ms (1,180 ms) | 4,554 ms |
Other machines, disks and projects will differ; run python3 bench/hook_overhead.py to measure yours.
Codex and Cursor hooks
rewindagents install --agent codex # adds the hook to .codex/hooks.json in this project
rewindagents install --agent cursor # adds the hook to .cursor/hooks.json in this project
rewindagents install --agent cursor --settings ~/.cursor/hooks.json # or for every project
Same recorder, same log, same replay, rewind, branch, export and sessions. What differs is how each
agent calls the hook, and src/rewindagents/agents.py quotes the vendor documentation (read 2026-11-11) it was
built from:
- Codex (
.codex/hooks.json, the same file shape as Claude Code's settings) sendsPreToolUseandPostToolUsewithsession_id,cwd,tool_name,tool_use_id,tool_inputandtool_response; shell commands arrive asBashand file edits asapply_patch. Codex asks you to trust a new hook before it runs (/hooksinside Codex) and remembers the trust by the hook's hash, so a hook command that changes needs trusting again. Project hooks load only when the project's.codex/folder is trusted. - Cursor (
.cursor/hooks.json) sendspreToolUseandpostToolUsewithconversation_id(used as the session),cwd,tool_name,tool_input,tool_use_idand, after the call,tool_output; its tools areShell,Read,Write,Grep,Delete,TaskandMCP:<name>. Cursor'spreToolUseis a permission hook that treats an empty or invalid answer as a failure, so for Cursor the hook prints{"permission": "allow"}before a call and{}after one. "allow" is the one answer that changes nothing; a deny from any other hook still wins. - The input of Codex's
apply_patchand Cursor'sWriteis not documented, so the hook never reads a file path out of a Codex or Cursor payload. Instead, around every Codex or Cursor call except the tools the docs name that cannot change files (Cursor'sReadandGrep, Codex'supdate_plan), the project is saved before the call and scanned after it, exactly as around aBashcommand, and only the files the call changed, created or deleted are checkpointed. The cost is a stat of every project file per call; unchanged files are not read again. The same 20 MB and 20,000-file limits apply. - Verified so far: the hook driven by the payloads in the vendors' documentation, in
tests/test_agents.pyand through the installed binary intests/test_installed.py. Not yet in a live Codex or Cursor session. If a real session sends something else, open an issue with the payload (replay --step Nprints what was recorded).
Gemini CLI, Copilot CLI, Droid and Qwen Code hooks
rewindagents install --agent gemini # adds the hook to .gemini/settings.json in this project
rewindagents install --agent copilot # adds the hook to .github/hooks/rewindagents.json in this repository
rewindagents install --agent droid # adds the hook to .factory/settings.json (or .factory/hooks.json if it exists)
rewindagents install --agent qwen # adds the hook to .qwen/settings.json in this project
rewindagents uninstall --agent qwen # same flags as install, for every agent
These are built from the vendors' hook documentation (read 2026-11-12, quoted with URLs in
src/rewindagents/agents.py) and tested with the documented payloads, not yet in a live session of any of
them. As for Codex and Cursor, the hook never reads a file path out of these payloads: the project is saved
before every call and scanned after it, except around the tools each agent's docs name as read-only, which
are recorded but not scanned.
- Gemini CLI (
.gemini/settings.json) sendsBeforeToolandAfterToolwithsession_id,cwd,tool_name,tool_inputand, after the call,tool_response. Shell commands arrive asrun_shell_command, edits aswrite_fileandreplace. Gemini reads the hook's stdout as JSON, so the hook prints{}(no decision, which changes nothing). Not scanned:read_file,read_many_files,list_directory,glob,grep_search,search_file_content,google_web_search,web_fetch. - GitHub Copilot CLI (
.github/hooks/rewindagents.json): installed under the PascalCase eventsPreToolUse,PostToolUseandPostToolUseFailure, which select the payload withhook_event_name,session_id,cwd,tool_name,tool_inputandtool_result(orerrorfor a failed call). Tools:bash,create,edit. The hook prints nothing. Copilot'spreToolUseis fail-closed: a non-zero exit denies the call. So the command it writes ends in|| true(for a Windows Python: under Copilot'spowershellkey, ending in; exit 0), and even a missing Python exits 0. In Copilot's cloud agent the hook file is read from the default branch, and this machine's Python is not there, so nothing is recorded and nothing is blocked. Not scanned:view,grep,glob,web_fetch. - Factory Droid sends
PreToolUseandPostToolUsewithsession_id,cwd,tool_name,tool_inputandtool_response. Tools:Execute,Create,Edit,ApplyPatch. Droid reads thehookskey of.factory/settings.jsononly when.factory/hooks.jsonis absent, so the hook goes into.factory/hooks.jsonwhen that file exists and into.factory/settings.jsonotherwise. A newhooks.jsonwould hide hooks you keep insettings.json. The hook prints nothing. Not scanned:Read,LS,Glob,Grep,FetchUrl,WebSearch. - Qwen Code (
.qwen/settings.json) sendsPreToolUse,PostToolUse(a call that succeeded) andPostToolUseFailure(one that failed), withsession_id,cwd,tool_name,tool_use_id,tool_inputandtool_responseorerror. A failed shell command can still have changed files, so the hook is installed onPostToolUseFailuretoo and closes the scan there. The hook prints nothing. Not scanned:read_file,list_directory,glob,grep_search. - Gemini CLI, Copilot CLI and Droid send no call id, so a call's before and after events are paired by session and input. Two identical calls running at the same moment in one session would share a scan.
- Not supported yet, and why: Windsurf's hooks page now leads to Devin's, and Devin's payload documents no
working directory. Devin also runs hooks from
.claude/settings.jsonby default, so a Claude Code install fires there as the Claude Code hook, and it never blocks. Kiro documents the payload before a call but not after one. Cline, OpenCode and Amp hooks are JavaScript/TypeScript plugins, not commands. Roo Code, Zed, Warp and Replit document no tool hooks.
Timeline UI
rewindagents ui # opens the timeline in your browser; Ctrl+C stops it
rewindagents ui --session abc --no-open --port 8765
A local page over the log. Sessions on the left. In the middle, the session as a timeline: each step's
number, tool, agent, file or command, time, the files it changed with +/- line counts, its checkpoints,
rewind steps, and the steps a later rewind undid. Click a step, or move with j / k, to see each file's
diff and the step's input and result (d hides or shows the diffs).
- Preview rewind to here shows the files
rewind Nwould put back or delete, each as a diff from now, using the same plan asdiff N. It changes nothing. - Rewind to here (or
r) asks first, then runs the same rewind asrewindagents rewind N: the hash chain is checked, the rewind is recorded as a new step, and an Undo button rewinds it back. Rewind just this file does the same asrewind N --only PATH. - It listens on 127.0.0.1 only, on a free port unless you pass
--port. The link it prints carries a random token made for this run; every request without it gets a 403, and so does any request whose Host header is not 127.0.0.1 or localhost on that port. Rewinds are POST only and must come from the page itself. No fonts, scripts or images are fetched from anywhere, so it works offline. - Diffs are cut as
exportcuts them (400 lines per file, files over 256 KB described). An input or result longer than 20,000 characters is cut on the page, with the count left out.
Replay, rewind, branch
Run these from the project directory or any directory under it: like git, they use the nearest
.rewindagents/ at or above where you are (not above the repository root, never your home directory's from
below it). They work on the latest session unless you pass --session ID; the start of an id is enough when
only one session begins with it, and an id that matches none is an error that lists the sessions there are.
rewindagents replay # one line per step: number, tool, file or command
rewindagents replay --step 12 # step 12 in full: input, checkpoints, result
rewindagents rewind 12 --dry-run # what would change
rewindagents diff 12 # the same files, as a unified diff: now -> step 12
rewindagents diff 12 src/db.py # only that file (a directory means every file under it)
rewindagents rewind 12 # files back to how they were right after step 12
rewindagents rewind 12 --only src/db.py --only tests/ # put back only these
rewindagents revert 12 --dry-run # what taking back step 12 alone would change
rewindagents revert 12 # take back step 12 alone, keep every later step and hand edit
rewindagents branch 12 --name try2 # keep the current files, then rewind to step 12
-
replay --step N --diffnames each file step N changed, created or deleted, then diffs the file right before the step against the file right after it (its next checkpoint in the session, else the file now), the same before and after the export page shows.git apply -Rof that diff undoes exactly that step. -
replayreplaces secrets the wayexportdoes, in the step list, in--step Nand in--step N --diff, and says on stderr how many it replaced, because terminal output gets pasted into issues and chats.--no-redactshows them as recorded (use it beforegit apply -Rof a diff that touches a secret: a diff with placeholders in it does not apply). -
diff N [PATH ...]reads the same planrewind Nacts on, so it names exactly the filesrewind N --dry-runlists (a test checks this). Thea/side is the file now, theb/side is the file after the rewind, sogit applyof the diff does what the rewind would do. Files the rewind would delete diff to/dev/null; binary files are named, not printed; files it cannot put back are listed on stderr. It writes nothing. Exit code 1 when something could not be shown, as forrewind. -
rewind N --only PATHputs back only those files (or every file under a directory) and leaves the agent's other changes as they are. Same hash-chain and stored-copy checks, and it is recorded as a step like any rewind, so it can be undone. A path no step after N changed is reported asskip; if none of the paths was changed, nothing is written and the exit code is 1. -
revert Ktakes back step K alone and keeps everything after it: later agent steps, later sessions and hand edits, in other files and in the same file. For each file step K changed it does a three-way merge (base: the file right after step K, which the hook keeps a copy of; theirs: the file right before step K; ours: the file now), so step K's lines go back and the other lines stay. A file step K created is removed only if it is unchanged since; a file it deleted comes back only if nothing created it again. When a later change touched the same lines as step K (or lines right next to them, asgit merge-filecounts it; in a file where the same line repeats many times the two can pair lines differently, measured bybench/merge_vs_git.py), or changed a file step K created or deleted, that is a conflict:revertchanges nothing, names each file, says how to see step K's change and how to put the file back by hand, and exits 1.--dry-runprints the plan, conflicts included. A revert is recorded as a step like a rewind, current bytes first, sorewind <step before it>undoes it. It has the same limits asrewind(files outside the project, over 20 MB or not checkpointed are reported, exit 1). Steps recorded by an older version kept only the hash of the file after the step, so for themrevertneeds those bytes from somewhere else: the file now, or a later step's copy of it; otherwise that file is reported, not guessed. -
rewind Nputs back every file that a step after N changed withWrite,Edit,MultiEdit,NotebookEditor aBashcommand, and deletes the files those steps created.rewind 0undoes the whole session. -
A rewind is undoable. It first saves the current bytes of every file it will change and records itself as a new step; the command prints
undo it with: rewindagents rewind <step> --session <id>(from an uninstalled clone it sayspython3 -m rewindagentsinstead). -
A rewind does not silently overwrite later work. The hook records each file's SHA-256 right after every step, so a rewind can tell when a file it would put back or delete has changed since the steps it takes back: by a later session (named with its step), or outside any recorded step (by hand, or by a tool with no hook).
diff Nandrewind N --dry-runlist each such file with a WARNING and exit 1.rewind Nandbranch Nrefuse and change nothing;--forcerewinds anyway, and because the rewind saves the current bytes first, the undo command it prints brings that work back. The timeline UI refuses the same rewind with the same message.fork Nchanges nothing in the project, so it only warns that the run starts without those changes. A file that is absent now loses nothing and is not listed. Sessions recorded by an older version hold no after-hashes: for those, a later session's change is still caught, a hand edit is not. -
branch N --name Xdoes the same and, in a git repo, also commits the whole current working tree to the branchrewindagents/X. It does this through a temporary index, so yourHEAD, index and current branch stay as they were. Outside git, the current files are kept in the log only. -
Before writing anything, rewind checks the log's hash chain and the SHA-256 of every stored copy. If the chain is broken it changes nothing. If a stored copy no longer matches, that file is reported and left as it is.
-
It only touches files inside the project directory. Files outside it are reported and left alone.
-
Limits: a step whose before/after scan did not finish (a
Bash,Shellorapply_patchcall in a project of more than 20,000 files, or one whose post event never arrived) is counted and reported, and its changes are not put back. Directories created by later steps stay (empty). Files over 20 MB were never copied, so they are reported and not restored. If anything could not be restored, the exit code is 1.
Exit codes, the same in every command: 0 when it did what you asked; 1 when it ran but something was not
done or does not check out (a file a rewind could not put back or refused to overwrite, a log that does not
verify); 2 when it could not run as asked: an option it cannot parse or combine, a step number the session
does not have, or no log yet. A step number the session does not have is a bad argument in replay --step,
rewind, diff, branch and fork alike: exit 2, and the message gives the numbers the session has. A name that
matches nothing (an unknown or ambiguous --session, a run compare cannot find), a fork --name that is
not valid or already taken, or a fork --dir inside the project exits 1, and the message says why. rewindagents --help says this too.
Fork a step, compare the runs
Rewind to any step, fork it, let another agent take it from there, compare. A recorded step is a starting point you can hand to another agent, another model, another prompt or a person, and the runs that follow can be compared on what they actually did to the files and on your own check.
rewindagents replay # pick the step to start from, say 12
rewindagents fork 12 --name try2 # ../<project>-try2 with step 12's files
cd ../your-project-try2 # run any agent with a hook here, or edit by hand
cd - && rewindagents compare --check "python3 -m pytest -q"
rewindagents compare --diff your-project try2 # how two runs differ, as a git diff
sh ux-review/try-runs.sh does the whole loop in a temporary project with no agent needed: it records a
session through the real hook, forks step 2, makes a second attempt by hand and compares the two.
rewindagents fork 12 --name try2 makes a new directory next to the project (<project>-try2; --dir
picks another place outside it) holding the project's files as rewind 12 would leave them: the project as
it is now, with every change that session made after step 12 taken back, untracked files included. In a git
repository it is a git worktree on the branch rewindagents/run/try2, so your HEAD, index and files stay
as they were; elsewhere it is a plain directory. The run gets its own .rewindagents/, whose first record names
the session, the step, the source log's head hash at that moment, and every starting file with its SHA-256
(copies kept in the run's store). Run any agent there, or edit by hand: with a hook in place (the project's
agent config comes along when git does not ignore it, or a --global hook), its steps go into the run's own
log, and replay, rewind and diff work in the run as in any project. fork says whether a hook reaches
the run.
Back in the project, rewindagents compare lines up the project and every run forked from the same step:
per run, the agents and their number of tool calls since the start, the files changed, created or deleted
and the lines added and removed; per file, which runs ended with the same bytes (the same letter).
rewindagents compare --check "python3 -m pytest -q" runs your command in each run and reports pass or the
exit code, with the last lines of a failing one. rewindagents compare --diff proj try2 prints how two runs
differ as a git diff (git apply in the first turns its files into the second's). --json prints it all
as data.
forkrefuses a step it cannot rebuild exactly (a stored copy missing, a command whose scan did not finish, a log that does not verify) and leaves nothing behind when it fails half-way.- Git-ignored files (
.env,node_modules) are not copied, as in any fresh worktree; caches and environments (__pycache__,.venv,node_modules) are left out of the comparison even when git does not ignore them. A project of more than 20,000 files is not forked. comparewrites nothing; the command--checkruns may write in the run it runs in. Runs from different steps are not mixed. Tested intests/test_runs.py, through the real hook.
Export a replay
rewindagents export # writes .rewindagents/replay-<session>.html
rewindagents export --session abc --out replay.html # a given session, to a given file
rewindagents export --no-contents # steps, tools and paths only: no inputs, results or diffs
rewindagents export --no-redact # keep secrets as recorded (they are replaced by default)
One HTML file with the whole session: every step with its tool, input and result, and for every file a step checkpointed, the change that step made as a unified diff (the file before the step against the file after it: its next checkpoint in the session, or the file as it is now). Open it in a browser, attach it to a bug report or a code review, or keep it with the session.
- Inline CSS only. No scripts, and nothing is fetched from anywhere, so the page is safe to pass on.
- Paths inside the project are shown relative to it; where the project lives on disk is not in the page.
- A file over 256 KB on either side is described, not diffed. A diff longer than 400 lines is cut, with the count of the lines left out. Binary files show their size before and after.
- Inputs and results are the recorded ones, so a result that was cut at 4,000 characters stays cut. A cut
value shows its first characters and then one line,
... first 4,000 of N characters kept in the log, here, inrewindagents uiand inreplay --step. --no-contentsdrops inputs, results and diffs (aWriteinput is the file's content). Each step keeps the one-line summaryreplayprints, so aBashcommand line is still on the page.- If the log's hash chain does not verify, the page is still written, with a notice naming the first bad record, and the command exits 1.
- Secrets are replaced with
[redacted <kind>]in every input, result, diff and step line, and the page says how many: AWS access key ids, GitHub, Polar, OpenAI and Anthropic tokens, webhook secrets (whsec_), private key blocks, the credential in anAuthorizationheader, the value of anything named like a secret (..._TOKEN,PASSWORD,API_KEY,client_secret), and every value in a.envor.env.*file. It is pattern matching: a secret of another shape stays, so read the page before you pass it on. A file whose change was only inside a replaced value says so.--no-redactturns this off. - The log keeps only the first 4,000 characters of a long input or result. When that cut ends inside a
secret (a key, a private key block, a
.envvalue), the part before the cut is replaced too, in the page and in a bundle.
Find a session
rewindagents sessions # every session in the log: id, first and last time, steps, files touched
rewindagents sessions --grep config.py # only sessions with a step that mentions it, and those steps
One line per session, in the order the sessions first wrote to the log, with the session id, the local
time of its first and last record, the number of steps (the numbers replay and rewind use, with how
many of them are rewinds or branches) and the files it touched; a second line names the first 5 files and
counts the rest. The session that wrote the
last record, the one replay and rewind use by default, is marked (latest).
- A file is touched when a step checkpointed it: changed, created or deleted by
Write,Edit,MultiEdit,NotebookEdit, aBashcommand or a rewind. A file that was only read is not touched. --grep TEXTkeeps the sessions with a step whosereplayline (the command, the file, or the input) or checkpointed path contains TEXT, in any case, and lists those steps under the session with their step numbers, sorewindagents rewind <step> --session <id>can follow. Exit code 1 if no session matches.- Paths are shown relative to the project.
Move a session to another machine
rewindagents bundle --out s1.bundle # the latest session, and the file copies it names, in one file
rewindagents bundle --session abc --out abc.bundle # a given session
rewindagents bundle --no-redact --out s1.bundle # carry secrets as recorded (they are replaced by default)
rewindagents import s1.bundle # in another clone: check the file, then add the session to its log
Then replay, rewind and branch work on that session in the other clone, with --session <id>.
- One JSON file: the session's log records as the log holds them (secrets aside: next line), each with its hash, and every stored file copy they name. Nothing goes over a network; carry the file however you like.
- By default, secrets are replaced in the records and the stored copies, as
exportreplaces them. A record or copy that changed carries the hash of its new contents, soimportchecks it like any other, and rewinding that file in the other clone writes the placeholder, not the secret.--no-redactcarries the session exactly as recorded. bundlerefuses a log whose chain does not verify, and a session whose stored copies are missing or altered. That includes a log whose only damage is a torn write: the log it moves to would not show the torn line, so the call that was lost would leave no trace there.importwrites nothing until everything checks out: the file's own SHA-256, every record's hash, that every record belongs to the session and is in log order, every stored copy against its SHA-256, that no copy a record names is missing, that this project's log verifies, and that it does not already hold the session. The one exception: a log here whose only damage is a torn write still takes the session in. The torn line stays where it is, the new records chain on from the last whole record, andimportprints a note and exits 1.- The records join this project's chain in order, with their original times; they get new sequence numbers and hashes here.
- File paths under the old project move under this one, so a rewind puts the files back in this clone. Commands and results keep their text as recorded.
Attach a replay to a pull request
rewindagents bundle --out .rewindagents-pr.bundle # the session behind this change, secrets replaced
git add .rewindagents-pr.bundle
# .github/workflows/replay.yml
on: pull_request
permissions:
contents: read
pull-requests: write # for the one comment; nothing else writes
jobs:
replay:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: Johnbjoseph-cybersec/rewindagents/attach@<commit sha>
with:
bundle: .rewindagents-pr.bundle
The action in attach/ imports the bundle, checks the log's hash chain (against head: too, if you pin
one), writes the session's export page and uploads it as a workflow artifact, then posts one comment on the
pull request with the chain result, the number of secrets replaced and the download link. A later push
updates that comment instead of adding another.
- The
.rewindagents/store is git-ignored, so the checkout holds no log of its own; commit a bundle. - Secrets are always replaced in the page; the action has no input to turn that off.
- It installs
rewindagentsfrom the same commit as the action, so pinning the action's SHA pins the tool. The one action it calls (actions/upload-artifact) is pinned to a commit SHA. - The token is handed to the comment step only. A pull request from a fork gets a read-only token: the page is still uploaded and the comment step logs a warning instead of failing.
- If the log does not verify, the page is uploaded with its notice, and then the job fails.
attach/attach.pyis not part of the package; the CLI still makes no network connections. Tested intests/test_attach.pyagainst a fake GitHub API on 127.0.0.1. It has not run on GitHub yet.
Clean up stored copies
rewindagents gc --dry-run # what would be deleted, and how many bytes
rewindagents gc # delete it
rewindagents gc --drop-pending-older-than 7 # first drop scans whose command never finished
Before every Bash call the hook saves a copy of every project file, and afterwards the log names only the
copies of files the command changed, so .rewindagents/objects/ grows. gc deletes every stored copy that no
log record (in any session) and no pending scan (a command whose after-scan has not run) names, and prints how
many it deleted and the bytes those files took on disk.
- Every step of every session in the log can still be rewound afterwards; the copies a rewind needs are the ones the log names.
- It refuses to run when the log does not verify, and it never writes to the log. The exception is a log whose only damage is a torn write (a full disk is the likeliest cause, and that is when you need the space): it runs, also keeps every copy a torn line names, prints a note and exits 1.
- While it runs it holds the store lock, so a hook call waits for it to finish, and it waits (up to 30 s) for a hook, rewind or import that has saved a copy but not yet written the record naming it.
- It lists every pending scan with its age and the command it belongs to. A scan whose after-scan never ran
(the agent was killed, a crash) stays pending and keeps its copies;
--drop-pending-older-than DAYSremoves the scans older than DAYS first, so their copies are collected too. That command's step then rewinds as unscanned, as it already did while the scan was pending. Scans younger than 1 day are never dropped.
Recorder
Recorder.record(session, tool, args, result)appends one JSON line per tool call.- Each record holds the SHA-256 of the record before it, so editing, deleting or reordering any
record makes
verifyfail and name the first bad record. - Several processes can write to the same log at once; appends are locked, so the chain stays single.
- Plain JSONL. No server, no database, no dependencies beyond the Python standard library.
Needs a Unix for now. The write lock has a Windows path (
msvcrt) and the hook command has a Windows form, but the test suite has not passed on Windows yet, so Windows is not supported.
Use it
echo '{"tool": "Bash", "args": {"command": "ls"}}' | rewindagents record --session s1
rewindagents verify # OK: 1 records, chain intact
rewindagents show # list recorded calls
rewindagents head # current head hash
The log defaults to .rewindagents/log.jsonl; change it with --log PATH.
From Python:
from rewindagents import Recorder, verify
Recorder("log.jsonl").record("s1", "Bash", {"command": "ls"}, {"exit": 0})
print(verify("log.jsonl")) # (True, 1, 'chain intact')
What the chain does not catch
A hash chain proves the records are unchanged relative to each other. It cannot, on its own, tell
that records were cut off the end, or that someone rewrote the whole file and re-hashed every line.
To catch both, copy the head hash somewhere the agent cannot write (rewindagents head) and check
against it:
rewindagents verify --head <pinned-hash>
Roadmap
- Run the Codex and Cursor hooks in live sessions and keep the real payloads as test fixtures
- Fork and compare, next: saved starting points (a step plus the check that judges it) and re-running one across
agents on your machine. See
ux-review/ROADMAP.md. - A paid Cloud tier for teams, opt-in, that the local tool never needs (a shared page per comparison, saved
starting points run in parallel cloud sandboxes, a team's comparison history, scheduled re-runs when a model or
prompt changes; retention, SSO, seats): planned, not built, not priced. The waitlist is a GitHub issue on this
repository with the label
waitlist; say what you would pay for.
Payments code (not live)
billing/polar.py is the checkout and webhook code for that Cloud tier, written against Polar's API documentation
(the pages and the date are cited at the top of the file). It is not part of the rewindagents package and is never
installed with it; the CLI makes no outbound network connections (rewindagents ui listens on 127.0.0.1 only). No product exists yet, so nothing can be bought.
python3 billing/polar.py link --product <id> # a reusable checkout link, printed
python3 billing/polar.py checkout --product <id> # a single-use checkout session, printed
python3 billing/polar.py verify --headers h.json --body b.json # check a saved webhook delivery
- The sandbox (
sandbox-api.polar.sh) unless--productionis given. The token is read fromPOLAR_ACCESS_TOKENand the webhook secret fromPOLAR_WEBHOOK_SECRET; neither is ever an argument, and error messages replace the token with[token]. link --write-configalso setscheckout_urlinbrand/site/config.json, which turns the pricing page's waitlist button into a buy button. The return address after paying comes fromsite_urlin the same file.verifychecks the Standard Webhooks signature (HMAC-SHA256 overid.timestamp.body) with both keys Polar documents (secrets made before 8 September 2026 use the whole secret string as the key), and refuses a timestamp more than 5 minutes from now. The 5 minutes is our choice; Polar does not give a number.- Tested in
tests/test_polar.pywith a fake network; it has not yet talked to Polar's sandbox.
Site
brand/site/ holds the landing page, the pricing page and the getting-started docs, published with GitHub Pages
by .github/workflows/pages.yml. The pages are built by brand/site/build.py from this README, the package and
the clip's session, and tests/test_site.py fails if a committed page differs from a fresh build. The site's
address lives in one place, brand/site/config.json.
brand/vsl/ holds the scripts and captions of the launch videos, rendered by brand/vsl/build.py from
brand/vsl/beats.json; every command and terminal line in them is one of this README's or one the clip's session
printed, and tests/test_vsl.py checks that. The rendered videos are brand/vsl-90s.mp4, brand/vsl-30s.mp4 and
brand/vsl-15s-vertical.mp4; the site plays brand/vsl/vsl-90s-web.mp4, a copy of the 90-second one.
Tests
python3 -m unittest discover -s tests -v
That runs against the source tree and skips the tests of the installed command. .fire-test-cmd holds the
full command: it builds .venv, installs the package into it and runs every test, including the ones that
drive the installed rewindagents binary and the hook command it writes into a settings file.
Licence
Apache-2.0. The hash-chain design is adapted from tinyguard (Apache-2.0).
Metadata
Release files for rewindagents 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rewindagents-0.0.9.tar.gz | 154.3 kB | With provenance | Details for rewindagents-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rewindagents-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for rewindagents-0.0.9-py3-none-any.whl |
Total release size: 288.1 kB
Release files / rewindagents-0.0.9.tar.gz
| Download URL | rewindagents-0.0.9.tar.gz |
|---|---|
| Size | 154.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5910d917deea4aea7ee7f5550e8af606d0894473b7a11d53232aab5602323df
|
|
BLAKE2b-256 checksum How to use checksums |
e840f8f498a7c9695b034357fbd359d1d505b42543b7674767ecda3865b1e321
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / rewindagents-0.0.9-py3-none-any.whl
| Download URL | rewindagents-0.0.9-py3-none-any.whl |
|---|---|
| Size | 133.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a855ad988ccc49145c6efa6116c556eecab24aaa6daa0459243e49064051d24
|
|
BLAKE2b-256 checksum How to use checksums |
70591e66d28386864ad2f3f58a3d77b132595e6d141c73a8c1aa7c7da8225996
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for rewindagents 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for rewindagents-0.0.9.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.