Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

Bug Report: Bash Command Output Not Captured in Agent Context

Open tmattoneill opened this issue 1 year ago • 4 comments

Before opening, please confirm:

Operating System

MacOS 15.6.1 (24G90)

Kiro Version

0.3.9

Bug Description

Bug Report: Bash Command Output Not Captured in Agent Context Summary The AI agent cannot see stdout/stderr output from bash commands executed via the executeBash tool, despite commands executing successfully (Exit Code: 0). The user can see the output in their terminal, but the agent only receives the prompt line and exit code.

Kiro: Version: 0.3.9 VSCode Version: 1.103.2 Commit: 08f2a25ac39a433fcac50bcacf936f381d4577cb Date: 2025-10-02T22:44:07.528Z Electron: 37.5.1 ElectronBuildId: undefined Chromium: 138.0.7204.251 Node.js: 22.19.0 V8: 13.8.258.32-electron.0 OS: Darwin arm64 24.6.0

Environment OS: macOS (darwin) Shell: zsh Platform: Apple Silicon (M1/M2) Working Directory: /Volumes/NMVe M2/dev/sunchart (external NVMe drive) Kiro Version: Beta Python: 3.13.5 (via pyenv) Expected Behavior When executing bash commands via executeBash tool, the agent should receive:

Output:

Exit Code: 0 For example, echo "test output" should return:

Output: test output

Exit Code: 0 Actual Behavior The agent receives only the shell prompt and exit code:

Output: homasoneill@MacBook-M1-2063:/Volumes/NMVe M2/dev/sunchart

Exit Code: 0 No stdout or stderr content is captured, regardless of the command.

Reproduction Steps Execute any bash command that produces output via executeBash tool Commands tested: echo "test output" pwd ls -la docker ps python3 --version which docker All commands return only the prompt line with no actual output.

Impact Severity: High - This fundamentally breaks the agent's ability to:

Diagnose system state Verify command execution results Read file listings Check installed software versions Debug application issues Interact with Docker containers Perform any bash-based diagnostics The agent is essentially "blind" to command output, making it unable to perform basic system administration or troubleshooting tasks.

User Confirmation The user confirms they can see the full command output in their terminal, indicating:

Commands ARE executing correctly Output IS being generated The issue is in the capture/transmission layer between the shell and the agent context Potential Causes to Investigate

  1. Path/Volume Issue Working directory is on an external NVMe drive with a space in the path: /Volumes/NMVe M2/dev/sunchart

Could be a path escaping issue Could be a volume permission issue Could be related to external drive mounting 2. Shell Configuration User is using zsh with pyenv Could be a prompt configuration issue (PS1/PROMPT) Could be related to shell initialization files (.zshrc, .zprofile) Could be output redirection in shell config 3. Output Buffering stdout/stderr might not be flushed before capture Could be a timing issue with command completion detection 4. Terminal Emulation Could be related to how Kiro captures terminal output Might be treating the prompt as the only output 5. macOS-Specific Issue Could be related to macOS security/privacy settings Could be related to Apple Silicon architecture Could be related to terminal accessibility permissions Suggested Debugging Steps Test with different working directories:

Try from user's home directory Try from a path without spaces Try from internal drive vs external drive Test with explicit output redirection:

echo "test" 2>&1 printf "test\n" Check if stderr is captured:

echo "error" >&2 Test with different shells:

Try with bash instead of zsh Try with sh Check terminal permissions:

Verify Kiro has accessibility permissions in macOS System Settings Check if terminal emulator has full disk access Test command execution method:

Log what command is actually being executed Log the full subprocess call and capture method Check if output is being written to a temp file that's not being read Workaround Currently, the user must manually run commands in their terminal and paste output back to the agent, which defeats the purpose of autonomous agent execution.

Additional Context This issue was discovered during a diagnostic session for a Docker-based application The agent needed to check Docker container status, Python versions, and file listings All file-based operations (readFile, listDirectory, etc.) work correctly Only bash command output capture is affected Request Please investigate the output capture mechanism for the executeBash tool, particularly:

How stdout/stderr are being captured Whether there are known issues with external drives or paths with spaces Whether macOS accessibility permissions are required Whether there's a configuration option to enable verbose output logging Reporter: User via AI Agent Date: April 10, 2025 Session Context: Sunchart application diagnostics

