You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
kimi -p exits before a blocking Stop hook finishes in 2.6.3 #5032
On Kimi Code 2.6.3, kimi -p exits with status 0 after the first model response, before a configured Stop hook finishes. The same hook completes on 2.5.3 and its exit status 2 triggers a second model request.
Reproduced on macOS arm64 with a local OpenAI-compatible test endpoint.
Minimal reproduction
Save this as stop.sh in a writable directory. The one-second delay makes it easy to see whether the CLI waits. The marker makes the hook request continuation only once.
#!/bin/sh
marker="$(dirname "$0")/stop-ran"if [ -f"$marker" ];thenexit 0
fi
sleep 1
:>"$marker"printf'%s\n''Reply with SECOND and no tools.'>&2exit 2
Add the hook to ~/.kimi-code/config.toml alongside a working model configuration.
Still reproduces on 2.7.2, and main has the same code. A Stop hook that only observes, without blocking, loses the event the same way. In our CI's headless kimi -p runs on macOS runners, the Stop hook never ran in 5 of 29 runs since 2.7.2. On 2.5.3 it was 0 of 45.
notifyTurnEnded queues runStop on stopHookQueue after the turn has ended (packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts:429-433).
Print mode's cleanup waits only for the agent loops to settle (quiesceSessionAgents). It then flushes and calls client.close() (apps/kimi-code/src/cli/v2/run-v2-print.ts:177-189), which disposes the agent.
The service's dispose aborts stopHookAbortController (agentExternalHooksService.ts:92-99), and runHook kills the hook process on that abort (packages/agent-core-v2/src/features/externalHooks/internal/runHook.ts:120-123).
So whether Stop runs depends on whether the hook finishes before client.close(). One possible fix is for print mode to await the queued Stop hooks (stopHookQueue) before it disposes the agent, for example as part of quiescing.
Activity
IvanWng97 commentedon Nov 22, 2026
Still reproduces on 2.7.2, and
mainhas the same code. A Stop hook that only observes, without blocking, loses the event the same way. In our CI's headlesskimi -pruns on macOS runners, the Stop hook never ran in 5 of 29 runs since 2.7.2. On 2.5.3 it was 0 of 45.The race, at
@moonshot-ai/[email protected]:notifyTurnEndedqueuesrunStoponstopHookQueueafter the turn has ended (packages/agent-core-v2/src/features/externalHooks/agent/agentExternalHooksService.ts:429-433).cleanupwaits only for the agent loops to settle (quiesceSessionAgents). It then flushes and callsclient.close()(apps/kimi-code/src/cli/v2/run-v2-print.ts:177-189), which disposes the agent.stopHookAbortController(agentExternalHooksService.ts:92-99), andrunHookkills the hook process on that abort (packages/agent-core-v2/src/features/externalHooks/internal/runHook.ts:120-123).So whether Stop runs depends on whether the hook finishes before
client.close(). One possible fix is for print mode to await the queued Stop hooks (stopHookQueue) before it disposes the agent, for example as part of quiescing.