Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

postToolUse hooks: toolArgs not populated in USER_PROMPT environment variable

Open stack72 opened this issue 9 months ago • 7 comments

Before opening, please confirm:

Operating System

macOS 26.2

Kiro Version

0.10.32

Bug Description

Kiro IDE is not populating the toolArgs field in the USER_PROMPT environment variable when executing postToolUse hooks. The environment variable is set correctly, but toolArgs is always an empty object {} instead of containing the actual parameters passed to the tool.

This prevents hooks from accessing critical information like:

  • The actual bash command that was executed (executeBash)
  • File paths and content for file operations (strReplace, fsWrite, etc.)
  • Any other tool-specific parameters

This breaks integrations with external audit/logging systems that need to record what commands were actually executed.

Impact: High - blocks integration with external audit/logging systems like swamp audit record --from-hook

Steps to Reproduce

  1. Create a postToolUse hook in .kiro/hooks/test-hook.kiro.hook:
{
  "name": "Test Hook",
  "description": "Test hook to capture tool arguments",
  "version": "1",
  "when": {
    "type": "postToolUse",
    "toolTypes": ["*"]
  },
  "then": {
    "type": "runCommand",
    "command": "echo \"$USER_PROMPT\" >> ~/hook-test.log",
    "timeout": 5
  }
}
  1. Execute any tool in Kiro IDE (e.g., run a bash command like date or pwd)

  2. Check the log file:

cat ~/hook-test.log
  1. Observe that toolArgs is always {}

Example output:

{"toolName":"executeBash","toolArgs":{},"toolResult":"Output:\nTue  3 Mar 2026 15:04:48 GMT\n\n\nExit Code: 0","toolSuccess":true}

Expected Behavior

The USER_PROMPT environment variable should contain the complete tool invocation details including all arguments passed to the tool.

Expected output for executeBash with command "date":

{
  "toolName": "executeBash",
  "toolArgs": {
    "command": "date"
  },
  "toolResult": "Output:\nTue  3 Mar 2026 15:04:48 GMT\n\n\nExit Code: 0",
  "toolSuccess": true
}

Expected output for strReplace:

{
  "toolName": "strReplace",
  "toolArgs": {
    "path": "file.txt",
    "oldStr": "old text",
    "newStr": "new text"
  },
  "toolResult": "Replaced text in file.txt",
  "toolSuccess": true
}

The toolResult and toolSuccess fields are correctly populated - only toolArgs is affected.

Conversation ID

No response

Additional Context

Environment

  • Kiro Version: 0.10
  • Platform: macOS (darwin)
  • Shell: bash

This Works in kiro-cli but NOT in Kiro IDE