Steps to Reproduce

Steps to Reproduce Prerequisites macOS system (tested on Apple Silicon M1/M2) Kiro IDE Beta installed Terminal using zsh shell Working directory on external NVMe drive with space in path: /Volumes/NMVe M2/dev/sunchart pyenv installed with Python 3.13.5 Reproduction Steps Open Kiro IDE

Launch Kiro IDE Beta Open a project located at /Volumes/NMVe M2/dev/sunchart Start an AI agent session

Initiate a chat with the AI agent Ask the agent to run a diagnostic or check system state Agent executes a simple bash command

Agent uses executeBash tool with command: echo "test output" Or any other command that produces stdout: ls -la, pwd, docker ps, etc. Observe the output

In user's terminal: Full command output is visible ❯ echo "test output" test output In agent's context: Only prompt line is captured Output: homasoneill@MacBook-M1-2063:/Volumes/NMVe M2/dev/sunchart

Exit Code: 0 Verify the issue persists across different commands

Try: python3 --version Try: docker ps -a Try: which docker Try: ls -la All return only the prompt line, no actual output Expected Result Agent should receive the actual command output:

Output: test output

Exit Code: 0 Actual Result Agent receives only the shell prompt:

Output: homasoneill@MacBook-M1-2063:/Volumes/NMVe M2/dev/sunchart

Exit Code: 0 Frequency 100% reproducible - occurs with every bash command execution

Additional Test Cases Test Case 1: Simple echo Command: echo "hello world" Expected: "hello world" Actual: Empty (only prompt) Test Case 2: List directory Command: ls -la Expected: Directory listing with files and permissions Actual: Empty (only prompt) Test Case 3: Check version Command: python3 --version Expected: "Python 3.13.5" Actual: Empty (only prompt) Test Case 4: Docker status Command: docker ps Expected: Container listing or "CONTAINER ID IMAGE..." header Actual: Empty (only prompt)

Expected Behavior

Command Output Capture When the AI agent executes a bash command using the executeBash tool, the tool should capture and return the complete stdout and stderr output from the command execution.

Example 1: Simple Echo Command Command: echo "test output" Expected Response:

Output: test output

Exit Code: 0 Example 2: Directory Listing Command: ls -la Expected Response:

Output: total 48 drwxr-xr-x 12 homasoneill staff 384 Apr 10 14:23 . drwxr-xr-x 8 homasoneill staff 256 Apr 10 12:15 .. -rw-r--r-- 1 homasoneill staff 123 Apr 10 13:45 docker-compose.yml drwxr-xr-x 6 homasoneill staff 192 Apr 10 14:20 backend drwxr-xr-x 8 homasoneill staff 256 Apr 10 14:22 frontend -rw-r--r-- 1 homasoneill staff 1024 Apr 10 12:30 README.md

Exit Code: 0 Example 3: Version Check Command: python3 --version Expected Response:

Output: Python 3.13.5

Exit Code: 0 Example 4: Docker Container Status Command: docker ps -a Expected Response:

Output: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1856a4010c1d ghcr.io/open-webui/open-webui:cuda "bash start.sh" 3 weeks ago Created open-webui fcb713305e3d photo-sort-frontend "/docker-entrypoint.…" 4 weeks ago Exited (0) 4 weeks ago picker-frontend 5746442742ca photo-sort-backend "uvicorn app.main:ap…" 4 weeks ago Exited (0) 4 weeks ago picker-backend

Exit Code: 0 Example 5: Error Output (stderr) Command: ls /nonexistent Expected Response:

Output: ls: /nonexistent: No such file or directory

Exit Code: 2 Key Requirements Complete stdout capture - All standard output from the command should be included Complete stderr capture - All error output should be included (either merged with stdout or separately indicated) Exit code - The command's exit code should be accurately reported Timing - Output should be captured after command completion, not truncated prematurely Encoding - Output should preserve special characters, newlines, and formatting No prompt pollution - Shell prompt (PS1) should not be included in the output unless it's actual command output Agent Usage With proper output capture, the agent should be able to:

Read and parse command results Make decisions based on system state Verify command execution success Debug issues by examining error messages Chain commands based on previous output Provide accurate diagnostics to users

