feat: allow PreToolUse hooks to modify tool input via updatedInput#1963
Open
0xMashiro wants to merge 2 commits intoMoonshotAI:mainfrom
Open
feat: allow PreToolUse hooks to modify tool input via updatedInput#19630xMashiro wants to merge 2 commits intoMoonshotAI:mainfrom
0xMashiro wants to merge 2 commits intoMoonshotAI:mainfrom
Conversation
…dInput docs(zh): fix incorrect callout title for info block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
PreToolUsehooks to modify tool arguments by returningupdatedInputin stdout, matching the hook format used by Claude Code-compatible tooling such as rtk.
Before this change, Kimi CLI
PreToolUsehooks could allow or block a tool call, butcould 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 originalgit statusarguments would still be executed.The toolset now consumes
updatedInputfrom allowedPreToolUsehook results beforerunning the tool. It supports both formats below:
{"updatedInput": {"command": "rtk git status"}}{ "hookSpecificOutput": { "updatedInput": {"command": "rtk git status"} } }Implementation details:
updatedInputonly for allowed hook results.field while preserving the rest.
fail-open behavior.
PostToolUseandPostToolUseFailurepayloads aligned with the rewritteninput.
tool_call.function.argumentsafter rewriting sowire external tools receive the updated arguments as well.
Tests added in
tests/core/test_toolset.pycover:updatedInputoutput.hookSpecificOutput.updatedInputoutput.Verification run locally:
Result:
45 passed.Documentation updates:
CHANGELOG.md.node docs/scripts/sync-changelog.mjs.PreToolUse.updatedInput.task waiting before one-shot
--printexits.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.