[Bug] Claude ignores persistent user rules for build process restrictions

Status Fixed / completed
Reported on v2.1.150
Maintainer reply None cached
Activity 3 comments · opened May 25, 2026 · closed May 26, 2026

Bug Description
I've had a rule in place for at least a month that claude can never run any build processes for the software project I'm working on. Over this long weekend claude has attempted to run a cmake on the code three times even though the rule is in memory. This causes me to have to deny the attempt and reiterate the rule. Burns tokens unnecessarily for no good reason.

Environment Info

  • Platform: linux
  • Terminal: vte-based
  • Version: 2.1.150
  • Feedback ID: 7388a9b1-7d6d-43ed-ae27-c8d744c7100c

Errors

[]

View original on GitHub ↗

3 Comments

giruuuuj · 4 months ago

Your analysis is spot-on. The root problem is that memory rules are soft instructions, not hard constraints. The model can under-weight or overlook them during tool planning.

The fix already exists — use PreToolUse hooks

Claude Code's hook system provides exactly the enforcement boundary you're describing. A PreToolUse hook for the Bash tool can:

  1. Intercept every bash command before execution
  2. Match it against blocked patterns (cmake, make, npm build, etc.)
  3. Exit code 2 → block the tool call entirely and explain why

This turns a soft memory rule into a hard execution guardrail — enforced at the tool layer, not dependent on model reasoning.

I've created a ready-to-use hook example that does this:

  • Blocks build-system commands (cmake, make, ninja, gradle, npm run build, etc.)
  • Allows non-build commands to pass through normally
  • Shows a clear message explaining why the command was blocked

You can use it by adding to your hooks config:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "python3 /path/to/block_build_commands_hook.py"
          }
        ]
      }
    ]
  }
}

See the existing example at examples/hooks/bash_command_validator_example.py and the new block-build-commands example in PR #62264 for reference.

BiloxiGeek · 4 months ago

Got it working, thanks. Also added a bit to the output so claude not only says it's blocked from running the command but it outputs exactly what it attempted to run. Allows for an easy user copy/paste to run the command themselves.

The bit I added is in the 62264 conversation

github-actions[bot] · 2 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.