Skip to content

feat: allow PreToolUse hooks to modify tool input via updatedInput#1963

Open
0xMashiro wants to merge 2 commits intoMoonshotAI:mainfrom
0xMashiro:feat/pretooluse-updated-input
Open

feat: allow PreToolUse hooks to modify tool input via updatedInput#1963
0xMashiro wants to merge 2 commits intoMoonshotAI:mainfrom
0xMashiro:feat/pretooluse-updated-input

Conversation

@0xMashiro
Copy link
Copy Markdown

@0xMashiro 0xMashiro commented Apr 21, 2026

Related Issue

N/A - no related issue. Add support for rtk - CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies.

Description

This PR allows PreToolUse hooks to modify tool arguments by returning updatedInput
in stdout, matching the hook format used by Claude Code-compatible tooling such as rtk.

Before this change, Kimi CLI PreToolUse hooks could allow or block a tool call, but
could not rewrite the tool input before execution. That made transparent command
rewriters ineffective: a hook could decide that a shell command should become
rtk git status, but the original git status arguments would still be executed.

The toolset now consumes updatedInput from allowed PreToolUse hook results before
running the tool. It supports both formats below:

{"updatedInput": {"command": "rtk git status"}}
{
  "hookSpecificOutput": {
    "updatedInput": {"command": "rtk git status"}
  }
}

Implementation details:

  • Applies updatedInput only for allowed hook results.
  • Merges updated fields into the original argument object so hooks can rewrite one
    field while preserving the rest.
  • Ignores non-object tool arguments and malformed hook stdout to keep the existing
    fail-open behavior.
  • Keeps PostToolUse and PostToolUseFailure payloads aligned with the rewritten
    input.
  • Synchronizes the serialized tool_call.function.arguments after rewriting so
    wire external tools receive the updated arguments as well.

Tests added in tests/core/test_toolset.py cover:

  • Direct updatedInput output.
  • Nested hookSpecificOutput.updatedInput output.
  • Non-object tool arguments.
  • Wire external tools receiving rewritten request arguments.

Verification run locally:

.venv/bin/python -m pytest tests/core/test_toolset.py tests/hooks/test_runner.py tests/hooks/test_engine.py tests/hooks/test_integration.py

Result: 45 passed.

Documentation updates:

  • Added an Unreleased changelog entry in CHANGELOG.md.
  • Synced the English release notes with node docs/scripts/sync-changelog.mjs.
  • Added the matching Chinese changelog entry.
  • Updated the Hooks documentation in English and Chinese to describe PreToolUse.updatedInput.
  • Updated the Print mode documentation in English and Chinese to describe background
    task waiting before one-shot --print exits.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…dInput

docs(zh): fix incorrect callout title for info block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant