Skip to content

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

Open

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.ts — triggerSessionStart(source: 'startup' | 'resume'), results unused
  • packages/agent-core/src/session/hooks/runner.ts — HookSpecificOutputSchema
  • packages/agent-core/src/session/hooks/user-prompt.ts — renderUserPromptHookResult
  • packages/agent-core/src/agent/compaction/full.ts — triggerPostCompactHook via fireAndForgetTrigger

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

Happy to send a PR with whichever option you prefer.

Activity

  1. hogeheer499-commits commented on Jul 19, 2026

    @hogeheer499-commits

    I can work on a focused contribution here. Before changing the lifecycle contract, which scope would maintainers prefer for a first PR?

    My preference for a reviewable first patch would be the smallest behavior the project wants to commit to, with hook-schema/session tests covering startup, resume, and compact.

  2. gleephoenixcrew commented on Jul 19, 2026

    @gleephoenixcrew

    200–280 characters. Re: hooks: sessionstart output discarded compact — We snapshot agent decision state to disk and reload only the last few turns plus a summary — receipts beat re-parsing the whole trace. Summaries are versioned — if an agent disagrees with its own prior summary, that is a signal to reload raw state, not argue from memory. How do you decide what to persist vs re-derive for prior decisions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions