G

Git Add Changes Verifier

Streamline your workflow with this automatically, stage, changes, after. Includes structured workflows, validation checks, and reusable patterns for post tool.

HookClipticspost toolv1.0.0MIT
0 views0 copies

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 add step 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

AspectDetails
Edit MatcherStages files after Edit tool operations
Write MatcherStages files after Write tool operations
Commandgit add "$CLAUDE_TOOL_FILE_PATH"
Error HandlingSuppressed for non-git directories
ScopeOnly 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

ParameterTypeDefaultDescription
matchersstring[]["Edit","Write"]Tool operations that trigger auto-staging
exclude_patternsstring[][]File patterns to skip staging (e.g., *.test.js)
suppress_errorsbooleantrueSilently handle non-git repositories
verify_stagedbooleanfalseEcho confirmation message after staging
dry_runbooleanfalseShow what would be staged without actually staging

Best Practices

  1. Exclude Generated Files - Add patterns for generated files (build output, compiled assets) to exclude_patterns so they are not automatically staged. Auto-staging generated files leads to noisy commits.

  2. Review Before Committing - Auto-staging is convenient but removes one review checkpoint. Always run git diff --cached before committing to verify the staged changes match your intent.

  3. 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.

  4. Use verify_staged for Visibility - Enable the verify_staged option during initial setup so you can see which files are being staged. Once you trust the workflow, disable it to reduce output noise.

  5. Handle New Files Correctly - The Write matcher handles new file creation, but ensure your .gitignore is up to date so newly created files that should not be tracked (temp files, secrets) are excluded.

Common Issues

  1. Staging Files in Non-Git Directories - If Claude edits files outside a git repository, the git add command fails. The error suppression handles this gracefully, but consider adding a git directory check first.

  2. Accidentally Staging Secrets - If Claude writes a .env file or config with credentials, the hook auto-stages it. Add *.env and sensitive file patterns to exclude_patterns to prevent this.

  3. 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.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates