Skip to content

Block agent commands that skip git hooks - #55

Merged
andrewthomaslee merged 1 commit into
mainfrom
git-hook-guard
Nov 26, 2026
Merged

andrewthomaslee merged 1 commit into
mainfrom
git-hook-guard

Conversation

@andrewthomaslee

Copy link
Copy Markdown
Member

What

  • flake-parts/homeModules/agents/_git-hook-guard.nix (new): agent-git-hook-guard, a Python script. It's a claude-code PreToolUse hook on Bash, and it exits 2, which blocks the tool call, when a git command skips the hooks:

    • --no-verify on any subcommand
    • git commit -n, also inside a short-option cluster like -anm
    • core.hooksPath set through git -c or git config
    • PREK_ALLOW_NO_CONFIG or SKIP set on a git command

    It checks every part of a compound command, and inside sh -c / bash -c. It parses the command with shlex, so text that only mentions a flag (a commit message, echo, grep) isn't blocked.

  • agents.nix: new option homeSpec.agents.gitHookGuard.enable (default true). When on, it adds the hook to ~/.claude/settings.json (hooks.PreToolUse).

  • tests/flake-module.nix:

    • new checks.agents-git-hook-guard: 13 blocked and 9 allowed commands, plus non-JSON input
    • agents-wiring now asserts the PreToolUse hook is present.
  • README.md: documents the option.

  • Bumps skills (the new ground rule, Git hooks in the org standard; never skip them skills#25) and org-pkgs (git hooks, Add git hooks to the org devenv shell pkgs#45) with sync-locks.

  • Opts modules in to the org git hooks: devenv.yaml follows org-pkgs/git-hooks, and .pre-commit-config.yaml is gitignored.

Why

The ground rules now say agents never skip git hooks. This makes it hold for claude. The owner can still skip a hook from their own shell, or with claude's ! prefix, which runs outside the agent's tool calls.

Only claude gets the guard for now. pi, kimi and opencode would each need their own hook format; that can be a follow-up.

Checks

  • fmt: clean. check: all checks passed, incl. the new agents-git-hook-guard. One existing non-fatal eval warning (stdenv.isDarwin deprecated).
  • Block message, checked by hand: Blocked: this git command uses git commit -n, which skips the git hooks. … If a skip is really needed, ask the owner to run the command. (exit 2)
  • This commit went through the new fmt git hook (Passed).

Merge order

pkgs#45 and skills#25 (both merged), then this, then home (bumps modules, skills and org-pkgs, opts in, adds the clan vars check pre-push hook). Reaches machines only after a deploy from home.

🤖 Generated with Claude Code

homeSpec.agents.gitHookGuard (on by default) adds a claude-code
PreToolUse hook on Bash that blocks git commands skipping the git hooks:
--no-verify, git commit -n, core.hooksPath, PREK_ALLOW_NO_CONFIG or SKIP.
The org shell's hooks (external-systems/pkgs#45) are part of the gate and
the ground rules (external-systems/skills#25) say never to skip them;
this enforces it for the agent. The command is parsed with shlex, so a
commit message that mentions a flag is not a false hit.

Bumps skills (the new ground rule) and org-pkgs (git hooks, sync-locks),
and opts this repo in to the org git hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee
andrewthomaslee enabled auto-merge (squash) November 26, 2026 11:24
@andrewthomaslee
andrewthomaslee merged commit dd52b66 into main Nov 26, 2026
3 checks passed
andrewthomaslee added a commit to external-systems/home that referenced this pull request Nov 26, 2026
## What
- `devenv.yaml`: follows `org-pkgs/git-hooks`, which opts home in to the
org shell's git hooks (external-systems/pkgs#45).
- `.gitignore`: `.pre-commit-config.yaml` (the shell writes it as a link
into the nix store).
- `devenv.nix`: a `pre-push` hook, `clan vars check`, on top of the org
`fmt` pre-commit hook. It uses the real clan binary (no key, no
1Password prompt) through an absolute path, so it also works from a
plain shell outside devenv.
- `flake.lock` / `devenv.lock`: bumps `org-pkgs` (with `sync-locks`) and
`modules`. That brings in the skills ground rule
(external-systems/skills#25) and the claude git hook guard
(external-systems/modules#55).
- `AGENTS.md`, `documentation/docs/machines/index.md`: say where `clan
vars check` runs now (`check`, pre-push) and the worktree note.

## Why
CI's `checks.clan-vars-present` only checks that the vars files exist.
`clan vars check` also validates hashes and recipients, but until now it
only ran if someone ran `check` by hand. Now every push runs it.

## Checks
- `fmt`: clean. `check`: all checks passed; `clan vars check` passed for
all 6 machines.
- This commit went through `fmt` on pre-commit (Passed), and the push
went through `clan vars check` on pre-push (Passed, about 2.7s for the
whole push).
- I re-ran the pre-push hook with an empty environment (no `DEVENV_*`
variables, only HOME and the system PATH): Passed. So an agent pushing
from a plain shell gets the check, and the private `secrets` input
resolves.

## Reviewer notes
- **No machine change on merge.** The modules bump changes the netsa and
matt home-manager profiles (claude settings get the PreToolUse guard;
CLAUDE.md gets the new ground rule). Those only reach machines with a
deploy, which is the owner's call: `clan machines update <machine>` from
`main`.
- After merging, enter the shell once in the home clone, and in any
existing worktree, so each has its hook config.

## Merge order
pkgs#45, skills#25 and modules#55 (all merged), then **this** (last).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee
andrewthomaslee deleted the git-hook-guard branch November 29, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant