Skip to content

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

Description

@Digentra

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 Suggestion: option to hide UserPromptSubmit hook output from TUI #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 Suggestion: option to hide UserPromptSubmit hook output from TUI #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions