Repository navigation
Description
Summary
pi-code executes Claude Stop hooks synchronously even when the hook is configured with "asyncRewake": true (or "async": true). Claude Code runs such hooks in the background; pi-code awaits them. A long-running background-style hook therefore holds pi's turn open for the hook's full duration — with a multi-hour timeout, the session appears frozen and subsequent user input stays queued.
Background: the Claude Code contract
Claude Code's hooks documentation (https://code.claude.com/docs/en/hooks) defines two fields on type: "command" hooks:
"async": true— "run the hook in the background without blocking Claude"."asyncRewake": true— "runs in the background and wakes Claude on exit code 2. The hook's stderr … is shown to Claude as a system reminder so it can react to a long-running background failure".
Tools in the wild rely on this: they register Stop hooks with asyncRewake: true and a deliberately long timeout (e.g. 28,800s) to run background monitoring that occasionally wakes the model via exit 2.
What pi-code does instead
In extensions/hooks/index.ts, the agent_end handler gathers matching Stop commands and awaits them all:
const run = boundRunner(ctx)
const results = await Promise.all(commands.map((command) => run(command, payload, timeoutMs(command))))Neither async nor asyncRewake appears anywhere in the hook command handling — the fields are silently ignored and every hook runs blocking. Verified in 1.0.11 and 1.0.14.
Observed impact
Real freeze observed 2026-08-30 with pi + pi-code 1.0.11 in a project whose .claude/settings.json registers a Stop hook with asyncRewake: true and timeout: 28800:
- pi finishes a visible response.
pi-coderuns the Stop hook and awaits it; the hook runs its long-lived monitoring loop in the foreground, as it is entitled to under the documented async contract.- pi never settles the turn. Anything typed afterward stays queued for hours. To the user the session is simply dead.
Confirmed via the live process tree: the pi process was blocked waiting on the hook script; killing the script immediately released the session.
Why this is worth fixing rather than documenting away
The README documents the hooks integration in close detail and calls out its deliberate divergences from Claude explicitly (timeout defaults, events that never fire, etc.). The async fields are not among the documented gaps, so users have no way to predict this — the same settings file that behaves correctly under Claude Code hard-freezes a pi session.
Suggested resolution (either is fine)
- Implement the documented semantics: fire-and-forget hooks marked
async/asyncRewakeinstead of awaiting them (forasyncRewake, ideally also honor the exit-2 wake, but simply not blocking the turn is the critical part); or - Explicitly reject/skip hooks carrying these fields with a visible warning ("async hooks are not supported"), so the failure is loud instead of an indefinite silent freeze.
Versions
- pi-code 1.0.11 (observed live) and 1.0.14 (code inspected, same behavior)
- Claude Code 2.1.238 for the reference behavior (
asyncRewakepresent in the settings schema and documented at the link above)
Activity
ilovepixelart commentedon Sep 1, 2026
@nightskytech thanks for the issue creation will assign pr soon to it