MoonshotAI / MoonshotAI/kimi-code
feat(hooks): proposal — context field in hook JSON output (model-visible, terminal-hidden)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Problem
UserPromptSubmit hook output is injected into the conversation AND displayed in the terminal as one undifferentiated blob. Any hook that injects large dynamic context (project state, issue trackers, environment snapshots) floods the user's terminal with raw data on every prompt.
Concrete case: we inject a per-issue briefing (~6 KB: description, open todos, timeline entries, dependency file list) on every prompt. The model needs it; the user drowns in it. Today there is no way to say "this part is for the model only".
Proposal
Add an optional top-level context field to the hook JSON output:
{"message": "Issue #42 loaded.", "context": "...6KB of briefing data..."}
message— unchanged: injected into the conversation AND rendered in the terminal.context— appended to the model-facing prompt text (wrapped in<hook_result>like the rest), but excluded from the terminal display event.
Only UserPromptSubmit rendering is affected; blocking semantics (permissionDecision), plain-stdout hooks, and all other events are unchanged. The field is optional; existing hooks work as-is.
Implementation
A working implementation is ready on my fork: https://github.com/wubing-wx/kimi-code/tree/hook-context-field (based on v0.40.1)
contextadded to the output schema andHookResultin both theagent-coreandagent-core-v2hook pipelines- renderers split the model-facing
textfrom the displaymessage - tests added for both packages (JSON parsing + render split); both suites pass, typecheck clean
Happy to open the PR if you'd like this.
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 reviewing the hook pipelines in agent-core and agent-core-v2, then compare the working implementation on the linked fork with the proposal's rendering requirements. Run both package test suites and typecheck; done means context reaches the model but not the terminal for UserPromptSubmit, while existing behavior and other events remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100