agentleFS
binay-pybinay-py/claude-skills/skills/bash-checkpoint/SKILL.md

bash-checkpoint

Skill1 starsChanged 6 days agoMITView on GitHub

Undo button for shell commands Claude runs. A PreToolUse hook that snapshots files before destructive Bash/PowerShell commands (rm, mv, git clean/reset/checkout, sed -i, overwrites), blocks catastrophic ones (rm -rf ~ or /, Remove-Item -Recurse C:\, mkfs, dd to a disk), and forces a confirmation before force-push, git reset --hard and DROP TABLE, even in bypass mode. Use when the user wants protection from Claude deleting files, asks how to undo a command Claude ran, or wants to restore something Claude removed.

  • Reads credentials
  • Deletes or force-pushes
  • Commits and pushes

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add to ~/.claude/settings.json (all projects) or .claude/settings.json (one project), using the absolute path to the script:

    line 11

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

bash-checkpoint

scripts/checkpoint.mjs is zero-dependency Node 22+. Claude Code's own checkpoints cover file edits, not shell commands. This covers those.

Install (ask the user first, it changes their settings)

Add to ~/.claude/settings.json (all projects) or .claude/settings.json (one project), using the absolute path to the script:

{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash|PowerShell",
        "hooks": [{ "type": "command", "command": "node \"/ABSOLUTE/PATH/bash-checkpoint/scripts/checkpoint.mjs\" hook" }] }
    ]
  }
}

Merge into existing hooks rather than overwriting them. Restart Claude Code, then check with /hooks.

What happens on each shell command

CommandAction
rm -rf ~, rm -rf /, rm -rf "$HOME", Remove-Item -Recurse C:\, rd /s C:\, mkfs, dd of=/dev/sda, fork bombBlocked (exit 2). Claude is told the user must run it themselves.
git push --force, git reset --hard, git clean -f, git checkout -- ., branch -D, DROP TABLEUser must confirm, even in bypass mode, plus a snapshot
rm, mv, sed -i, find -delete, > file, Remove-Item, git restore/stash/rm …Snapshot, then runs normally
everything elsenothing (no slowdown)

Snapshots: in a git repo, the whole working tree (tracked + untracked, respecting .gitignore, so ignored files like .env are not in it) is stored as a commit under refs/claude-checkpoints/. Branches, index and stash are untouched. Outside git, and for paths the command names outside the repo (rm ../other/x, rm /tmp/y), the paths are copied to ~/.claude/checkpoints/<id>/ (up to 300 MB).

Restoring

node checkpoint.mjs list               # checkpoints for the current folder (--all for every folder)
node checkpoint.mjs show <id>          # what differs from now
node checkpoint.mjs restore <id>       # put everything back
node checkpoint.mjs restore <id> src/  # just one path
node checkpoint.mjs prune --keep 50
node checkpoint.mjs test "rm -rf ~"    # see what the rules would do
node tests/run.mjs                    # 67 rule test cases (block / ask / snapshot / none)

Restoring brings back deleted and modified files and leaves files created after the snapshot alone.

Limits (tell the user)

  • It's pattern-based, so a determined or obfuscated command (eval $(echo …), a script file that deletes things) can get past it. It's a seatbelt, not a sandbox. Pair it with deny rules (claude-safety-audit --fix) and run risky work in a container.
  • The snapshot runs before the command, so files the same command creates and then deletes can't be saved.
  • Block rules check each command segment and fire only when that segment runs the program (rm, Remove-Item, mkfs…), unwrapping bash -c, sh -c, eval, powershell -Command and cmd /c. Mentions inside quotes (commit messages, grep patterns) pass. A heredoc body fed to a command that only reads it (git commit -F - <<EOF, cat > notes.md <<EOF) is data and is skipped. It is still checked when a shell runs it (bash <<EOF, ssh host <<EOF, cat <<EOF | sh) or when the same command later runs a script (bash x.sh, ./x.sh).
  • Quoted text is ignored for snapshot/ask decisions, so git commit -m "rm old docs" or grep "rm" does nothing. Compound commands (cd dir && rm x) are followed segment by segment.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.