An engineering enablement team at Northbank gives its legacy-migration agent the Bash tool so it can run build and test commands inside a scratch checkout. To stop the agent running commands that write outside that checkout, an engineer writes a hook that inspects the command string and returns a blocking response when a target path lies outside the checkout, and registers it as a PostToolUse hook matching Bash. During a rehearsal the agent issues a command that writes a file outside the checkout. What will happen?
- AThe command is intercepted before the shell starts and the agent receives a denial, because a hook matching Bash is consulted ahead of execution whichever event it is registered on.
- BThe command runs and the hook cannot evaluate it, because a PostToolUse hook receives the tool name and the result rather than the arguments that were submitted.
- CThe command runs and the harness reverts it, because a hook that rejects a tool result causes the runtime to undo the work that produced that result before continuing.
- DThe command runs and writes the file, and the hook's blocking response only shapes what the agent is told afterwards, so the side effect has already taken place on disk. Correct
Why A is wrong: Tempting because the matcher genuinely does select the Bash tool and the hook logic is written as a gate. It is wrong because the event, not the matcher, decides when the hook runs, and PostToolUse runs after execution.
Why B is wrong: Tempting because it sounds like a reasonable privacy boundary between events. It is wrong because the hook does see the call details, so it evaluates the command correctly and still cannot undo the write.
Why C is wrong: Tempting because transactional rollback is a familiar guarantee elsewhere in engineering. It is wrong because the harness has no general mechanism to undo arbitrary shell side effects, and no such rollback exists.
Why D is correct: Correct because PostToolUse fires after the tool has executed, so a blocking response there can influence the agent's next step but cannot prevent an effect that has already occurred.