[BUG] Bash commands always timeout after 2 minutes despite successful completion
Resolved 💬 16 comments Opened Jul 14, 2025 by gaolbreaker Closed Mar 7, 2026
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.51
- Operating System: macOS 14.6.1
- Terminal: Terminal App
Bug Description
All bash commands executed through both the Bash tool and ! syntax consistently timeout after 2 minutes, even when the commands complete successfully and produce output. The actual commands work fine - the issue appears to be with shell session cleanup/termination detection.
Steps to Reproduce
- Execute any bash command (e.g., echo "test", ls, pwd)
- Command executes successfully and produces expected output
- Wait 2 minutes
- Receive timeout error despite successful execution
Expected Behavior
Commands should complete immediately after execution without timeout errors.
Actual Behavior
Command timed out after 2m 0.0s
Agent pid 52450
[command output here - shows command actually worked]
Additional Context
- Cannot effectively use bash commands interactively
- Affects both programmatic Bash tool usage and manual ! commands
sudo claudeseems to not have this problem
<img width="741" height="137" alt="Image" src="https://github.com/user-attachments/assets/eb11292c-7d8b-44dd-a081-0f750a7dbd44" />
16 Comments
I second this - also been getting this issue - the bash command succeeds right away (I can see a new file created for example) but then proceeds to wait 2 min until timeout before moving on
Using
sudo claude"fixes" the issue, but will cause other permission issues. Reference:Another workaround which doesn't need
sudousage: installingclaudeusing homebrew.i also have this issue and installed using brew so that's not the solution.
May be you can try different $SHELL.
For me, I use this cmd to run claude and it works.
yes, this worked for me. thanks.
I'm having exactly the same symptoms. Every shell command executed 'successfully' runs but claude takes the full 2 minute default timeout to notice and react.
Executing via
SHELL=/bin/bash claudeorSHELL=/bin/zsh claudeworks for me as well.My default login shell is bash 5.3.3 installed via homebrew at
/opt/homebrew/bin/bash.This is a symlink.
I installed claude via the official instructions AFAICT with the small caveat that I have a wrapper that adds the keg only node@18 brew path:
---
It feels like there's zero chance that this is the issue for anyone else but what I noticed is that claude executes my shell in a context that executes my .bashrc.
My .bashrc has a coproc that it starts which does some things.
Making it so that that coproc only starts when stdout is a tty (
[[ -t 0 ]]) makes it so that the shell exit is noticed immediately. Presumably this is because claude is waiting for the whole process tree to exit for some reason.This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue is still occurring, can't believe it's not fixed yet
The buck occurs for me as well, but only when the sandbox is enabled. What's really strange is that it also occurs when I enable the sandbox and I exclude dotnet from the sandbox via excludedCommands.
This bug is still present for me on version 2.0.73 and on MacOS 14.8.3
This actually works for me
UPDATE: Root cause identified - background processes in shell config
I've identified the root cause of this issue in my setup.
The Problem
I had this line in my
.bash_profile:This spawns a background
ssh-agentprocess on every shell invocation. When Claude Code runs a bash command:ssh-agentremains running as a background processssh-agentnever terminates → 2 minute timeoutThe Fix
Replaced the unconditional ssh-agent invocation with:
This prevents ssh-agent from spawning in non-interactive shells.
Result
After this change, bash commands in Claude Code complete immediately without timeout.
Why the
SHELL=/usr/bin/zshworkaround workedLaunching with
SHELL=/usr/bin/zsh claudebypassed my bash profile entirely, avoiding the ssh-agent spawn.Environment
This may help others diagnose similar issues related to background processes in shell configurations.
I was still facing issues with some CLI tools, e.g.
dotnet buildwas waiting for bash timeouts.The shell workaround didn't work for me. I narrowed my issue down to
.profileand.zlogin(impacting both, bash & ZSH shells) having this RVM setup:[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"Moving this from
.profile/.zprofile/.zloginto.zshrcfixed the issue for me.---
This change does break the RVM shell function within Claude Code. You can instruct Claude Code to use one of these workarounds for RVM:
``
shell
``unset -f rvm && source "$HOME/.rvm/scripts/rvm" && rvm --version
``
shell
``~/.rvm/bin/rvm --version
Spent a while debugging this, and finally found the culprit in my case — a chpwd() hook in my .zshrc that runs eza after every cd (auto-ls). Claude Code snapshots your shell environment at startup, including functions. So every command that involves a cd triggered eza as a child process, and since CC waits for all child FDs to close, every single command hangs — not just builds, even git status.
Removing the chpwd hook fixed everything completely. No wrappers needed.
This would affect anyone with an auto-ls-on-cd setup in their shell (pretty common in dotfiles). More generally, avoid shell hooks (chpwd, precmd, preexec) that spawn external processes — CC snapshots and replays them in its non-interactive shell.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.