Commit gate for Claude Code and Codex
Install the commit gate for Claude Code and Codex, which runs fallow audit before an agent commits or pushes and blocks a fail verdict.
AGENTS.md tells your coding agent to run fallow audit before it commits, but an agent can skip a step of its instructions. In the demo project, an agent adds describeOrder to src/services/orders.ts, nothing calls it, and the agent commits. The commit gate stops that commit. It is a hook that runs fallow audit before Claude Code or Codex commits or pushes, and blocks the command when the audit fails. The agent then gets the findings, fixes the code, and tries again.
How the commit gate works
The commit gate is a PreToolUse hook on the shell tool of the agent, so it runs before each shell command of the agent. It is not a Git hook: when you run git in a terminal, the hook does not run. Follow the commit of the agent from left to right:
Diagram source
sequenceDiagram
participant Agent
participant Hook as Commit gate
participant Fallow as fallow audit
Agent->>Hook: git commit
Hook->>Fallow: audit the change
Fallow-->>Hook: verdict fail
Hook-->>Agent: blocked, with the findings
Agent->>Agent: fix the code
Agent->>Hook: git commit
Hook->>Fallow: audit the change
Fallow-->>Hook: verdict pass
Hook-->>Agent: commit continuesFor each git commit and git push, the hook runs this command:
fallow audit --format json --quiet --explain --gate-marker agent
- On the verdict
passorwarn, the command continues. - On
fail, the hook blocks the command and gives the agent a short list of the findings. - When the audit cannot run, for example on an invalid ref, a folder without Git or an invalid config, the hook writes a notice and lets the command continue. A new repository can thus commit before the first audit that works.
The hook runs before the agent runs the shell command, so git push --no-verify does not skip it. When local Impact tracking is on, --gate-marker agent lets fallow record a block that a later audit clears.
The audit uses the default audit.gate value new-only, so only the findings that the change adds block a commit. An old finding in the same file, such as cancelOrder, does not. Changed code explains the verdict. Keep the check in CI too, because the commit gate checks only the commands that the agent runs.
Before you start
- Add fallow to the development dependencies of the project:
npm install --save-dev fallow. The hook looks for fallow in this order:./node_modules/.bin/fallow,fallowonPATH,yarn exec fallow, thennpx --no-install fallow. - The hook needs
bash. On Windows, use Git Bash or WSL.
Install the commit gate
fallow agent install installs the commit gate together with the skills and the MCP server. This is the recommended setup. To install only the commit gate:
-
Preview the files:
npx fallow hooks install --target agent --dry-runfallow hooks install --target agent (install) (dry run): .claude/settings.json would create .claude/hooks/fallow-gate.sh would create -
Install the hook:
npx fallow hooks install --target agent -
Commit the files, so that each team member gets the commit gate.
-
In Codex, trust the hook in
/hooks. Codex does not run a project hook before you trust it.
The installer chooses the agent from the folders in the project. With a .claude/ folder, it installs the hook for Claude Code. With a .codex/ folder, it installs the hook for Codex. With both, it installs both, and with neither, it installs the hook for Claude Code. To choose yourself, add --agent claude or --agent codex.
To install the commit gate in your home folder for all repositories, add --user. fallow hooks lists each option.
The installed files
The install writes two parts for each agent: a handler in the settings of the agent, and the gate script that the handler starts.
| Agent | Handler | Gate script |
|---|---|---|
| Claude Code | A PreToolUse handler with the matcher Bash in .claude/settings.json | .claude/hooks/fallow-gate.sh |
| Codex | A PreToolUse handler with the matcher ^Bash$ in .codex/hooks.json | .codex/hooks/fallow-gate.sh |
For Codex, the installer also writes a routing block in AGENTS.md. The block tells an agent without a hook to run the audit itself.
The handler goes up from the directory of the session to the nearest directory with the gate script, and runs the audit there. The audit thus covers the full project, also when the session works in a package folder. The walk stops at the first .git entry, so a nested worktree does not use the gate script of the checkout around it. When the walk finds no gate script, the Claude Code handler runs the script under $CLAUDE_PROJECT_DIR, and the Codex handler exits with code 0 and no output. The installer keeps each other handler in the settings file of the agent.
Each install writes the gate script again, so a change that you make in it does not stay. To change the behavior, use the config file and the environment variables below. The header of the installed script has the line # Installer version: X.Y.Z. Compare it with fallow --version when the gate does not agree with your fallow.
The gate reads the JSON of the audit with the JSON reader of fallow. A gate from an older fallow uses jq. When the gate finds neither, it prints a notice and lets the command continue without an audit.
Commit or push in another worktree
An agent can commit or push in another folder with git -C <dir> or cd <dir> && git .... The gate then audits the work tree of that folder.
A linked worktree shares its branches with the checkout of the session, so a push from a linked worktree can send the branch of the session. For such a push, the gate also audits the checkout of the session. It audits only the linked worktree when all of these are true:
- The push options are only
-u,-q,--set-upstream,--force-with-leaseand--force-if-includes. - Each refspec sends the branch that the linked worktree has checked out, for example
git -C ../feature push -u origin featureorHEAD. - A push without a refspec has
push.defaultunset or set tosimple,current,upstreamornothing, and no remote has apushormirrorsetting.
In all other cases, and when a git command fails, the gate audits the checkout of the session too. Findings in that checkout, such as untracked build output, then block the push. Run fallow agent install again after you update fallow to get this behavior.
The routing block in AGENTS.md
For Codex, the installer writes a block between <!-- fallow:setup-hooks:start --> and <!-- fallow:setup-hooks:end -->. The block starts like this:
## Fallow checks
Use fallow for code-quality, cleanup, and setup tasks in this repository. Fallow checks the changed code before each `git commit` and `git push`. In Claude Code and Codex, a PreToolUse hook from `fallow agent install` runs this check and blocks the command when the verdict is `fail`. Other agents run the check themselves: `fallow audit --format json --quiet --explain --gate-marker agent`. If the verdict is `fail`, fix the reported findings before you try again. A JSON runtime error such as `{ "error": true, ... }` does not block.
The rest of the block explains the default audit gate and holds the task map of fallow schema. A new install replaces the block in place.
Manual setup
Use fallow hooks install --target agent when you can. When you cannot run it, write the files by hand:
-
Write
.claude/settings.json:{ "$schema": "https://json.schemastore.org/claude-code-settings.json", "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "d=\"$(pwd)\"; until [ -f \"$d/.claude/hooks/fallow-gate.sh\" ] || [ -e \"$d/.git\" ] || [ \"$d\" = / ]; do d=\"$(dirname \"$d\")\"; done; if [ -f \"$d/.claude/hooks/fallow-gate.sh\" ]; then cd \"$d\" && exec ./.claude/hooks/fallow-gate.sh; fi; exec \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/fallow-gate.sh" } ] } ] } } -
Copy
crates/cli/src/setup_hooks/fallow-gate.shof the fallow repository to.claude/hooks/fallow-gate.sh. Leave out the# Installer version:line, because only the installer writes it. -
Make the script executable:
chmod +x .claude/hooks/fallow-gate.sh.
For Codex, the handler in .codex/hooks.json uses the matcher ^Bash$ and this command:
d="$(pwd)"; until [ -f "$d/.codex/hooks/fallow-gate.sh" ] || [ -e "$d/.git" ] || [ "$d" = / ]; do d="$(dirname "$d")"; done; if [ -f "$d/.codex/hooks/fallow-gate.sh" ]; then cd "$d" && exec ./.codex/hooks/fallow-gate.sh; fi; exit 0
The block message
When the hook blocks a command, the agent gets a message that names each finding that caused the block. This is the message for the commit of describeOrder in the demo project:
fallow-gate: blocked by fallow 3.49.0 at ./node_modules/.bin/fallow
fallow-gate: verdict fail, 1 finding(s) caused the block:
unused-export src/services/orders.ts:22 describeOrder
The first line names the version and the path of the fallow that ran. Each finding line has the form <kind> <path>:<line> <name>. With the default gate new-only, the list holds only the findings that the change adds. The full report still holds the old findings. With gate = "all", the list holds each finding that is not a warning. The message lists at most 50 findings, and gives the count of the rest. Its last line gives the path of the full JSON report, .fallow/gate-report.json in the audited tree. The .fallow/ folder has a .gitignore, so the report does not show in git status.
Set the policy
By default, the gate blocks only on the findings that the change adds. Two settings change which findings count:
- Block on each finding in the changed files. Set
"audit": { "gate": "all" }in the config file. Seeaudit.gate. - Compare with another branch. The hook passes no
--base, so the audit compares with the merge base of the upstream branch, or oforigin/main. On a fork, or when your team merges intodevelop, setFALLOW_AUDIT_BASE, for exampleFALLOW_AUDIT_BASE=upstream/main.
Version floor
The hook passes --gate-marker agent, and a fallow older than 2.85.0 rejects this option. Without a check, the audit would fail to run on such a version, and the hook would let each commit through. That is why the hook blocks when the fallow that it finds is older than FALLOW_GATE_MIN_VERSION, with the default 2.85.0. The block message shows how to update. This is the message when a team sets the floor above the installed version:
fallow-gate: blocked: ./node_modules/.bin/fallow is fallow 3.49.0, below required 4.0.0.
fallow-gate: older binaries reject the --gate-marker flag this gate passes
fallow-gate: (added in fallow v2.85.0), so the audit cannot run.
fallow-gate: update the fallow devDependency of the project (for example npm install -D fallow@latest),
fallow-gate: or set FALLOW_GATE_MIN_VERSION= to disable.
Set the variable in the environment of the agent:
# Require a newer fallow in your team
export FALLOW_GATE_MIN_VERSION=3.0.0
# Turn the check off
export FALLOW_GATE_MIN_VERSION=
Strict mode
By default, the hook lets a commit or push continue when it cannot run the audit, for example when it finds no fallow. It then prints the cause, the fix, and a line that names FALLOW_GATE_STRICT=1.
Set FALLOW_GATE_STRICT=1 in the environment of the agent to block in these cases:
- The hook finds no fallow.
- The hook finds no JSON reader and no jq.
- The hook cannot read the hook input, and the input can hold a git commit or push.
- The hook cannot create a temporary file.
- The audit gives a runtime error, an unexpected exit code, or a report that the hook cannot read.
export FALLOW_GATE_STRICT=1
To turn on strict mode for each user of a repository, install the gate with --strict and commit the gate script:
npx fallow agent install --strict
The install writes GATE_STRICT='1' into the gate script. A reinstall without a flag keeps that value. --no-strict turns strict mode off. fallow hooks install --target agent --strict does the same for the gate alone. With --user, strict mode applies to each repository that the user gate audits.
A non-empty FALLOW_GATE_STRICT overrides the value of the script. The values 0, false, no and off keep the default, so FALLOW_GATE_STRICT=0 skips the audit for one session.
The block message names the fix, the source of strict mode, and the opt-out:
fallow-gate: blocked: fallow binary not found (tried the node_modules/.bin of the install root, PATH, yarn and npx --no-install), so the audit cannot run (FALLOW_GATE_STRICT is set).
fallow-gate: install the project dependencies (for example npm install), or install fallow on PATH (for example npm install -g fallow).
fallow-gate: set FALLOW_GATE_STRICT=0 to skip the audit instead.
A gate that --strict wrote says (this gate was installed with --strict) instead.
A fresh clone blocks until you install the project dependencies. The first commit of a new repository also blocks, because the audit finds no base branch. Set FALLOW_GATE_STRICT=0 for that commit.
Inspect hook state
To see which hooks a project has, run npx fallow hooks status. It changes nothing:
Git hook: not installed
Claude hook: installed (.claude/hooks/fallow-gate.sh)
Codex hook: not installed
Codex block: not installed
Add --format json for a script. npx fallow agent status also reports a gate script from another fallow version as stale. To update it, run npx fallow agent install again.
Turn the commit gate off
The hook has no option to skip one command. To turn the commit gate off, remove it:
npx fallow hooks uninstall --target agent
fallow hooks uninstall --target agent (uninstall):
.claude/settings.json updated (1 handler removed)
.claude/hooks/fallow-gate.sh removed
The command removes the fallow handler and each gate script that you did not edit. Other handlers stay.
If it fails
- The hook does not block. Run the agent command again with
FALLOW_GATE_DEBUG=1. The hook then logs each command that it skips because it is not a commit or a push:fallow-gate: not a git commit/push, skipping audit. - "fallow binary not found". The hook found no fallow, and lets the command continue. Install fallow in the project. To block in this case, use strict mode.
- "below required". The fallow that the hook found is older than the version floor. Update it.
- Codex commits without a check. Trust the hook in
/hooks. - The hook blocks on old findings. The audit compares with the wrong base. Set
FALLOW_AUDIT_BASE.
Reference
The gate script reads these environment variables:
| Variable | Default | Description |
|---|---|---|
FALLOW_GATE_REPORT | .fallow/gate-report.json | Agent gate script of fallow agent install: path of the full JSON report that the gate writes on a block (default .fallow/gate-report.json). The fallow binary does not read it. |
FALLOW_GATE_OUTPUT | Agent gate script of fallow agent install: set to json to print the full JSON report on stderr instead of the compact block message. The fallow binary does not read it. | |
FALLOW_GATE_MIN_VERSION | 2.85.0 | Agent gate script of fallow agent install: lowest fallow version that the gate accepts. Set it to the empty string to disable the check. The fallow binary does not read it. |
FALLOW_GATE_DEBUG | Agent gate script of fallow agent install: set to a non-empty value to log each command that the gate skips because it is not a git commit or push. The fallow binary does not read it. | |
FALLOW_GATE_STRICT | Agent gate script of fallow agent install: set to 1 to block a git commit or push when the gate cannot run the audit, for example when it finds no fallow binary. The values 0, false, no and off keep the fail-open default. A non-empty value overrides the strict mode that fallow agent install --strict wrote into the gate script. The fallow binary does not read it. |