Skip to main content
Glama
README.md
<div align="center">

<p>
  <a href="README.md"><strong>English</strong></a> · <a href="README.ru.md">Русский</a>
</p>

<img src="assets/hero-banner.svg" alt="agent-undo hero banner" width="900" />

<br/><br/>

![Tests](https://img.shields.io/badge/tests-node%3Atest%20passing-248A3D?style=flat-square)
![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20npm%20packages-0071E3?style=flat-square)
![Node.js >= 22.5](https://img.shields.io/badge/node-%3E%3D22.5.0-6E6E73?style=flat-square)
![License MIT](https://img.shields.io/badge/license-MIT-6E6E73?style=flat-square)

**Shadow Git snapshot and checkpoint time-machine for AI coding agents without touching your real `.git` history.**

Works with Claude Code, Cursor, Windsurf, Codex CLI, and Antigravity.

</div>

When an autonomous coding agent rewrites ten files on top of your uncommitted changes and breaks the build, `git checkout -- .` wipes your own unsaved work too, while `git reset --hard` deletes new untracked files you wanted to keep.

`agent-undo` keeps an isolated bare Git object store in `~/.agent-undo/<repo-hash>.git` outside the workspace. Every checkpoint captures tracked changes and new untracked files (honoring `.gitignore`) without adding a single commit to your real `.git` repository. Every restore takes an automatic `pre-rewind` snapshot first, so even an undo can be undone with `redo`.

## Quick start

Requires Node.js `>= 22.5.0` and `git`.

```bash
# Save a shadow checkpoint of your current working tree
npx -y github:keenfolk1-lgtm/agent-undo save "before auth refactor"

# List saved shadow checkpoints
npx -y github:keenfolk1-lgtm/agent-undo log

# Preview what restoring a checkpoint would change or delete
npx -y github:keenfolk1-lgtm/agent-undo undo <id> --dry-run

# Rewind to a checkpoint (saves pre-rewind first) and optionally redo
npx -y github:keenfolk1-lgtm/agent-undo undo <id>
npx -y github:keenfolk1-lgtm/agent-undo redo
```

### MCP server registration

```bash
claude mcp add agent-undo -- npx -y github:keenfolk1-lgtm/agent-undo serve
```

Or add to `mcp.json`:

```json
{
  "mcpServers": {
    "agent-undo": {
      "command": "npx",
      "args": ["-y", "github:keenfolk1-lgtm/agent-undo", "serve"]
    }
  }
}
```

### Automatic `PreToolUse` hook

Connect `hooks/checkpoint-hook.mjs` as a `PreToolUse` hook in Claude Code or Antigravity so a debounced shadow snapshot runs automatically before `edit_file`, `write_file`, `Edit`, `Write`, or `Bash`:

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "edit_file|write_file|Edit|Write|MultiEdit|Bash",
        "hooks": [{ "type": "command", "command": "node /path/to/agent-undo/hooks/checkpoint-hook.mjs" }]
      }
    ]
  }
}
```

## Safety guarantees

`agent-undo` sets `GIT_DIR` and `GIT_INDEX_FILE` to `~/.agent-undo/<hash>.git`, leaving `<workspace>/.git` and its index untouched. `.gitignore` rules are honored, binary/archive build artifacts (`.exe`, `.apk`, `.dmg`, `.zip`, `.db`) and files over 10 MB are skipped automatically, and unsafe targets (home directory, filesystem root, `.gemini/config`) are blocked.

## MCP tools

| Tool | Purpose |
| --- | --- |
| `checkpoint_save` | Creates a shadow tree commit if working tree bytes changed since the previous checkpoint. |
| `checkpoint_list` | Lists checkpoint IDs, ISO timestamps, and labels. |
| `checkpoint_diff` | Shows `--stat` and unified diff between two checkpoints or against current files. |
| `checkpoint_restore` | Rewinds all files or a `--file` subset after taking a `pre-rewind` snapshot and prunes emptied folders. |
| `checkpoint_redo` | Restores the latest automatic `pre-rewind` snapshot to reverse a restore. |
| `checkpoint_prune` | Keeps the latest N checkpoints and runs `git gc --prune=now` on the shadow store. |

## Limitations

Checkpoints store snapshots of non-ignored text and binary files inside `~/.agent-undo/`, which consumes local disk space proportional to changed objects until `prune` runs. Files outside the workspace root or ignored via `.gitignore` (such as `.env` or `node_modules`) are intentionally skipped by snapshots and untouched on restore.

## License

[MIT](LICENSE)

Related tools: [mcp-diet](https://github.com/keenfolk1-lgtm/mcp-diet) · [skill-guard](https://github.com/keenfolk1-lgtm/skill-guard) · [blast-radius-mcp](https://github.com/keenfolk1-lgtm/blast-radius-mcp) · [flight-recorder-mcp](https://github.com/keenfolk1-lgtm/flight-recorder-mcp) · [de-slop](https://github.com/keenfolk1-lgtm/de-slop)