Claude Code Hooks let you intercept tool usage and run shell commands at specific lifecycle events—making them the ideal way to replace git commit and gh pr create with omni. Unlike Rules (advisory, in CLAUDE.md) or Skills (discovered by the model), hooks are system-triggered and fire automatically every time the matched action occurs. code.claude
Add the following to your project's .claude/settings.json (or ~/.claude/settings.json for all projects): code.claude
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/omni-intercept.sh"
}
]
}
]
}
}Then create .claude/hooks/omni-intercept.sh:
#!/usr/bin/env bash
set -euo pipefail
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // ""')
# Intercept git commit → omni commit
if echo "$COMMAND" | grep -qE '^git\s+commit'; then
echo "Use 'omni commit --yes --json' instead of git commit." >&2
exit 2
fi
# Intercept gh pr create / git push → omni pr
if echo "$COMMAND" | grep -qE '(gh\s+pr\s+create|git\s+push)'; then
echo "Use 'omni pr --yes --json' instead of gh pr create / git push." >&2
exit 2
fi
# Allow everything else
exit 0Make it executable:
chmod +x .claude/hooks/omni-intercept.shHow it works:
- The
PreToolUseevent fires every time Claude is about to execute a Bash command. code.claude - The
matcher: "Bash"ensures only shell commands are inspected. code.claude - Exit code 2 is a blocking error—it prevents the tool call and sends your
stderrmessage back to Claude as feedback, prompting it to useomni commitoromni prinstead. code.claude - Exit code 0 lets all other commands pass through untouched. code.claude
For the agent workflow, pair this with a CLAUDE.md rule so Claude knows the correct commands:
## Git Policy
- Never use `git commit` or `gh pr create` directly.
- Use `omni commit --yes --json` for commits.
- Use `omni pr --yes --json` for pull requests.
- See the command expectation matrix in docs for all flags.This gives you a two-layer safety net: the CLAUDE.md rule guides Claude's behavior, and the hook enforces it by blocking any git commit or gh pr create calls that slip through. code.claude