Skip to content

PreToolUse hook stdout is not appended to context (0.29.0) #2107

Open

Description

@seasonmsg

PreToolUse hook stdout is not appended to context (0.29.0)

Summary

On 0.29.0, a PreToolUse hook that exits 0 with text on stdout runs successfully (side effects observable), but its stdout never reaches the model context. The documented behavior — "stdout content (if any) may be appended to context" — does not hold for PreToolUse, while the same mechanism works for UserPromptSubmit in the same session.

This blocks a class of safety hooks that want to attach a warning/reminder to specific tool calls (e.g., marking web content as untrusted right before a FetchURL call).

Expected behavior (docs)

https://www.kimi.com/code/docs/en/kimi-code-cli/customization/hooks.html — Return Values: exit code 0 = "Normal exit, allow; stdout content (if any) may be appended to context".

Actual behavior

  • The hook executes: a file-written side effect (taint marker) is produced with correct session/tool data.
  • The hook prints the reminder to stdout before exit 0 (verified by running the same script manually with the same stdin payload — stdout present).
  • The reminder text never appears in the session wire (agents/main/wire.jsonl grep = 0 hits), and the model shows no awareness of it.
  • In the same session, a UserPromptSubmit hook's stdout is injected as a <hook_result hook_event="UserPromptSubmit"> user message (present in wire).

Observed in headless (kimi -p) sessions; #2070 makes interactive-window verification impossible for us at the moment, so headless is our authoritative channel.

Reproduction

  1. ~/.kimi-code/config.toml:
[[hooks]]
event = "PreToolUse"
matcher = "FetchURL|WebSearch"
command = "node /path/to/remind.mjs"
timeout = 5
  1. remind.mjs: reads stdin payload; if tool_name is FetchURL/WebSearch, writes a marker file to disk, then console.log("UNTRUSTED-CONTENT-MARKER") and process.exit(0).

  2. New headless session: kimi -p "FetchURL https://example.com and tell me the title".

  3. Results:

    • Marker file exists → hook executed with correct payload.
    • agents/main/wire.jsonl contains zero occurrences of UNTRUSTED-CONTENT-MARKER.
    • Control: a UserPromptSubmit hook with identical stdout approach does appear in wire as a hook_result user message.

Environment

  • kimi-code 0.29.0 (Windows 10, Git Bash)
  • Config has 4 hooks total (2×UserPromptSubmit, 1×PreToolUse matcher=FetchURL|WebSearch, 1×PreToolUse matcher=Bash); all fire correctly as far as execution is concerned — only PreToolUse stdout delivery is absent.

Ask

  • Confirm whether PreToolUse stdout delivery is unimplemented, gated, or a bug.
  • If unimplemented: please consider it — safety hooks that annotate untrusted tool results (web pages, search snippets) before the model sees them are a key defense layer against indirect prompt injection, and currently only UserPromptSubmit (wrong timing) can deliver text into context.

Activity

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