Repository navigation
Return a blocked PreToolUse reason to the model instead of ending the run - #411
Merged
Merged
Conversation
… run blockedToolCall set pi's terminate flag on every PreToolUse block, so a block on the only call in a batch skipped the follow-up model call and ended the run. A headless run (-p, --mode json) exited 0 with no final answer and nothing on stderr. Claude shows a deny's reason to the model, which keeps working; an exit-2 block routes the same way. A deny, decision block, exit 2, fail-closed timeout and headless ask now block without terminate, so the model reads the reason and continues. terminate stays on a block that also carries continue: false (otherwise pi starts the next model request before the abort lands), on defer (Claude ends the turn) and on an ask the user declines in the dialog. Combining PreToolUse hooks follows Claude's deny > defer > ask > allow precedence; a defer previously won over a deny listed after it. Closes #410
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A blocked PreToolUse call now returns the hook's reason to the model and the run continues, matching Claude's deny semantics. Only
continue: false,deferand a declined ask dialog still end the run (extensions/hooks/decisions.ts,extensions/hooks/index.ts).Headless runs ended at the first block
decision: "block", exit 2, fail-closed timeout or headless ask no longer ends the run (blockedToolCall). Every block set pi'sterminateflag. When the blocked call was the only one in its batch, pi skipped the follow-up model call.pi --mode json -pwith a Bash hook that exits 2 then emittedtool_execution_end,turn_end,agent_end: one assistant message withstopReason: "toolUse", no final text, exit 0, empty stderr. The block now carries noterminate. The model receives the reason as the tool error and answers in a second assistant message. Behavior change: interactive sessions also continue after a block instead of waiting for the user, as Claude does.terminatestays where the run is meant to end. Withcontinue: falsebeside the block, it prevents pi from starting a model request that the pending abort would cancel (stopReason: "error", "This operation was aborted"). Withdefer, it follows Claude's "ends the turn". With an ask declined in the dialog, the user is present to direct what happens next.Hook precedence
combinePreToolDecisions). The first non-ask block in config order won, so a defer listed before a deny returned the defer verdict. Precedence is now Claude's deny > defer > ask > allow.docs/hooks.mdstates what happens after a block, and that pi ends the run only when every call in the batch agrees.Closes #410
npm run checkpasses (Biome, strict tsc, Vitest)