MoonshotAI / MoonshotAI/kimi-code
Hooks: SessionStart output is discarded + no compact source — plugins have no silent post-compaction context channel
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.
-
SessionStart hook output goes nowhere.
triggerSessionStartawaits the
hook results and then ignores them
(packages/agent-core/src/session/index.ts). Combined with
HookSpecificOutputSchemaonly parsingmessage,permissionDecision,
andpermissionDecisionReason(session/hooks/runner.ts), a SessionStart
hook has no way to contribute context at all. -
Nothing context-capable fires after compaction. SessionStart only
supportsstartup | resume, andPostCompactis fired via
fireAndForgetTriggerwith its output discarded
(agent/compaction/full.ts). A plugin that wants to restore session state
after/compactmust piggyback on the nextUserPromptSubmit— one
message late, and always visible in the TUI, because
renderUserPromptHookResultsends 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):
- Fire
SessionStartwithsource: "compact"after
context.applyCompaction()infull.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. - Support
hookSpecificOutput.additionalContextas 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.ts—triggerSessionStart(source: 'startup' | 'resume'), results unusedpackages/agent-core/src/session/hooks/runner.ts—HookSpecificOutputSchemapackages/agent-core/src/session/hooks/user-prompt.ts—renderUserPromptHookResultpackages/agent-core/src/agent/compaction/full.ts—triggerPostCompactHookviafireAndForgetTrigger
Related: #897 (hide UserPromptSubmit hook output from TUI), #447 (session
lifecycle hooks).
Happy to send a PR with whichever option you prefer.
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
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