Git Add Changes Verifier
Streamline your workflow with this automatically, stage, changes, after. Includes structured workflows, validation checks, and reusable patterns for post tool.
Git Add Changes Verifier
Automatically stages modified files in git after Claude edits or writes them, streamlining the commit workflow by keeping the staging area current.
When to Use This Hook
Attach this hook when you need to:
- Keep git staging area synchronized with every file Claude modifies during a session
- Eliminate the manual
git addstep between editing files and committing changes - Ensure no edited files are accidentally left unstaged when creating commits
Consider alternatives when:
- You prefer to selectively stage files and review diffs before adding to the index
- Your workflow involves amending commits frequently and auto-staging could include unwanted changes
Quick Start
Configuration
name: git-add-changes-verifier type: hook trigger: PostToolUse category: post-tool
Example Trigger
# Hook triggers after Claude edits or writes a file claude> Edit src/components/Header.tsx # File is automatically staged in git
Example Output
Staged: src/components/Header.tsx
Core Concepts
Auto-Staging Overview
| Aspect | Details |
|---|---|
| Edit Matcher | Stages files after Edit tool operations |
| Write Matcher | Stages files after Write tool operations |
| Command | git add "$CLAUDE_TOOL_FILE_PATH" |
| Error Handling | Suppressed for non-git directories |
| Scope | Only stages the specific file that was modified |
Staging Workflow
Tool Completes (Edit or Write)
|
Get File Path
|
Run git add
/ \
Success Fail
| |
Staged Suppress
(non-git)
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
matchers | string[] | ["Edit","Write"] | Tool operations that trigger auto-staging |
exclude_patterns | string[] | [] | File patterns to skip staging (e.g., *.test.js) |
suppress_errors | boolean | true | Silently handle non-git repositories |
verify_staged | boolean | false | Echo confirmation message after staging |
dry_run | boolean | false | Show what would be staged without actually staging |
Best Practices
-
Exclude Generated Files - Add patterns for generated files (build output, compiled assets) to
exclude_patternsso they are not automatically staged. Auto-staging generated files leads to noisy commits. -
Review Before Committing - Auto-staging is convenient but removes one review checkpoint. Always run
git diff --cachedbefore committing to verify the staged changes match your intent. -
Combine with Pre-Commit Hooks - Since files are auto-staged, your git pre-commit hooks (linting, formatting) will run on the correct set of files. This creates a smooth pipeline from edit to validated commit.
-
Use verify_staged for Visibility - Enable the
verify_stagedoption during initial setup so you can see which files are being staged. Once you trust the workflow, disable it to reduce output noise. -
Handle New Files Correctly - The
Writematcher handles new file creation, but ensure your.gitignoreis up to date so newly created files that should not be tracked (temp files, secrets) are excluded.
Common Issues
-
Staging Files in Non-Git Directories - If Claude edits files outside a git repository, the
git addcommand fails. The error suppression handles this gracefully, but consider adding a git directory check first. -
Accidentally Staging Secrets - If Claude writes a
.envfile or config with credentials, the hook auto-stages it. Add*.envand sensitive file patterns toexclude_patternsto prevent this. -
Partial Staging on Multi-Edit Operations - If a single logical change spans multiple files, some may be staged before the full change is complete. This is generally harmless but can create confusing intermediate states in
git status.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.