MoonshotAI / MoonshotAI/kimi-code
SessionStart hook stdout is silently discarded — hook output is never displayed in the TUI
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Summary
SessionStart hook commands execute, but their stdout is silently discarded — the hook output is never rendered in the TUI or appended to the conversation context. Users configuring a SessionStart hook (e.g. to print a startup message or inject session-start instructions) see nothing, despite the hook actually running.
Expected behavior
Per the hooks documentation (Return Values section):
0— Normal exit, allow: Continue execution; stdout content (if any) may be appended to context
So for any hook (including observation-only events like SessionStart), stdout should be surfaced to the user — at minimum rendered in the TUI transcript, similar to how UserPromptSubmit hook results appear as UserPromptSubmit hook entries.
Actual behavior
The SessionStart hook runs (its side effects, e.g. writing a file, are visible), but its stdout goes nowhere:
- No
hook.resultevent is emitted, so the TUI never renders a transcript entry. - No context append happens, so the model never sees the output either.
- The returned
HookResult[]from the trigger is simply dropped.
Steps to reproduce
# ~/.kimi-code/config.toml
[[hooks]]
event = "SessionStart"
command = "echo 'hello from SessionStart hook' && echo HOOK_RAN >> /tmp/hook-marker.log"
- Start a new
kimisession (or resume one). - Observe that
/tmp/hook-marker.loggets written — the hook did run. - The string
hello from SessionStart hookappears nowhere: not in the TUI transcript, not in the model context (checkable viakimi -p+ inspectingwire.jsonl— nocontext.append_messageentry for it).
Tested on kimi-code 0.35.0 (macOS).
Root cause
The session-scope external hooks service fires SessionStart fire-and-forget and discards the result:
packages/agent-core-v2/src/session/externalHooks/externalHooksService.ts:137-149—triggerSessionStart()callsawait this.runner.trigger('SessionStart', …)and ignores the returnedHookResult[](nohook.resultevent, no context append, nothing).
Meanwhile, hook.result events — the only thing the TUI renders as a hook transcript entry (apps/kimi-code/src/tui/controllers/session-event-handler.ts → handleHookResult) — are only published by the agent-scope UserPromptSubmit handler:
packages/agent-core-v2/src/agent/externalHooks/externalHooksService.ts:353-397—runPromptSubmitHook()is the only path that appends hook stdout to the context and publishestype: 'hook.result'.
So observation-only events (SessionStart, SessionEnd, SubagentStart, PreCompact, Notification, …) currently have no output-surfacing path at all.
Suggested fix
Publish hook.result (and optionally append stdout to context) for observation-only events too, mirroring the UserPromptSubmit path in runPromptSubmitHook:
- Emit
hook.resultwith the hook stdout for events such asSessionStart/SessionEndso the TUI renders them as transcript entries. - Or append stdout to the context for observation events (possibly gated behind an opt-in config field to avoid context pollution for noisy hooks).
Workaround
Until this is fixed, the same effect can be achieved with a UserPromptSubmit hook guarded by a per-session_id state file so it only emits on the session's first prompt — UserPromptSubmit is currently the only event whose stdout is actually surfaced.
Environment
- kimi-code CLI version: 0.35.0 (
kimi --version) - OS: macOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the SessionStart configuration, then read packages/agent-core-v2/src/session/externalHooks/externalHooksService.ts:137-149 and compare it with runPromptSubmitHook in packages/agent-core-v2/src/agent/externalHooks/externalHooksService.ts:353-397. Check how apps/kimi-code/src/tui/controllers/session-event-handler.ts handles hook.result. Done means SessionStart stdout is surfaced through the intended event or context path and appears in the TUI or model context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100