# Claude Code

What Claude Code's checkpoints and /rewind undo, and Folder's copy of a folder on this Mac before each session, to put any change back. The two hook lines.

A copy before each session, and every change it made, file by file. On This Mac.

## Undo for Claude Code

Works in a folder [on this Mac](/docs/on-this-mac). Once, in Folder Settings › Undo, Let Folder See Claude Code's Sessions… asks for access to your `.claude` folder. After that, Undo for Claude Code is a switch in the Add sheet and in Folder Settings, on unless you turn it off. While any folder has it on, `.claude/settings.json` carries the two hook lines below.

When a Claude Code session starts in the folder, Folder copies the folder first, and the session waits until the copy exists. The copy uses APFS clones, so it is quick and takes almost no space. When the session ends, the earlier versions of the files it changed are kept for 30 days.

## Undo a Session, Step by Step

1. In Folder, File › Add a Folder… (⌘N), On This Mac, and pick the project folder.
2. Leave Undo for Claude Code on. The first time, Let Folder See Claude Code's Sessions… asks for your `.claude` folder, and Folder adds the two hook lines below to `.claude/settings.json`.
3. Start Claude Code in the folder as usual. The session waits until the copy exists: 607 files took 0.12 seconds when we measured.
4. After the session, View › Sessions (⌘2) lists every file it changed, added or deleted. Select files and Restore This File…, or Restore All… or Keep All.

## Claude Code's Own Checkpoints

Claude Code takes a checkpoint before each prompt you send. Run `/rewind`, or press Esc twice with an empty prompt, pick a prompt, and choose Restore code, Restore conversation, or both. Checkpoints are saved with the conversation, so `/rewind` works after you resume a session. Claude Code deletes a session's file snapshots about 30 days after it last saved one.

What a checkpoint does not bring back, from [Claude Code's docs](https://code.claude.com/docs/en/checkpointing):

- A file only shell commands changed: an `rm`, `mv` or `cp` Claude runs on a file it never edited with its own tools stays as it is.
- A subagent's edits to files Claude had not edited itself.
- Changes you make outside Claude Code, and edits from other sessions running at the same time.
- Symlinked and hard-linked files, which a restore skips.

Claude Code's docs say checkpoints are not a replacement for version control. Folder's copy looks at the disk, not at Claude's tools, so a file a shell command deleted shows up in Sessions as deleted and can be put back.

## Git

If the folder is a git repository, `git status` and `git diff` show what changed since the last commit, and `git checkout -- <file>` puts a file back. Changes you had not committed before the session are not in git; the copy has them.

## Sessions

View › Sessions (⌘2) lists each session and the files it changed, file by file. In a session, select files and Restore This File… (or Restore 3 Files…), or use Restore All… or Keep All. Restore puts the current version in the Trash first, so a restore can be undone too.

Without Claude Code you can do the same by hand: File › Save Restore Point (⌥⌘S) takes the copy, and Sessions lists what changed since.

## A Folder on Another Disk

Clones only work within one disk. For a folder on an external disk or another volume, the copy is a plain copy, with build folders skipped.

## The Two Hook Lines

Folder adds two [hooks](https://code.claude.com/docs/en/hooks) to Claude Code's settings while any folder has Undo for Claude Code on. Before it changes the file, Folder keeps a copy beside it, `settings.json.folder-backup`. When no folder has it on, both lines come out.

### SessionStart

Runs when a session starts or resumes (matcher `startup|resume`), with a 30 second timeout. It reads the session's folder and id from what Claude Code passes it, opens a `folder://local/start` link to the Folder app, and waits up to 25 seconds for the app to say the copy of the folder is made, so Claude never writes before the copy exists. It always exits 0, so a Mac without Folder never notices it.

```sh
j=$(cat); d=$(printf %s "$j" | sed -n 's/.*"cwd" *: *"\([^"]*\)".*/\1/p' | head -1 | base64 | tr '+/' '-_' | tr -d '=\n'); s=$(printf %s "$j" | sed -n 's/.*"session_id" *: *"\([^"]*\)".*/\1/p' | head -1); k=$(date +%s)$$; r="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/folder-ready"; mkdir -p "$r"; u="folder://local/start?a=claude&d=$d&s=$s&k=$k"; /usr/bin/open -g -b dev.folder.app "$u" >/dev/null 2>&1 && { i=0; while [ ! -e "$r/$k" ] && [ $i -lt 125 ]; do sleep 0.2; i=$((i+1)); done; rm -f "$r/$k"; }; exit 0 # folder.dev on this mac
```

### SessionEnd

Runs when the session ends, with a 10 second timeout. It tells the app the session is over, so the list of what it changed is final and the earlier versions of those files are kept for 30 days.

```sh
j=$(cat); s=$(printf %s "$j" | sed -n 's/.*"session_id" *: *"\([^"]*\)".*/\1/p' | head -1); /usr/bin/open -g -b dev.folder.app "folder://local/end?s=$s" >/dev/null 2>&1; exit 0 # folder.dev on this mac
```

### What They Use

Only system tools: `sed`, `base64`, `tr`, `open`, `sleep`. They run as you, send nothing over the network, and the comment `# folder.dev on this mac` at the end of each line is how Folder finds its own lines again.

Source: https://folder.dev/docs/claude-code