[BUG] Terminal receiving ANSI escape codes as typed input during tool execution
Description
When Claude Code executes certain tools (particularly interactive CLI tools), ANSI escape codes appear as typed characters in the terminal input buffer, even though the user hasn't typed anything.
Environment
- OS: macOS (Darwin 24.6.0)
- Claude Code: Running in terminal
- Shell: bash/zsh (standard macOS terminal)
Symptoms
Random characters appearing in the terminal input while Claude is "thinking" or executing tools, such as:
[33;197R- Other ANSI escape sequences
These codes appear to be cursor position queries (CSI 6 n) responses from the terminal.
Reproduction Steps
- Start Claude Code in an interactive terminal session
- Execute a command that triggers interactive CLI tools (e.g.,
jira view TICKET-123) - Observe ANSI escape codes appearing in the terminal input buffer while Claude processes the request
Example Session
User: You have access to my local environment. Read my jira authentication details from ~/.jira.d/config.yml and use them to call the Jira API and retrieve the data for this ticket
Assistant: [executes jira view command]
Terminal input buffer receives: [33;197R [other escape codes]
Root Cause
Interactive CLI tools (like the Jira CLI) send cursor position queries to the terminal:
- Tool sends:
ESC[6n(query cursor position) - Terminal responds:
ESC[{row};{col}R - Response codes leak into the input buffer instead of being consumed by the tool
Expected Behavior
ANSI escape code responses should be consumed by the tool making the query, not leaked to the user's input buffer.
Actual Behavior
Escape codes appear as typed characters in the terminal, polluting the input buffer.
Workaround
- Use
resetcommand to clear terminal state - Use Ctrl+C to clear input buffer
- Prefer non-interactive tools (e.g., use REST APIs with
curlinstead of interactive CLIs)
Impact
- Confusing user experience (appears like random typing)
- Input buffer pollution
- May interfere with subsequent commands
Related
This appears to be related to how Claude Code handles stdin/stdout when spawning subprocesses that query terminal capabilities.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