claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Bash commands always timeout after 2 minutes despite successful completion

Open gaolbreaker opened this issue 9 months ago • 12 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • 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

  1. Execute any bash command (e.g., echo "test", ls, pwd)
  2. Command executes successfully and produces expected output
  3. Wait 2 minutes
  4. 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 claude seems to not have this problem
Image

gaolbreaker avatar Jul 14 '25 20:07 gaolbreaker

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

mjbarton712 avatar Aug 05 '25 15:08 mjbarton712

Using sudo claude "fixes" the issue, but will cause other permission issues. Reference:

note that sudo claude seems to help with this, at the cost of messing up other operations (commits get created as root for one, and then ssh-agent . I'm also using mise for node+npm, but it persisted when using fnm as well. persists when I do sudo -u $USER claude.

thanks, can confirm this allows claude to run commands (but introduces other problems caused by sudo usage)

Another workaround which doesn't need sudo usage: installing claude using homebrew.

fouadgm avatar Aug 06 '25 04:08 fouadgm

i also have this issue and installed using brew so that's not the solution.

ngzax avatar Aug 07 '25 13:08 ngzax

May be you can try different $SHELL. For me, I use this cmd to run claude and it works.

 SHELL=/usr/bin/zsh claude

wty92911 avatar Aug 23 '25 04:08 wty92911

yes, this worked for me. thanks.

ngzax avatar Aug 29 '25 15:08 ngzax

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 claude or SHELL=/bin/zsh claude works 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.

$ ls -lA $SHELL                                                                                                                         │
lrwxr-xr-x 1 tim.visher admin 29 Sep  4 15:48 /opt/homebrew/bin/bash -> ../Cellar/bash/5.3.3/bin/bash*

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:

$ claude --version
1.0.128 (Claude Code)

$ type claude
claude is hashed (/Users/tim.visher/.config/timvisher/ide/bash/bin/claude)

$ nl "$(type -p claude)"
     1  #!/usr/bin/env bash

     2  p=$(brew --prefix)

     3  export PATH="${p}/opt/node@18/bin:$PATH"

     4  exec "${p}/bin/claude" "$@"

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.

timvisher-dd avatar Sep 29 '25 16:09 timvisher-dd

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.

github-actions[bot] avatar Dec 09 '25 10:12 github-actions[bot]

This issue is still occurring, can't believe it's not fixed yet

jgoyvaerts avatar Dec 12 '25 23:12 jgoyvaerts

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.

pluggy avatar Dec 15 '25 20:12 pluggy

This bug is still present for me on version 2.0.73 and on MacOS 14.8.3

gaolbreaker avatar Dec 19 '25 20:12 gaolbreaker

May be you can try different $SHELL. For me, I use this cmd to run claude and it works.

SHELL=/usr/bin/zsh claude

This actually works for me

gaolbreaker avatar Dec 19 '25 20:12 gaolbreaker

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:

eval $(ssh-agent)

This spawns a background ssh-agent process on every shell invocation. When Claude Code runs a bash command:

  1. The command completes immediately and produces correct output
  2. The bash shell exits
  3. But ssh-agent remains running as a background process
  4. Claude Code waits for all child processes to terminate
  5. ssh-agent never terminates → 2 minute timeout

The Fix

Replaced the unconditional ssh-agent invocation with:

# Only start ssh-agent if not already running and in interactive shell
if [ -z "$SSH_AUTH_SOCK" ] && [ -n "$PS1" ]; then
    eval "$(ssh-agent -s)" > /dev/null
fi

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/zsh workaround worked

Launching with SHELL=/usr/bin/zsh claude bypassed my bash profile entirely, avoiding the ssh-agent spawn.

Environment

  • Claude Code version: 2.0.73 (native install)
  • macOS: 14.8.3
  • Shell: bash

This may help others diagnose similar issues related to background processes in shell configurations.

gaolbreaker avatar Dec 19 '25 21:12 gaolbreaker