Conversation ID

3aca1fc5-5fb6-44fa-8b43-4e9c6a021990

Additional Context

No response

tmattoneill avatar Oct 04 '25 09:10 tmattoneill

Some interesting additional info:

Perfect! So you see thomasoneill correctly in your terminal, but I'm seeing homasoneill@MacBook-M1-2063:/Volumes/NMVe M2/dev/sunchart which is clearly your shell prompt, not the command output.

This confirms:

Commands execute correctly - you get proper output
I'm only seeing the prompt - specifically what looks like a PS1 prompt
The "t" is missing - which is very strange and might be a rendering/capture issue
Actual stdout is completely lost - I never see thomasoneill at all
Key Finding
The executeBash tool is capturing the shell prompt instead of (or in addition to, but overwriting) the actual command output.

This is likely a terminal emulation or output stream capture issue where:

The prompt is being written to the same buffer as stdout
The prompt is overwriting the actual output
Or the tool is reading from the wrong file descriptor
Or there's a timing issue where it captures before stdout is flushed
This is definitely the root cause. Should I add this specific finding to the bug report? This is a smoking gun - the tool is fundamentally capturing the wrong output stream.

tmattoneill avatar Oct 04 '25 09:10 tmattoneill

I got the same issue with Gradle errors. Kiro misses stderr output from failed commands.

Environment

  • OS: Omarchy 3.1.0 (Linux 6.17.3-arch2-1)
  • Kiro: 0.4.0

Reproduction

When Kiro executes:

./gradlew shared:compileKotlinAndroid

Running manually shows the actual error:

Cannot locate tasks that match ':shared:compileKotlinAndroid' as task 'compileKotlinAndroid' not found in project ':shared'.

The problem is clear, the task compileKotlinAndroid doesn't exist.

But Kiro only captures:

Output:
…/Dev/project-name ✗
Exit Code: 1

stderr is completely missing, as @tmattoneill mentioned. This causes blind retry loops where Kiro tries random fixes without seeing the actual error, burning tokens with no progress.

Workaround

Created .kiro/steering/build-error-handling.md to stop the retry loop:

---
inclusion: always
---

# Error Handling Guidelines

## CRITICAL: Stop and Ask First

When ANY command fails with non-zero exit code but shows minimal/no error details:

1. **IMMEDIATELY STOP** attempting fixes
2. **DO NOT GUESS** the problem
3. **DO NOT MAKE** multiple attempts
4. **ASK THE USER FIRST** to run the command manually with verbose flags

This rule applies BEFORE any other troubleshooting steps.

## Detailed Guidelines

When encountering command failures with non-zero exit codes but no detailed output:

1. ALWAYS ask the user to run the command manually in their terminal with verbose flags
2. Request the user to paste the complete error output
3. Do not attempt to guess the error or make multiple blind attempts
4. Explain that the executeBash tool is not showing complete error details

## Common Verbose Flags by Tool Type:

### Build Tools:
- Gradle: `--stacktrace` or `--debug`
- Maven: `-X` (debug) or `-e` (errors)
- npm/yarn: `--verbose`

### General Commands:
- Most CLI tools: `-v`, `--verbose`, or `--debug`
- System commands: Add `-v` where supported

## Example Response Template:
"I see the command failed but the error output is not showing details. Could you please run this command in your terminal and paste the complete output?

\`\`\`bash
[original-command] [appropriate-verbose-flag]
\`\`\`

This will help me identify the exact issue and provide a proper solution."

## When to Apply:
- Any command that exits with non-zero status but shows minimal/no error details
- Build failures, test failures, deployment issues, or any CLI tool errors
- When the executeBash tool output is insufficient for diagnosis

Result: Kiro now asks for the real error instead of guessing.

Before the workaround:

Image

After the workaround:

Image

RafaelrainBR avatar Oct 19 '25 23:10 RafaelrainBR

Similar issue. But for me caused by enabling iterm shell integration tools. https://iterm2.com/documentation-shell-integration.html#download-and-run

Image Image

rossalanmiller avatar Nov 20 '25 20:11 rossalanmiller

Closing as duplicate of #207. The terminal output capture issue is being tracked there. Please follow that issue for updates.

AnilMaktala avatar Nov 25 '25 17:11 AnilMaktala