Windows: PostToolUse hooks fail with exit code 1
Bug
On Windows (nightly desktop app), PostToolUse hook (failed): error: hook exited with code 1 appears on every tool-use callback. The activity feed goes dead and the agent gets interrupted.
Reported by @somewherelostt (Maaz), project orydle, Codex worker sessions.
Analysis
Key finding: runHook cannot exit non-zero by design
The hidden ao hooks <agent> <event> command routes through runHook() in backend/internal/cli/hooks.go (line 132). Every code path in runHook returns nil — missing AO_SESSION_ID, stdin read errors, unknown events, and daemon POST failures are all swallowed via reportHookFailure() (which logs to ~/.ao/hooks.log and exits 0):
func (c *commandContext) runHook(ctx context.Context, agent, event string) error {
sessionID := strings.TrimSpace(os.Getenv("AO_SESSION_ID"))
if !sessionIDPattern.MatchString(sessionID) {
return nil // exit 0
}
// ... read stdin, derive state, POST to daemon ...
// ALL error paths call reportHookFailure() and fall through to:
return nil // exit 0
}
This means exit code 1 is not coming from inside runHook — it's happening before the Go hook logic runs or the wrong ao binary is resolving.
PostToolUse is a Claude Code hook, not Codex
The Codex adapter (backend/internal/adapters/agent/codex/hooks.go line 69-74) deliberately installs only: SessionStart, UserPromptSubmit, PermissionRequest, Stop. There is no PostToolUse. This is a documented design choice (activity.go line 17-19):
// codex installs no pre/post-tool-use hooks, so a blocked state
// could never be cleared before the turn ends.
The PostToolUse hook (failed) errors in the screenshot are from the orchestrator session (which runs Claude Code), not the Codex workers. Claude Code installs the full tool-use trio (claudecode/hooks.go line 40-42).
Most likely root cause: wrong ao binary resolving on Windows
The hook command installed in .claude/settings.local.json is a bare string: ao hooks claude-code post-tool-use. HookPATH() (session_manager/manager.go line 2285) is supposed to pin the daemon's directory first on PATH so this resolves to the Go daemon binary (ao.exe). But if the pin fails or a stale npm ao.cmd shim is earlier on PATH, the hook command resolves to the frozen 0.10.0 TS CLI which may not handle hooks correctly.
The same session shows ao session get orydle-2 --json working (green dots) — this works because both old and new CLIs support session get, but only the Go rewrite has the current hooks <agent> <event> dispatch.
Diagnostic steps needed from reporter
-
Which
aoresolves?where.exe ao where.exe ao.cmdIf
%APPDATA%\npm\ao.cmdappears before the daemon directory, that's the conflict. -
Check the hook failure log:
type "%USERPROFILE%\.ao\hooks.log"If this file has entries, the Go binary IS running and the daemon POST is failing. If empty/missing, the Go binary never ran.
-
Run the hook manually:
$env:AO_SESSION_ID = "test-session" echo '{"tool_name":"Bash"}' | ao hooks claude-code post-tool-use echo $LASTEXITCODEExit 0 = Go binary works; non-0 = wrong binary or config issue.
-
Check daemon data dir:
echo $env:AO_DATA_DIRIf unset,
config.Load()defaults to~/.ao.
Possible fixes (pending diagnostics)
- If npm shim conflict: document uninstalling the npm CLI, or make
HookPATHmore aggressive on Windows (strip npm shims). - If binary not found: install hooks with explicit path or
.exesuffix on Windows. - If daemon POST failing: the 2-minute
commandTimeoutindoJSONPath(client.goline 133) exceeds Codex's 5s hook timeout — consider a shorter timeout for hook POSTs specifically.
Environment
- OS: Windows
- Build: nightly
- Agent: Codex workers + Claude Code orchestrator
- Project: orydle
Thanks for contributing to Agent Orchestrator.
This issue is being picked up by the current external contributor on-call pair:
- @illegalcall
- @pulkit7070
If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @illegalcall and @pulkit7070 here.
For faster context or live questions, you can also join the AO Discord.
Join the session here: https://discord.gg/H6ZDcUXmq
Come by if you want to see what is being built, ask questions, or just hang around with the community.
Closing as fixed on current main by #4629. Windows Codex hooks now invoke the quoted AO executable with PowerShell’s call operator, so PostToolUse and the other hook callbacks no longer fail at command parsing with exit code 1.