Claude Code Hooks vs Git Hooks
Git hooks protect repository operations. Claude Code hooks observe and steer the agent while it works. They are complementary, not interchangeable.
Claude Code hooks and Git hooks both run automation, but they fire at different layers. Git hooks run when Git performs repository operations such as commit, merge, applypatch, and push. Claude Code hooks run during the Claude Code session lifecycle and agent tool loop.
Git hooks: repository lifecycle
The official Git hooks documentation says hooks are programs placed in a hooks directory, usually $GIT_DIR/hooks or a path configured with core.hooksPath. Git invokes them at specific moments in Git operations. A pre-commit hook can block a commit. A commit-msg hook can validate the message. Server-side hooks can inspect pushes.
Git hooks are excellent for repository policy: formatting, linting, secret checks, commit-message conventions, and push-time enforcement.
Claude Code hooks: agent lifecycle
Anthropic's Claude Code hooks reference describes hooks as user-defined commands, HTTP endpoints, or prompt hooks that execute at lifecycle events. Events include SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop, and others. Command hooks receive JSON context on stdin.
That makes Claude Code hooks useful for agent-aware automation: inject context at session start, inspect tool calls before execution, record edits after tool use, summarize state when a turn stops, or add deterministic feedback after a file change.
The difference that matters
A Git hook sees the repository event. A Claude Code hook sees the agent event. If you only use Git hooks, you may know a commit happened but not which prompt caused it or what Claude observed while editing. If you only use Claude Code hooks, you may capture rich session context but miss enforcement at the final commit or push boundary.
How h5i combines them
h5i's Claude Code hook commands are designed for agent context. h5i hook session-start prints prior context into the new session. h5i hook run reads JSON from Claude Code as a PostToolUse handler and emits h5i context traces. h5i hook stop checkpoints recent context before the session ends.
That can coexist with Git hooks for conventional repository policy. For example, Claude Code hooks can capture the prompt and tool trace, while a Git pre-commit hook runs tests or blocks secrets.
Practical rule
Use Claude Code hooks for agent observability and session memory. Use Git hooks for repository gates. Use h5i to connect the two into provenance that survives beyond the chat window.
FAQ
Can a Git hook capture Claude Code prompts?
Not reliably by itself. Git hooks run at Git operations and do not naturally receive Claude Code session context.
Can a Claude Code hook replace pre-commit?
It can run checks, but repository enforcement still belongs at Git boundaries if you want the policy to apply to all contributors and tools.
Which one should I install first?
For AI provenance, install Claude Code hooks first. For enforcement, keep or add Git hooks and CI.
Sources and verification
This article avoids vendor-specific claims that were not checked against primary docs or local h5i CLI behavior.
Bring AI provenance into Git
h5i records prompts, context, test evidence, review signals, and agent messages alongside normal Git history.
Star on GitHub Read the guides