Skip to content

Return a blocked PreToolUse reason to the model instead of ending the run - #411

Merged
ilovepixelart merged 1 commit into
mainfrom
fix/continue-after-pretooluse-block
Oct 23, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
fix/continue-after-pretooluse-block

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

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, defer and a declined ask dialog still end the run (extensions/hooks/decisions.ts, extensions/hooks/index.ts).

Headless runs ended at the first block

  • A deny, decision: "block", exit 2, fail-closed timeout or headless ask no longer ends the run (blockedToolCall). Every block set pi's terminate flag. When the blocked call was the only one in its batch, pi skipped the follow-up model call. pi --mode json -p with a Bash hook that exits 2 then emitted tool_execution_end, turn_end, agent_end: one assistant message with stopReason: "toolUse", no final text, exit 0, empty stderr. The block now carries no terminate. 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.
  • terminate stays where the run is meant to end. With continue: false beside the block, it prevents pi from starting a model request that the pending abort would cancel (stopReason: "error", "This operation was aborted"). With defer, 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

  • A deny wins over a defer whatever the hook order (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.md states what happens after a block, and that pi ends the run only when every call in the batch agrees.

Closes #410

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

… 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
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 8255be8 into main Oct 23, 2026
13 checks passed
@ilovepixelart ilovepixelart mentioned this pull request Oct 23, 2026
2 tasks done
@ilovepixelart
ilovepixelart deleted the fix/continue-after-pretooluse-block branch November 4, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A blocked PreToolUse hook ends a headless run instead of returning the reason to the model

1 participant