This hook integrates with Claude Code to automatically create git checkpoints (snapshots) of your code before any file modifications. It provides a safety net allowing you to easily restore previous states if needed, without interfering with your main git repository.
git clone https://github.com/Ixe1/claude-code-checkpointing-hook.gitClaude Code Checkpointing Hook automatically creates git snapshots before file writes, edits, and multi-edits, providing a safety net for code recovery. It uses shadow repositories stored separately from your main project to avoid cluttering your git history while maintaining full version control capabilities. The tool offers interactive restoration with diff preview, configurable retention policies, and efficient storage via git delta compression. Developers benefit from risk-free code exploration—revert unwanted changes instantly without impacting their primary repository. Installation is straightforward via a bash script, with shell commands for listing, searching, and restoring checkpoints.
Run ./install.sh to set up the hook (requires Python 3.6+, Git, and Linux/macOS). Use ckpt list to view checkpoints, ckpt restore to interactively recover previous states with diff preview, and ckpt search <term> to find specific snapshots. Configure retention periods and exclude patterns in ~/.claude/hooks/ixe1/claude-code-checkpointing-hook/config.json.
Restore code to a previous state after Claude Code makes unintended file modifications
Safely explore AI-generated code changes with easy rollback capability
Track file modifications across Claude Code sessions with searchable checkpoint history
Maintain code recovery without polluting your main git repository
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/Ixe1/claude-code-checkpointing-hookCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Create a checkpoint hook for my [PROJECT_NAME] project in [PROGRAMMING_LANGUAGE]. I want to automatically save a snapshot of my code before any modifications. The checkpoint should be stored in a [STORAGE_LOCATION] directory and include a timestamp. Make sure the hook works with my existing git workflow.
# Git Checkpoint Hook for [PROJECT_NAME]
```python
import os
import shutil
from datetime import datetime
def create_checkpoint():
# Get current timestamp
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
# Define source and destination paths
source_dir = os.getcwd()
destination_dir = os.path.join(os.getcwd(), 'checkpoints', f'checkpoint_{timestamp}')
# Create checkpoint directory
os.makedirs(destination_dir, exist_ok=True)
# Copy all files to checkpoint directory
for root, dirs, files in os.walk(source_dir):
for file in files:
if file.endswith('.py') or file.endswith('.js'): # Add more extensions as needed
source_file = os.path.join(root, file)
relative_path = os.path.relpath(source_file, source_dir)
destination_file = os.path.join(destination_dir, relative_path)
os.makedirs(os.path.dirname(destination_file), exist_ok=True)
shutil.copy2(source_file, destination_file)
print(f'Checkpoint created at {destination_dir}')
# Call the function to create a checkpoint
create_checkpoint()
```
## How to Use This Hook
1. Save this script as `create_checkpoint.py` in your project root directory.
2. Add the following line to your `.git/hooks/pre-commit` file:
```bash
python ../create_checkpoint.py
```
3. Make sure the `checkpoints` directory exists in your project root.
4. Now, every time you commit changes, a checkpoint will be automatically created.AI assistant built for thoughtful, nuanced conversation
Your one-stop shop for church and ministry supplies.
Automate your browser workflows effortlessly
Agents that listen, think and act for you.
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan