Terminal tool corrupts output and reports incorrect exit codes when shell outputs OSC escape sequences
Before opening, please confirm:
- [x] I have searched for duplicate or closed issues
Operating System
linux
Kiro Version
0.8.0
Bug Description
When a user's shell configuration outputs OSC (Operating System Command) escape sequences (e.g., from Amazon Q shell integration), the executeBash tool exhibits two issues:
-
Corrupted output: OSC sequences are partially captured as visible text instead of being filtered. For example,
TTY=not a ttyand prompt strings appear appended to command output. -
Incorrect exit code: All commands report
Exit Code: -1regardless of actual exit status (even successful commands likeecho "hello"orls).
Steps to Reproduce
- User has Amazon Q CLI installed with shell integration in
.bashrc - Amazon Q's init script uses
fig_oscto send sequences likefig_osc "TTY=%s" "${TTY}"andfig_osc "ExitCode=%s" "$__fig_ret_value" - These OSC sequences are meant for terminal interpretation but get captured/mangled by the tool
Example output:
> echo "Hello World"
Output:
echo "Hello World"
Hello World
TY=not a tty<user>@<host>: ~/path/to/workspace...
Exit Code: -1
Expected Behavior
- OSC escape sequences should be stripped from captured output
- Exit codes should reflect actual command exit status
Conversation ID
a0f5bfed-11c4-4326-8631-d029fc09afb5
Additional Context
Workaround:
Remove or disable shell integrations that output OSC sequences (Amazon Q, Fig, etc.) from .bashrc.
Environment:
- Kiro: 0.8.0 (ff5b0b54a4bf5780b759a0cf91b16350f8f1fd95, x64)
- OS: Ubuntu 24.04.3 LTS (Noble Numbat)
- Kernel: 6.14.0-37-generic x86_64
- Shell: GNU bash 5.2.21(1)-release
- Amazon Q CLI: 1.13.0
Sharing my workaround for those who have kiro-cli installed. https://github.com/kirodotdev/Kiro/issues/5240#issuecomment-3821798969
I've spent all day trying to debug this and nothing seemed to work.
DONE:0
TY=not a tty(.venv) (base) poecurt@GYK4W72NX9 frontend (ovid/deep-research*)
I finally developed the most awful workaround. This is in my tech.md steering file:
## Shell Environment (non-TTY workaround)
The agent shell SOMETIMES does not have Node.js on `$PATH` by default and SOMETIMES
reports "not a tty" errors. When this occurs, run any Node/npm/npx command, prefix
it with:
```bash
export PATH="/opt/homebrew/bin:/opt/homebrew/Cellar/node/25.2.1/bin:$PATH"
```
Interactive terminal output (spinners, progress bars) also gets swallowed.
Redirect output to a workspace file and read it back:
```bash
export PATH="/opt/homebrew/bin:/opt/homebrew/Cellar/node/25.2.1/bin:$PATH" \
&& npx vitest run --reporter=json 2>&1 > vitest_results.json; echo "DONE:$?"
```
Then read `vitest_results.json` with the readFile tool. Delete the file when done.
It's allowing me to limp along, but I'm glued to the IDE, approving every command.
Cheapest Anthropic & OpenAI-Compatible API π
Works with Claude Code, Cursor, Cline, Void, Continue, Kilo Code, OpenClaw, OpenCode, LangChain, Obsidian, IntelliJ β any OpenAI-compatible client.
π° Pricing (1 credit β $1 original Anthropic)
| Credits | Price | Tokens |
|---|---|---|
| 1k | $5 | ~100M |
| 5k | $15 | ~500M |
| 10k | $30 | ~1B |
π€ Models: claude-opus-4-6 / sonnet-4-6 / haiku-4-5 (1M ctx + websearch)
β Why us?
- 100 trial credits before payment
- Credits issued before payment
- Any country, any payment method
- 400+ clients, quality guarantee
- We can prove Opus is real and explain pricing
π© Telegram: @yon_sup
Same issue here with zsh + Oh My Zsh + Powerlevel10k on macOS. Every execute_bash call reports exit code 1 no matter what, which causes the agent to think everything failed and ask "should I keep iterating?" after every successful command.
Did some digging β the actual $? inside the shell is 0 (verified by printing it). Even /bin/bash --norc --noprofile -c 'exit 0' reports 1. Explicit exit 0 works fine though, so the 633;D detection is functional. Tried reordering precmd hooks to put __vsc_precmd first β didn't help. It's P10k's OSC sequences that confuse the parser.
Workaround that fixed it for me β add this to .zshrc before P10k loads:
if [[ "$TERM_PROGRAM" == "kiro" ]]; then
POWERLEVEL9K_TERM_SHELL_INTEGRATION=false
POWERLEVEL9K_DISABLE_INSTANT_PROMPT=true
fi
This disables P10k's terminal integration (redundant since Kiro has its own) and the instant prompt (invisible in agent terminals anyway). Only affects Kiro sessions, regular terminals stay the same. After this, all exit codes report correctly.
Additional data point on Windows / PowerShell 7, with a reproducible early-return variant.
Environment: Kiro on Windows, shell PowerShell 7 (pwsh.exe) launched with -NoExit -Command ". <workspace-init>.ps1" (a workspace startup script).
Symptoms observed (matching this issue):
- Command input is echoed back character-by-character and interleaved into captured output.
- Prompt strings / prior command fragments appear appended to output.
- Commands return
Exit Code: 1despite the underlying command succeeding. - Output is frequently empty even though the command produced results.
Reproducible early-return on blocking commands:
- Run:
Start-Sleep -Seconds 30; "DONE" | Out-File proof.txt - The tool returns almost immediately with exit code 1 and no
DONE. - Reading
proof.txtimmediately after: file does not exist yet. - Reading ~30s later: file now contains the expected output.
This shows the runner hands control back before the command exits; the process keeps running in the background and its side effects/output land on a terminal nothing is reading. Any agent/Spec flow that waits on a long-running command proceeds as if it completed instantly.
Likely contributing factor in my case: this occurred while two Kiro sessions were open on the same workspace. Commands from the other session (redacted build/test and process-cleanup commands) appeared in this session's terminal buffer, strongly suggesting the same shell/terminal is being shared or routed across concurrent sessions. Filing that concurrency angle separately, but it appears to amplify the corruption + wrong-exit-code behavior described here.
Root cause, plus a Windows case that needs no custom shell integration
I traced this in the shipped bundle (Kiro IDE 1.0.242, kiro.kiro-agent 1.0.428). It is one regex, and it explains every variant reported in this thread β the TY=not a tty fragment, prompt strings appended to output, and prior command fragments.
The defect
src/extension/terminal/utils/strip-ansi.ts carries an ansi-regex-style pattern whose OSC branch only accepts payloads built from [-a-zA-Z\d\/#&.:=?%@~_]:
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
const pattern = [
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
].join("|");
That class contains no space and no backslash. So for any OSC string whose payload holds either character, the OSC branch fails β and the CSI branch then matches ESC ] <digits> ; <one char>, consuming the introducer plus exactly one character and leaving the rest of the payload and the terminator in the output as visible text.
That is why the leftovers in this thread all look like the original sequence with its first few characters shaved off:
| emitted by the shell | what survives into the agent's output |
|---|---|
ESC]697;TTY=not a tty BEL |
TY=not a tty^G (space in payload) |
ESC]0;C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe ESC\ |
:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe + ESC\ (backslash in payload) |
ESC]0;npm exec tsc --noEmit ESC\ |
pm exec tsc --noEmit + ESC\ |
A second, smaller gap in src/extension/terminal/utils/output-sanitizer.ts: the shell-integration pass only removes 633/133 sequences terminated by BEL, so ST-terminated ones fall through to the same broken branch.
value.replace(/\x1b\]633;[^\x07]+\x07/gs, "").replace(/\x1b\]133;[^\x07]+\x07/gs, "")
On Windows this fires with no shell integration at all
ConPTY sets the window title to the executable path, so every PowerShell or cmd command emits ESC]0;C:\WINDOWS\...\<exe>ESC\ β and every such title contains backslashes. No Amazon Q, no Powerlevel10k, no venv hook required.
Measured on one Windows 11 machine, across all 12 local session logs (~/.kiro/sessions/*/*/messages.jsonl): 1223 of 2404 captured command results (50.9%) contain the remnant. Most common forms:
870 ":\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe"
202 ":\WINDOWS\system32\cmd.exe "
44 "pm exec tsc --noEmit\u001b\\:\WINDOWS\system32\cmd.exe "
It is not always a harmless trailing line β it also lands mid-content, splitting real output:
"Output:\n6f0870c5d489f5755a7d2f4d898ee681531dcbb8\r\n:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\u001b\\claude/worker-session-handoff-"
A raw ESC byte also survives into the model's context and into the persisted session file. Given this, the os: linux label understates the scope β the Windows default path is affected too.
For the record, in my environment exit codes are reported correctly while the remnants are present, so the output-corruption half and the Exit Code: -1/1 half of this issue are separable.
Repro
Verbatim copies of both shipped files, no Kiro needed:
import { stripVTControlCharacters } from "node:util";
function ansiRegex({ onlyFirst = false } = {}) { // strip-ansi.ts, as shipped
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
const pattern = [
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
].join("|");
return new RegExp(pattern, onlyFirst ? void 0 : "g");
}
const stripAnsi = (v) => v.replace(ansiRegex(), "");
function sanitizeTerminalOutput(value) { // output-sanitizer.ts, as shipped
const s = value.replace(/\x1b\]633;[^\x07]+\x07/gs, "").replace(/\x1b\]133;[^\x07]+\x07/gs, "");
const lines = stripAnsi(s).trimEnd().split("\n");
lines[lines.length - 1] = lines[lines.length - 1].replace(/[%$#>]\s*q?$/m, "");
return lines.join("\n") + (value.endsWith("\n") ? "\n" : "");
}
const seq = "hello\r\n\u001b]0;C:\\WINDOWS\\system32\\cmd.exe \u001b\\\n";
console.log(JSON.stringify(sanitizeTerminalOutput(seq)));
console.log(JSON.stringify(ansiRegex({ onlyFirst: true }).exec("\u001b]0;C:\\WINDOWS\\system32\\cmd.exe \u001b\\")[0]));
"hello\r\n:\\WINDOWS\\system32\\cmd.exe \u001b\\\n"
"\u001b]0;C" <- 5 characters consumed, the rest survives
A POSIX-style title with no space or backslash (ESC]0;bash ESC\) is stripped correctly, which is why this looks OS- or prompt-specific when it is really payload-specific.
Worth noting: util.stripVTControlCharacters does not help β it carries the same upstream pattern and produces the identical leftover (checked on Node 22.22).
Fix
Strip OSC strings in their own pass, before the CSI pass, independent of payload bytes and terminator:
const OSC = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/g;
function sanitizeTerminalOutput(value) {
const oscRemoved = value.replace(OSC, "");
const ansiRemoved = stripAnsi(oscRemoved);
β¦unchangedβ¦
}
[^\x07\x1b]* keeps the match from running past the end of one sequence, and the |$ arm drops a sequence truncated by a chunk boundary. This also makes the 633/133 special cases redundant and covers their ST-terminated forms.
Verified against the six cases I could construct β Windows title with ST, Windows title with BEL, title set to the command line, POSIX title, OSC 633 shell integration, and a 633 marker followed by content: all six come out as clean "hello\n", and the 633 start-marker handling in findContentAfterStartMarkers is untouched since it runs on the raw stream.
Happy to test a build or provide the full measurement script.
Same issue on WSL2 (Ubuntu) + Kiro shell integration. A few additional data points that aren't in the report yet:
1. It happens with Kiro's own kiro-cli integration, not just third-party tools (Amazon Q/Fig). So "remove third-party shell integrations" isn't a real workaround β the OSC/prompt bleed comes from the blocks Kiro itself installs.
2. WSL double-initializes the integration. Stock Ubuntu ~/.profile sources ~/.bashrc, and Kiro installs its pre/post blocks in both files. On a login shell (which Kiro launches) the integration runs twice, producing duplicated prompt markers. Confirmed by inspecting the live shell:
PS1contained two full marker sets:...697;StartPrompt...633;A...697;StartPrompt...633;A...and matchingEndPrompt/NewCmdpairs at the end.PROMPT_COMMANDhad__bp_interactive_modelisted twice.
The visible bleed in captured output is the prompt's text content (the xterm title escape \e]0;\u@\h: \w\a plus the base \u@\h:\w prompt). The OSC marker bytes themselves get stripped, but the human-readable prompt text between them does not.
Symptom (plain ls):
ls file1 file2 file3 ;user@host: /path/to/workspaceuser@host:/path/to/workspace
Workaround that keeps the interactive prompt intact. Kiro's programmatic command-runner shell sets Q_TERM_DISABLED=1, but the interactive IDE terminal does not. So you can blank the prompt only in the capture shell. In ~/.bashrc, after PS1 is set:
# Blank the visible prompt only in Kiro's command-runner shell so it doesn't
# leak into captured output. Interactive terminals keep their normal prompt.
if [ "$Q_TERM_DISABLED" = "1" ]; then
PS1=''
fi
Kiro IDE version 1.0.242 kiro-cli version 2.15.1 OS Version Windows 10.0.26200.8893, running in WSL 2.6.1.0, Ubuntu 24.04.1 LTS
Same root cause (Kiro's shell integration / OSC handling), but a different failure mode here: empty captured output with a correct exit code, not corrupted output with a wrong exit code.
Symptom
execute_bash returns Exit Code: 0, which is correct, but the agent gets none of the command's stdout. Only the prompt line comes through. The command runs fine and the output is visible if you open the terminal. No third-party integration is involved (no Amazon Q, Fig or Powerlevel10k). The .bashrc is clean and the only prompt change is Kiro's own injected shell integration.
Controlled repro
I ran one command that printed a known 89-byte payload straight to stdout (no file redirect), tagged with a unique marker. The agent received none of it, only the prompt line. The log entry for that exact command recorded:
"exitCode":0,"outputLength":46,"timedOut":false
So 89 bytes were produced but only a fixed 46-byte residual (the prompt/marker area) got captured. Over a full session the captured outputLength keeps landing on the same fixed sizes (34 and 46 bytes) no matter what the command actually prints, with only a few commands returning their real length. Looks like the boundary parser grabs the prompt/marker region and misses the command's output block. The exit code detection (633;D) still works, so the exit code stays correct.
Log location used: ~/.config/Kiro/logs/*/window1/exthost/kiro.kiroAgent/Kiro Logs.log
Environment
- OS: Fedora Linux 43 (Workstation), kernel 7.1.10
- Shell: GNU bash 5.3.0(1)-release
- Kiro: 1.0.395,
TERM_PROGRAM=kiro,TERM=xterm-256color,VSCODE_SHELL_INTEGRATION=1 PROMPT_COMMAND=__vsc_prompt_cmd_original(Kiro-injected)- Locale:
LANG=de_DE.UTF-8. Git output was localized to German, which might matter if any parsing keys off English text. ~/.bash_profilesources~/.bashrc, and Kiro starts a login shell, so the integration may initialize twice (same double-init that an earlier WSL comment described).
Workarounds
-
Q_TERM_DISABLED=1is set in Kiro's command-runner shell here, so thePS1=''guard from an earlier comment applies on this setup. -
What actually held up for a full multi-step task: redirect to a temp file and read it back.
<command> > /tmp/out.txt 2>&1then read
/tmp/out.txtwith the file tool.
I can share fuller log excerpts if that helps.
Follow-up on my earlier comment: my Fedora/bash empty-output case is fixed in Kiro 1.3.11. The root cause was systemd's OSC 3008 hook as a second PROMPT_COMMAND entry, and 1.3.11 handles all PROMPT_COMMAND entries from its own hook now. I also poked at the foreign-OSC side on 1.3.11 with a couple of hand-made sequences: a window-title OSC with a space (printf '\e]0;my window title\a'; echo AFTER) and an OSC-697-style one both got stripped cleanly, no stray characters leaking into the captured output. That's only synthetic sequences, not a real Amazon Q / fig setup, so I can't speak to that pipeline specifically, but the basic OSC-with-space stripping looks fine on my end now. If anyone here is on Linux/bash, 1.3.11 is worth a re-test.
This issue has been fixed in v2.13.2 (released August 18, 2026).
Fix: Output from tools and shell commands can no longer corrupt the UI with terminal escape sequences.
Changelog entry: 20260818-1939-security
This was a security fix. Please upgrade to the latest version immediately. If you're still seeing this behavior after upgrading, please open a new issue with your version and a link back to this issue.