[Bug] zsh interactive: pressing Tab/Space for autocomplete triggers “Error: spawn EBADF” loop with 100% CPU

Resolved 💬 3 comments Opened Oct 20, 2025 by ekson73 Closed Oct 24, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

On macOS with zsh, Claude Code CLI interactive mode consistently falls into a tight loop of Error: spawn EBADF after typing a slash command and pressing Tab (and often Space) to trigger completion. CPU goes to ~100% and the error stack repeats until manually exiting.

  • Non-interactive usage (e.g., claude -p "...") works fine
  • Running the same interactive flow under bash works fine
  • Reproduces even in pristine zsh (env -i zsh -f), so not caused by user plugins/configs

What Should Happen?

Interactive completion should not crash or loop; no EBADF errors and no CPU spike.

Error Messages/Logs

Error: spawn EBADF
    at ChildProcess.spawn (node:internal/child_process:420:11)
    at spawn (node:child_process:753:9)
    at file:///Users/<user>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:2523
    at E40 (file:///Users/<user>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3018)
    at file:///Users/<user>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3251
    at Array.forEach (<anonymous>)
    at ChildProcess.I (file:///Users/<user>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3186)
    at ChildProcess.emit (node:events:518:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1101:16) {
  errno: -9,
  code: 'EBADF',
  syscall: 'spawn'
}

Steps to Reproduce

  1. Start a pristine zsh: env -i zsh -f
  2. Ensure claude is in PATH (Node via Volta or equivalent)
  3. Run claude (interactive mode)
  4. Type a slash command (e.g., /help) and press Tab (sometimes Space also triggers)
  5. Observe repeated spawn EBADF and CPU pegged until exit

Environment

  • OS: macOS (e.g., 14.x/15.x)
  • Shell: zsh (zsh --version)
  • Node.js: v22.20.0 (Volta-managed) [also reproduced on other Node LTS]
  • Claude Code: @anthropic-ai/claude-code v2.0.24
  • Terminal: Terminal.app / iTerm2 / Warp (issue reproduces irrespective of terminal)
  • TERM: xterm-256color

Additional attempts / mitigations tried

  • Downgraded Node (25 → 22 LTS) and reinstalled CLI → persists
  • Disabled Atuin and other zsh plugins; tested pristine zsh -f → persists
  • Set CLAUDE_DISABLE_AUTOCOMPLETE=1 → reduces impact but Tab in zsh still triggers crash loop
  • Killed stale claude/agent processes → no effect
  • Bash shell and non-interactive modes remain fine

Suspected cause

Issue appears tied to interactive completion and child process/TTY handling under zsh. Similar EBADF stacks were reported in #9428 with identical cli.js offsets (195:2523/3018/3251). Likely FD/race handling when spawning/reattaching during completion under zsh.

Workarounds that help temporarily

  • Disable zsh completion only for claude: compdef -d claude
  • Force-disable internal autocomplete when launching: CLAUDE_DISABLE_AUTOCOMPLETE=1 claude
  • Use a wrapper to run only the interactive CLI via bash: function claudei(){ /bin/bash -lc "CLAUDE_DISABLE_AUTOCOMPLETE=1 claude \"$@\""; }
  • Prefer non-interactive flags (-p, etc.) when possible

Request

  • Please investigate EBADF in zsh interactive completion path and ship a fix
  • If feasible, provide a flag to fully disable completion hooks in interactive mode under zsh as a stopgap

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.24 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