MoonshotAI / MoonshotAI/kimi-code

SessionStart hook stdout is silently discarded — hook output is never displayed in the TUI

Open
#2,873 0 comments 0 reactions 0 assignees View on GitHub

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.result event 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"
  1. Start a new kimi session (or resume one).
  2. Observe that /tmp/hook-marker.log gets written — the hook did run.
  3. The string hello from SessionStart hook appears nowhere: not in the TUI transcript, not in the model context (checkable via kimi -p + inspecting wire.jsonl — no context.append_message entry 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-149triggerSessionStart() calls await this.runner.trigger('SessionStart', …) and ignores the returned HookResult[] (no hook.result event, 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.tshandleHookResult) — are only published by the agent-scope UserPromptSubmit handler:

  • packages/agent-core-v2/src/agent/externalHooks/externalHooksService.ts:353-397runPromptSubmitHook() is the only path that appends hook stdout to the context and publishes type: '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.result with the hook stdout for events such as SessionStart/SessionEnd so 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.