-
Notifications
You must be signed in to change notification settings - Fork 186
Description
Kiro Product
IDE
Feature Description
Feature Request: runCommand hook with stdout injected into agent context + tool parameter variables
Problem
Currently, hooks offer two action types with a trade-off:
runCommand: Executes a shell command without blocking the agent, but the agent cannot see the command output (stdout/stderr). It's fire-and-forget.
askAgent: The agent can see results and act on them, but it blocks the main task (serial insertion), adding significant latency to every triggered event.
This makes it impossible to build lightweight, non-blocking automation where the agent still receives the command output.
Additionally, preToolUse and postToolUse hooks have no access to the tool's parameters. For example, when a write tool is invoked on
main.py
, the hook's command has no way to know which file was written. This forces you to either hardcode paths or run commands against the entire project.
Proposed Solution
Two enhancements:
runCommand with output injection: Add a flag (e.g., "injectOutput": true) that captures stdout/stderr asynchronously and injects it into the agent's context once the command completes — non-blocking, parallel to the agent's main task.
Tool parameter variables in hook commands: Expose the triggering tool's parameters as template variables (e.g., {{tool.path}}, {{tool.oldStr}}) so hook commands can reference them. For example:
{
"when": { "type": "postToolUse", "toolTypes": ["write"] },
"then": {
"type": "runCommand",
"command": "uv run ruff check --fix {{tool.path}}",
"injectOutput": true
}
}
Use Case
postToolUse hook on write tools → runs ruff check --fix src/app/main.py (using {{tool.path}}) in parallel → agent sees "2 errors remaining" in context → fixes them without an extra manual command invocation. No serial blocking, no wasted turns.
Without parameter variables, the hook would have to run ruff check --fix src/ on the entire project every time any file is written, which is wasteful and pollutes the output with unrelated issues.
Use Case
postToolUse hook on write tools → runs ruff check --fix src/app/main.py (using {{tool.path}}) in parallel → agent sees "2 errors remaining" in context → fixes them without an extra manual command invocation. No serial blocking, no wasted turns.
Without parameter variables, the hook would have to run ruff check --fix src/ on the entire project every time any file is written, which is wasteful and pollutes the output with unrelated issues.
Additional Context
No response