The same hook configuration works correctly in kiro-cli (agent hooks in .kiro/agents/*.json):

Working configuration (kiro-cli):

{
  "name": "swamp",
  "hooks": {
    "postToolUse": [
      {
        "command": "swamp audit record --from-hook --tool kiro"
      }
    ]
  }
}

This correctly passes tool arguments and successfully records audit data.

Broken configuration (Kiro IDE):

{
  "name": "Swamp Audit",
  "version": "1",
  "when": {
    "type": "postToolUse",
    "toolTypes": ["*"]
  },
  "then": {
    "type": "runCommand",
    "command": "echo \"$USER_PROMPT\" | swamp audit record --from-hook --tool kiro",
    "timeout": 5
  }
}

This fails because toolArgs is empty.

Other Tools Work Correctly

Claude Desktop uses a similar hook configuration and correctly passes tool arguments:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "swamp audit record --from-hook"
          }
        ]
      }
    ]
  }
}

Real-World Use Case

We're integrating Kiro with swamp audit record --from-hook, which expects to receive the actual command that was executed via stdin. The integration works with:

  • ✅ kiro-cli (agent hooks)
  • ✅ Claude Desktop
  • ✅ Cursor
  • ❌ Kiro IDE (desktop app)

Evidence

Created a test script to capture the USER_PROMPT environment variable:

#!/bin/bash
echo "USER_PROMPT content:" >> ~/kiro-hook-simple.log
echo "$USER_PROMPT" >> ~/kiro-hook-simple.log
echo "---" >> ~/kiro-hook-simple.log

After running multiple commands (date, pwd, ls -la), the log consistently shows:

USER_PROMPT content:
{"toolName":"executeBash","toolArgs":{},"toolResult":"Output:\nTue  3 Mar 2026 15:04:48 GMT\n\n\nExit Code: 0","toolSuccess":true}
---

In all cases, toolArgs is empty.

Technical Details

When hooks run, Kiro sets these environment variables:

__CFBundleIdentifier=dev.kiro.desktop
TERM_PROGRAM=kiro
VSCODE_IPC_HOOK=/Users/stack72/Library/Application Support/Kiro/0.10-main.sock
USER_PROMPT={"toolName":"...","toolArgs":{},"toolResult":"...","toolSuccess":true}

The USER_PROMPT variable is present but the toolArgs field is incomplete.

Suggested Fix

The Kiro IDE hook implementation should:

  1. Capture the full tool invocation parameters when a tool is called
  2. Serialize these parameters into the toolArgs field of the JSON object
  3. Set the complete JSON as the USER_PROMPT environment variable before executing the hook command

The implementation should match what kiro-cli does to ensure consistency across both interfaces.

stack72 avatar Mar 03 '26 15:03 stack72

🤖 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 issues are about hooks not working correctly - the new issue reports toolArgs not being populated in postToolUse hooks, while #4867 reports hook matcher not matching tool names. Both are hook-related functionality problems in Kiro with similar technical context around tool execution and hook integration.

github-actions[bot] avatar Mar 03 '26 15:03 github-actions[bot]

This is not a duplicate. #4867 is about hook matchers not recognizing renamed tool names. This issue is about toolArgs being empty in the USER_PROMPT environment variable - the hooks trigger but receive incomplete data.

stack72 avatar Mar 03 '26 15:03 stack72

Thank you for your feedback! 🙏

The duplicate label has been removed and this issue has been sent back for maintainer review.

A maintainer will review this issue shortly.

github-actions[bot] avatar Mar 03 '26 15:03 github-actions[bot]

Any time line on this fix? It also doesn't work for preToolUse we currently don't have a way to get way tool parameters are being used...

austinamorusoispot avatar Mar 31 '26 17:03 austinamorusoispot

+1 — independently verified on Kiro 0.11 (macOS Apple Silicon) that this also affects preToolUse hooks, confirming @austinamorusoispot's comment.

We tested with a Python script checking both USER_PROMPT env var and stdin:

USER_PROMPT = {} (empty toolArgs) stdin = empty (no JSON payload at all) The same hook works correctly in kiro-cli chat where stdin receives the full JSON with tool_name and tool_input.

The preToolUse case is arguably more critical than postToolUse because it enables blocking dangerous operations before they execute — security gates, toolchain enforcement (blocking pip install in uv projects), preventing writes to protected paths, etc. Without toolArgs, preToolUse + runCommand can only check static workspace state, which eliminates its primary use case.

neJoe-ch avatar Apr 13 '26 16:04 neJoe-ch

+1 - still broken on 0.11.133 (macOS). i did a pretty thorough investigation today, checked stdin, fds, every env var i could think of, parent process info, etc. the script has no context beyond a preToolUse event was triggered.

for preToolUse specifically, USER_PROMPT is just {}. not even the {toolName, toolArgs:{}, toolResult} structure that postToolUse gets.

the CLI docs show that runCommand hooks should receive full JSON on stdin with tool_name, tool_input, session_id, etc. the IDE sends none of it. the plumbing clearly exists in the source (spawnHookCommand does env: { USER_PROMPT: userPrompt }), the args just aren't being populated before they get there.

this effectively makes runCommand useless for preToolUse. the only 'workaround' is is to use askAgent, which obviously burns tokens on every tool use (unless that's the point) and is non-deterministic. i'd really love to see this prioritised, it would be so helpful!

breakbeatkid avatar Apr 24 '26 08:04 breakbeatkid

+1 — still reproduces on Kiro IDE 1.0.89 (macOS Apple Silicon). Adding a severity data point that hasn't been on this thread yet: the empty tool_input doesn't just disable a convenience hook — in a multi-agent orchestrator it silently collapses workflow determinism.

Fresh confirmation (IDE 1.0.89)

A postToolUse runCommand hook logging the raw stdin payload captured 471/471 tool calls with tool_input: {} — every execute_bash, fs_write, read_files, subagent, and MCP call, no exception. Note the channel has changed since the earlier reports here: on 1.0.89 the payload now arrives as stdin JSON (not the USER_PROMPT env var that #6188 / earlier comments describe), with the CLI-shaped envelope {session_id, hook_event_name, cwd, tool_name, tool_input, tool_response} — but tool_input is still {}, and tool_response carries only the tool's output, never the command/args string. So a hook still has no way to see what the tool did.

Why this is more than a convenience gap — a concrete blast radius

We run an AI-DLC-style workflow engine where a postToolUse hook recompiles a "runtime graph" after each state transition. That graph carries the unit-of-work dependency DAG (a topological batch plan: [[U1], [U2, U3], [U4]]) that the engine fans out across the Construction phase — one design/codegen pass per unit, gated per unit.

Because the hook is keyed on the shell command (tool_input.command) and that field is always empty, the recompile never fires after the dependency file is written. The graph stays frozen at its pre-dependency state, the DAG node is absent, and the per-unit loop degrades to a single iteration:

  • The engine processes only the first unit (U1) of the entire feature.
  • Units U2/U3/U4 — their design, their code, their per-unit gates — are silently skipped.
  • The workflow still reports "complete." The user gets a walking skeleton where they asked for the full feature, with no error surfaced.

We verified the engine logic itself is correct: replaying the same recompile with a non-empty command produces the DAG perfectly. The sole cause is the empty tool_input starving the hook of its trigger.

What we need (same ask as this issue)

The minimal CLI-parity payload on stdin for preToolUse / postToolUse — hook_event_name, tool_name, tool_input (and tool_response for postToolUse, which the CLI already provides). With tool_input populated, the recompile fires deterministically and the per-unit fan-out works as designed.

We have a local read-side workaround (recompute the DAG from the on-disk dependency file at consume time, independent of the hook channel), but that is us routing around a platform gap — every team building deterministic multi-agent orchestration on IDE hooks hits this same wall. This is the load-bearing primitive; it's been open since March across 0.11 → 0.12 → 1.0. Bumping for triage.

wowzoo avatar Jul 05 '26 12:07 wowzoo