Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

IDE preToolUse runCommand hooks receive empty toolArgs — CLI passes full context, IDE passes {}

Open breakbeatkid opened this issue 7 months ago • 2 comments

Before opening, please confirm:

Operating System

darwin

Kiro Version

0.11.131

Bug Description

IDE preToolUse runCommand hooks don't receive tool context. The USER_PROMPT env var is set but contains {} (empty JSON object). No TOOL_NAME, TOOL_INPUT, or other tool-related env vars are provided. No data is available on stdin.

This means runCommand hooks cannot make conditional decisions based on which tool is being invoked or what arguments it's being called with. The only workaround is askAgent, which invokes the LLM on every tool call — non-deterministic and expensive in tokens.

The CLI already passes full tool context as JSON via stdin for preToolUse hooks (documented here). The IDE should provide equivalent context.

Steps to Reproduce

  1. Create a preToolUse hook with runCommand:
{
  "name": "Debug Hook",
  "version": "1",
  "when": {
    "type": "preToolUse",
    "toolTypes": ["read"]
  },
  "then": {
    "type": "runCommand",
    "command": "bash debug-hook.sh"
  }
}
  1. Create debug-hook.sh:
#!/usr/bin/env bash
echo "USER_PROMPT=$USER_PROMPT" > /tmp/hook-debug.txt
echo "ENV_VARS:" >> /tmp/hook-debug.txt
env | grep -i 'TOOL\|HOOK\|KIRO' >> /tmp/hook-debug.txt 2>/dev/null
exit 0
  1. Trigger a readFile tool call.
  2. Check /tmp/hook-debug.txt — it shows USER_PROMPT={} and no tool-related env vars.

Expected Behavior

The hook script should receive context about the tool invocation, at minimum the tool name and its arguments. The CLI provides this via stdin:

{
  "hook_event_name": "preToolUse",
  "tool_name": "read",
  "tool_input": {
    "operations": [{ "mode": "Line", "path": "/some/file.ts" }]
  }
}

For the IDE, this could be via env vars (e.g. TOOL_NAME, TOOL_INPUT) or stdin — either would work.

Conversation ID

No response

Additional Context

The IDE source code does pass toolArgs through the hook pipeline in executePreToolUseHooks:

const toolArgsJson = JSON.stringify(toolArgs);
updatedState = await runHookCommandInstance.executeHook(hook2, updatedState, toolArgsJson);

And spawnHookCommand forwards it as USER_PROMPT:

env: { USER_PROMPT: userPrompt }

But toolArgs arrives as {} at the hook executor. The plumbing exists — the args just aren't being populated upstream.

Notably, postToolUse hooks appear to pass richer context ({ toolName, toolArgs, toolResult, toolSuccess }), suggesting this may be specific to the preToolUse path.

breakbeatkid avatar Apr 11 '26 18:04 breakbeatkid

🤖 Potential Duplicate Detected

This issue appears to be similar to:

What happens next?

  • ⏰ This issue will be automatically closed in 3 days
  • 🏷️ If this is not a duplicate, you can prevent automatic closure by adding a comment or reacting with 👎 to this message.
  • 💬 Comment on the original issue if you have additional information

Why is this marked as duplicate? Both report the same issue with preToolUse hooks not receiving proper toolArgs context - new issue focuses on IDE while existing issue mentions postToolUse but describes identical symptoms of empty toolArgs in USER_PROMPT environment variable

github-actions[bot] avatar Apr 11 '26 18:04 github-actions[bot]

This issue has been automatically closed as it appears to be a duplicate of #6188.

If you believe this is incorrect, please comment on this issue and a maintainer will review it.

github-actions[bot] avatar Apr 15 '26 00:04 github-actions[bot]