Ray's Knowledge Base
Unlock

A PreToolUse hook's ask does not reach a person in every Claude Code mode, and the ! prefix skips the hook

FactVerified 29 Sep 2026Holds anywhere
Fact. A statement and the evidence for it.

Statement#

A PreToolUse hook that answers permissionDecision: "ask" is only a real gate in modes that show a prompt:

  • In headless claude -p, an ask becomes a failed tool call whose result is the hook's reason, in every mode including bypassPermissions; nobody is asked, and the command does not run.
  • Per Claude Code's docs, interactive bypassPermissions skips an ask and the command runs, and dontAsk denies it without a prompt. A hook's deny blocks in every mode.
  • The hook input has a permission_mode field, so a hook can answer deny (with the command for the user to run) where an ask would be skipped.
  • A command the user types with Claude Code's ! prefix does not go through PreToolUse hooks at all: even a hook that denies it cannot stop it.

Evidence#

2026-09-29, Claude Code 2.1.284, rkb's confirm gate (rkb hook pre-tool) on a scratch knowledge base with a pending rkb doctor --break-lock request. Headless claude -p --permission-mode <mode> asked to run rkb confirm <id> --choice "break lock": with the hook answering ask, the tool result in default, acceptEdits, auto and bypassPermissions was is_error: true with the hook's reason text, and the lock stayed; with the hook answering deny in bypassPermissions and dontAsk, the agent got the deny reason, and the lock stayed. Interactive claude --permission-mode bypassPermissions with the deny hook active: the user typed ! rkb confirm <id> --choice "break lock", no deny message appeared, and rkb printed Removed the lock …. Docs checked: code.claude.com/docs/en/permission-modes, /hooks.

Also found by searching

  • PreToolUse hook returned permissionDecision ask but the Bash command just failed in claude -p with the hook reason
  • my hook asks for confirmation but in bypassPermissions mode the command runs anyway without a prompt
  • how do I make a PreToolUse hook gate dangerous commands when running headless or with dontAsk mode
  • commands typed with ! bang prefix in claude code skip my permission hook entirely
  • PreToolUse hook permissionDecision ask in claude -p tool call failed is_error true, command did not run
  • my hook returns ask but with bypassPermissions the command just runs without prompting me
  • how do I make a Claude Code hook actually block a dangerous command in every permission mode?
  • user typed !command in claude code and my deny hook never fired, can I stop shell escape commands?