MoonshotAI / MoonshotAI/kimi-code

Hooks: SessionStart output is discarded + no compact source — plugins have no silent post-compaction context channel

Open
#1,896 2 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

Two related gaps in the hook system prevent plugins from maintaining session
continuity. This affects any plugin that contributes model context —
memory/session-state tools, project-context injectors, or
Claude-Code-compatible hook packs — not one specific plugin.

  1. SessionStart hook output goes nowhere. triggerSessionStart awaits the
    hook results and then ignores them
    (packages/agent-core/src/session/index.ts). Combined with
    HookSpecificOutputSchema only parsing message, permissionDecision,
    and permissionDecisionReason (session/hooks/runner.ts), a SessionStart
    hook has no way to contribute context at all.

  2. Nothing context-capable fires after compaction. SessionStart only
    supports startup | resume, and PostCompact is fired via
    fireAndForgetTrigger with its output discarded
    (agent/compaction/full.ts). A plugin that wants to restore session state
    after /compact must piggyback on the next UserPromptSubmit — one
    message late, and always visible in the TUI, because
    renderUserPromptHookResult sends the same text to the context and the
    display (see also #897).

Comparison with Claude Code

Claude Code covers both cases: hookSpecificOutput.additionalContext is
injected into the model context silently (visible to the AI, hidden from the
TUI), and SessionStart fires with source: "compact" right after
compaction. Plugins built for that ecosystem cannot offer equivalent
behavior on Kimi Code today.

Proposal

Either or both, both additive (existing hooks unaffected):

  1. Fire SessionStart with source: "compact" after
    context.applyCompaction() in full.ts, and route SessionStart hook
    output into the rebuilt context. The platform already has an internal
    post-compaction injection mechanism (agent.injection.injectGoal()), so
    the plumbing partly exists.
  2. Support hookSpecificOutput.additionalContext as a silent injection
    channel (AI-visible, TUI-hidden) for all hook events — this would also
    resolve #897.

Source references

  • packages/agent-core/src/session/index.tstriggerSessionStart(source: 'startup' | 'resume'), results unused
  • packages/agent-core/src/session/hooks/runner.tsHookSpecificOutputSchema
  • packages/agent-core/src/session/hooks/user-prompt.tsrenderUserPromptHookResult
  • packages/agent-core/src/agent/compaction/full.tstriggerPostCompactHook via fireAndForgetTrigger

Related: #897 (hide UserPromptSubmit hook output from TUI), #447 (session
lifecycle hooks).

Happy to send a PR with whichever option you prefer.

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

Start by reading triggerSessionStart in packages/agent-core/src/session/index.ts, HookSpecificOutputSchema in session/hooks/runner.ts, renderUserPromptHookResult in session/hooks/user-prompt.ts, and triggerPostCompactHook in agent/compaction/full.ts. Trace how compaction context is rebuilt and how hook output reaches the model and TUI. Done means an agreed additive approach provides post-compaction or additionalContext delivery without breaking existing hooks.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.