omp packages

ai-undo0.1.2

Undo what your AI coding agent did to your files: snapshots in a hidden git repo, separate from your own history. Works with Claude Code, Codex, Gemini CLI, OpenCode and Pi.

kerimqzt Published 1 day ago MIT ~483 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

ai-undo

Undo what your AI coding agent did to your files.

Coding agents edit, create and delete files, and run shell commands that do the same. When a turn goes wrong, git checkout only helps for what you had committed. ai-undo takes a snapshot of the whole working tree (uncommitted and untracked files included, .gitignore respected) before every prompt, so any agent turn can be reverted, and the revert itself can be reverted.

Snapshots live in a hidden git repository under ~/.ai-undo, completely separate from your own: your commits, branches, index and stash are never touched.

npx ai-undo install claude     # or: codex, gemini. Once; works in every project
# ... the agent breaks something ...
npx ai-undo undo               # back to the state before the agent's last turn
npx ai-undo redo               # changed your mind

Setup per agent

Agent Setup What it hooks
Claude Code (tested) npx ai-undo install claude, or the plugin: /plugin marketplace add kerimqzt/ai-undo then /plugin install ai-undo@ai-undo UserPromptSubmit (+ PreToolUse with --per-tool)
Codex CLI (tested) npx ai-undo install codex, then run /hooks once in Codex to trust the new hook UserPromptSubmit (+ PreToolUse on Bash and apply_patch)
Gemini CLI (untested) npx ai-undo install gemini. Written from the hooks docs; not tested end to end, as Google now points individual users to Antigravity BeforeAgent (+ BeforeTool on write_file, replace, run_shell_command)
Pi (untested) pi install npm:ai-undo before_agent_start (+ tool_call with AI_UNDO_PER_TOOL=1)
OpenCode (experimental) add "opencode-ai-undo" to "plugins" (2.x) or "plugin" (1.x) in opencode.json prompt hook on 2.x, file-changing tools on 1.x
anything else run npx -y ai-undo snap --quiet from its hook, or before you send a prompt

For the fastest hooks install it once globally, npm i -g ai-undo, then run ai-undo install <agent>: the hook calls ai-undo directly instead of npx (about 2 seconds less per prompt).

install writes to the agent's user-level config by default (~/.claude/settings.json, ~/.codex/hooks.json, ~/.gemini/settings.json). Use --project for this project only, and --per-tool to also snapshot before every file-changing tool call. uninstall <agent> removes only what install added.

Commands

Command What it does
ai-undo undo [<n>] [--dry-run] [--yes] [-- <paths>...] Without <n>: back to the snapshot right before the last change. With <n>: back to snapshot #n from list. With paths: restore only those files or folders.
ai-undo redo Reverts the last undo (every undo first saves a backup snapshot).
ai-undo list [-n <count>] Snapshots, newest first.
ai-undo diff [<n>] [--patch] What changed since snapshot #n.
ai-undo snap [--agent <name>] [--label <text>] Take a snapshot now.
ai-undo install <agent> / uninstall <agent> See above.
ai-undo status / ai-undo clear Where snapshots are stored; delete them for this project.

undo shows the files it will restore, delete or revert and asks before changing anything. In scripts, pass --yes. In Claude Code the plugin also adds a /ai-undo:undo command.

Claude Code already has /rewind for its own file edits. ai-undo also covers files changed by shell commands, survives a closed session, and works the same way across agents.

How it works

  • One shadow repository per project at ~/.ai-undo/repos/<hash> (AI_UNDO_HOME to move it). The project is your git top-level, or the current directory outside git.
  • A snapshot is git add --all into the shadow index plus a commit on refs/ai-undo/snapshots. Unchanged files cost nothing; identical snapshots are skipped.
  • Ignored files (your .gitignore, .git/info/exclude, plus node_modules/, .venv/, __pycache__/) are never stored, and never deleted by an undo.
  • An undo restores the files that differ from the target snapshot, removes files that did not exist then, and records a backup snapshot first.
  • In hook mode (--quiet) it prints nothing and always exits 0, so it can never block or confuse your agent, and git calls are time-limited.

Requirements and limits

  • Node.js 18 or later and git on PATH. Windows, macOS and Linux.
  • The first snapshot of a large project takes a few seconds; later ones take a fraction of a second.
  • Large files that are not ignored are stored too. Add them to .gitignore if they should not be.

License

MIT