hook-git-auto-backup
Automatically backup your work with git commits after each Claude session
Automatically creates git commits after each Claude Code session to prevent work loss.
Features
- π Auto-commits all changes when session ends
- β° Timestamped commit messages
- π― Only commits when there are actual changes
- π‘οΈ Safe and non-intrusive
- π Clear commit attribution to Claude Code
How it Works
This plugin uses two hooks for automatic backup:
SessionStart Hook (init-config.js)
Runs at session start:
- Reads plugin version from
plugin.json - Checks if configuration file exists at
.plugin-config/hook-git-auto-backup.json - If config exists, compares
_pluginVersionwith current plugin version - If versions match, exits immediately (fast!)
- If versions differ, performs automatic migration:
- Merges existing user settings with new default fields
- Preserves all custom user configurations
- Updates
_pluginVersionto current version
- If config doesn't exist, creates it with default settings
Stop Hook (backup.js)
Runs when your Claude Code session ends:
- Check if the directory is a git repository
- Check if there are uncommitted changes (
git status --porcelain) - If changes exist:
- Stage all changes (
git add -A) - Create a commit with timestamp
- Display commit hash in the session
- Stage all changes (
Installation
/plugin install hook-git-auto-backup@dev-gom-plugins
Usage
Once installed, the plugin works automatically. No configuration needed!
When you end a Claude Code session, if there are changes, you'll see:
β Git Auto-Backup: Changes committed successfully (a1b2c3d)
Example Commit Message
Auto-backup: 2025-10-14 12:34:56
π€ Generated with Claude Code Auto-Backup Plugin
Configuration
The plugin automatically creates a configuration file at .plugin-config/hook-git-auto-backup.json on first run.
Automatic Configuration Migration
When you update the plugin, your settings are automatically migrated:
- β Preserves your custom settings
- β Adds new configuration fields with default values
- β
Version tracked via
_pluginVersionfield - β Zero manual intervention required
Available Configuration Options
showLogs
- Description: Show auto-backup messages in console
- Default:
false - Example:
true(show backup confirmations)
requireGitRepo
- Description: Only run if it's a Git repository
- Default:
true - Recommended:
true(use only in Git projects)
commitOnlyIfChanges
- Description: Only create commits when there are changes
- Default:
true - Recommended:
true(prevents empty commits)
includeTimestamp
- Description: Include timestamp in commit message
- Default:
true - Recommended:
true(track session time)
How to Change Settings
Edit .plugin-config/hook-git-auto-backup.json in your project root:
{
"showLogs": false,
"requireGitRepo": true,
"commitOnlyIfChanges": true,
"includeTimestamp": true
}
Customizing Commit Message
To change the commit message format, edit the scripts/backup.js file:
const timestamp = config.includeTimestamp
? new Date().toISOString().replace('T', ' ').slice(0, 19)
: '';
const commitMessage = `Auto-backup: ${timestamp}`;
Hook Output
The plugin follows Claude Code Hook best practices by outputting a single JSON result:
console.log(JSON.stringify({
systemMessage: 'β Git Auto-Backup: Changes committed successfully (abc1234)',
continue: true
}));
When the Plugin Runs
- β Session ends normally
- β Session interrupted by Stop hook
- β Does NOT run if not a git repository
- β Does NOT run if no changes detected
Best Practices
Recommended .gitignore
Add plugin-generated files to your .gitignore:
.todos-report.md
.complexity-log.txt
.docs-summary.md
.session-summary.md
Working with Branches
The plugin commits to your current branch. Make sure you're on the correct branch before starting a session:
git checkout feature-branch
claude
Reverting Auto-Commits
If you need to undo an auto-backup commit:
git reset --soft HEAD~1
Troubleshooting
Plugin not creating commits?
-
Check if it's a git repository:
git status -
Verify git user is configured:
git config user.name git config user.email -
Check plugin is installed:
/plugin
Commits are too frequent?
This plugin only commits once per session (when you exit). If you want more control, consider:
- Using manual commits during your session
- Squashing auto-backup commits later with
git rebase -i
Related Plugins
- Session File Tracker - Summarizes file operations
- TODO Collector - Tracks TODO comments
- Complexity Monitor - Checks code complexity
Technical Details
Script Locations
~/.claude/plugins/marketplaces/dev-gom-plugins/plugins/hook-git-auto-backup/scripts/init-config.js- Configuration initialization~/.claude/plugins/marketplaces/dev-gom-plugins/plugins/hook-git-auto-backup/scripts/backup.js- Git backup execution
Hook Types
- SessionStart - Initializes configuration on session start
- Stop - Creates git backup when session ends
Dependencies
- Node.js
- Git
Timeout
15 seconds
Version
Current Version: 1.1.1
Changelog
v1.1.1 (2025-10-20)
- π Auto Migration: Plugin version-based configuration migration
- π¦ Smart Updates: Preserves user settings while adding new fields
- π― SessionStart Hook: Auto-creates configuration file on session start
- β‘ Performance: SessionStart hook exits immediately if config is up-to-date
- π Cross-Platform: Enhanced path handling for Windows/macOS/Linux compatibility
v1.0.0
- Initial release
Contributing
Feel free to customize this plugin:
- Edit
backup.jsto change commit message format - Modify
plugin.jsonto change hook behavior - Test with
/plugin validate
License
Apache License 2.0 - See LICENSE for details
Credits
Part of the Claude Code Developer Utilities collection.
πQuick Installation
/plugin install hook-git-auto-backup@dev-gom-pluginsRun this command in Claude Code to install the plugin.