This guide shows how to use Claude's .claude/settings.json hooks to create automatic Git checkpoints with detailed summaries that can be easily rolled back.
The checkpoint system automatically creates Git commits and tags at key points during Claude's operations:
- Before editing files - Preserves the original state
- After editing files - Captures the changes made
- Before creating new files - Marks the project state
- At the start of user tasks - Major checkpoints for each request
- At session end - Summary and final checkpoint
- Copy the example settings file:
cp .claude/settings-checkpoint-example.json .claude/settings.json- Make the checkpoint manager executable:
chmod +x .claude/helpers/checkpoint-manager.sh- Initialize Git in your project (if not already):
git init
git add .
git commit -m "Initial commit before Claude checkpoints"The checkpoint system uses these hooks in .claude/settings.json:
Creates a checkpoint before Claude edits any file:
- Creates a stash of current changes
- Creates a checkpoint branch
- Stores checkpoint metadata in
.claude/checkpoints/
Creates a checkpoint after Claude edits a file:
- Commits the changes with a detailed message
- Creates a Git tag for easy reference
- Includes diff summary in checkpoint metadata
Creates a major checkpoint when you submit a task:
- Commits all current changes
- Can optionally create a GitHub release (set
CREATE_GH_RELEASE=true) - Stores task description for reference
Creates a session summary when Claude stops:
- Generates a markdown summary of all checkpoints
- Lists all modified files
- Provides rollback instructions
- Creates a final session-end tag
The checkpoint manager script (.claude/helpers/checkpoint-manager.sh) provides easy checkpoint management:
./.claude/helpers/checkpoint-manager.sh list./.claude/helpers/checkpoint-manager.sh show checkpoint-20240130-143022# Soft reset (keeps changes staged)
./.claude/helpers/checkpoint-manager.sh rollback checkpoint-20240130-143022
# Hard reset (discards changes)
./.claude/helpers/checkpoint-manager.sh rollback checkpoint-20240130-143022 --hard
# Create new branch from checkpoint
./.claude/helpers/checkpoint-manager.sh rollback checkpoint-20240130-143022 --branch./.claude/helpers/checkpoint-manager.sh diff checkpoint-20240130-143022./.claude/helpers/checkpoint-manager.sh clean./.claude/helpers/checkpoint-manager.sh summaryIf you prefer Git commands directly:
git tag -l 'checkpoint-*' | sort -r# View what changed
git diff checkpoint-20240130-143022
# Soft reset (keeps changes)
git reset --soft checkpoint-20240130-143022
# Hard reset (discards changes)
git reset --hard checkpoint-20240130-143022
# Create branch from checkpoint
git checkout -b recovery checkpoint-20240130-143022To enable GitHub releases for major checkpoints:
- Install GitHub CLI:
# macOS
brew install gh
# Linux
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update && sudo apt install gh- Authenticate:
gh auth login- Enable releases in hooks:
export CREATE_GH_RELEASE=trueCheckpoints are stored in multiple ways:
- Git Tags:
checkpoint-YYYYMMDD-HHMMSS - Git Branches:
checkpoint/pre-edit-YYYYMMDD-HHMMSS - Metadata Files:
.claude/checkpoints/*.json - Session Summaries:
.claude/checkpoints/summary-*.md
- Regular Commits: The checkpoint system works best with a clean working directory
- Meaningful Tasks: Start each Claude session with a clear task description
- Periodic Cleanup: Run
checkpoint-manager.sh cleanweekly to remove old metadata - Tag Management: Periodically push important tags to remote:
git push origin --tags
You can customize the checkpoint behavior by modifying the hooks:
Add conditions to check file patterns or sizes
Modify the JSON output to include additional information
Add webhook notifications or trigger builds on checkpoints
Modify the tag/branch naming patterns
- Ensure Git is initialized:
git init - Check hook permissions:
chmod +x .claude/settings.json - Verify jq is installed:
which jq
- Adjust hooks to be more selective
- Use the clean command regularly
- Consider disabling pre-edit checkpoints for small changes
# Find last known good checkpoint
git reflog
git tag -l 'checkpoint-*' --sort=-creatordate | head -5
# Force recovery
git reset --hard <checkpoint-or-commit>-
Start Claude with a task:
"Please refactor the authentication system"- Creates task checkpoint:
task-20240130-140000
- Creates task checkpoint:
-
Claude edits auth.js:
- Pre-edit checkpoint:
checkpoint/pre-edit-20240130-140100 - Post-edit checkpoint:
checkpoint-20240130-140130
- Pre-edit checkpoint:
-
Claude creates new test file:
- Pre-create checkpoint:
checkpoint/pre-create-20240130-140200
- Pre-create checkpoint:
-
Session ends:
- Final checkpoint:
session-end-session-20240130-141000 - Summary created with all changes
- Final checkpoint:
-
Need to rollback:
./.claude/helpers/checkpoint-manager.sh list ./.claude/helpers/checkpoint-manager.sh rollback checkpoint-20240130-140100 --branch
This system ensures you can always recover from any changes Claude makes, with full visibility into what was modified and when.