MoonshotAI / MoonshotAI/kimi-code

feat(hooks): proposal — context field in hook JSON output (model-visible, terminal-hidden)

Open
#3,536 0 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

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)

  • context added to the output schema and HookResult in both the agent-core and agent-core-v2 hook pipelines
  • renderers split the model-facing text from the display message
  • 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.