{
  "id": 14915735,
  "title": "A bug in my own branch-guard hook, caught by typing one extra space",
  "url": "https://urgent.news/2026/10/16/a-bug-in-my-own-branch-guard-hook-caught-by-typing-one-extra-space",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-16T09:03:34.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/98dkcc488bglitch/a-bug-in-my-own-branch-guard-hook-caught-by-typing-one-extra-space-5b8l"
  },
  "original_language": "en",
  "account": "A bug in the branch-guard hook of Claude Code was discovered by an engineer who accidentally typed an extra space in a test case. The hook, block-wrong-branch.sh, checks the git push command and compares the target branch against a policy file. However, when the engineer fed a command with extra whitespace to the hook, it reported an incorrect branch name instead of blocking the push. This happened because the shell parameter expansion and word-splitting operations do not collapse extra whitespace, unlike the read command. The engineer fixed the issue by normalizing runs of whitespace in the command string before processing. The fix also included adding a regression test to ensure the correct branch name is reported when a bad push attempt occurs. The engineer emphasized the importance of accurate error messages and thorough testing for hook scripts used with LLMs, as vague or incorrect feedback can mislead the AI model in subsequent interactions.",
  "summary": "A bug in my own branch-guard hook, caught by typing one extra space Context: Last week I shipped a set of 4 Claude Code hooks that catch common agent mistakes — no-op edits, pushes to the wrong branch, out-of-scope writes, and unverified claims at the end of a turn. I wrote about them in article #1 and the testing in #2 . This piece is the small, embarrassing follow-up: a bug I found by…",
  "key_points": [
    "Engineer found bug by typing extra space in test case",
    "Block-wrong-branch.sh hook incorrectly reported branch name",
    "Fix added whitespace normalization and regression test"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}