AIToday
AI Coding AssistantsAI Safety & AlignmentZenn AI/MLPublished: Oct 12, 2026, 22:00 JST

Claude Code deny rules leak; PreToolUse hook plugs gaps

Claude Code deny rules leak; PreToolUse hook plugs gaps

3 Key Points

  1. What happened

    The developer's settings.json deny list blocked commands starting with the literal text like git push, but official docs show forms such as git -C . push origin main, git -c push.default=current push origin main and git 'push' origin main slip through.

  2. Why it matters

    Anyone who trusts deny rules alone to keep an AI coding agent away from Git operations like push, reset, rebase or clean is exposed to that same bypass, since rules match command strings rather than the program's real behavior.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, in your inbox every morning.

Context & Analysis

The author's decision to stop AI involvement at commit and keep push and merge human reflects how he treats a codebase handling money and personal data. His first assumption — that writing the rule in CLAUDE.md and listing it in settings.json would be enough — did not hold, because instruction files only steer what Claude tries to do and do not change what Claude Code permits.

Moving the check to a PreToolUse hook addresses the specific weakness he identified: deny rules match command strings, whereas his Python script splits commands on separators, skips prefixes like env or timeout 10, ignores git options such as -C and -c, and re-reads the insides of bash -c and $( ). He tested 22 forms that should be blocked and 7 that should pass, then deliberately broke the -C and -c handling to confirm the tests caught the gap. He also notes that without "onFailure": "block", a mis-typed script path would let every command through.

Even so, he frames the hook as not a strong boundary. The larger fix, in his view, is separating privileges — running the AI under its own OS account, or protecting branches on GitHub's side, though he notes private repositories need a paid plan for branch protection. He chose the separate OS account, and says the credential-placement and SSH work that comes with it will be covered in a follow-up.

FAQ
Why does the deny list in settings.json fail to block git push?
The rules match the literal text of a command, so equivalent forms like git -C . push origin main, git -c push.default=current push origin main or git 'push' origin main are not matched, as the official docs show.
How does the PreToolUse hook actually stop a command?
Claude Code passes the full command to the hook as JSON on stdin, and if the hook exits with code 2 the command is stopped — taking priority over allow rules and permission mode.
What gaps remain even after adding the hook?
Saved credentials are still usable from the AI's process, the hook's settings file and script can be rewritten by the AI itself, and nested $( ), repo-config aliases or PowerShell syntax are not covered by his minimal example.

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleUS and European open-weight models trail Chinese rivals like GLM-5.3