[BUG] bash commands broken in 0.2.39+

Resolved 💬 23 comments Opened Mar 25, 2025 by hyperknot Closed Apr 25, 2025
💡 Likely answer: A maintainer (wolffiex, collaborator) responded on this thread — see the highlighted reply below.

My previous issue got closed as fixed, but the fix is not working. Even latest versions cannot run bash commands for me.

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 0.2.53 (Claude Code)
  • Operating System: macOS 15.3.1
  • Terminal: iterm2

Bug Description

The 0.2.39 broke bash command running, it waits forever before running the commands. Every version since is broken.

Bash(pnpm typecheck)…

✽ Doing… (65s · esc to interrupt)

Steps to Reproduce

  1. Ask to run some harmless bash command like pnpm typecheck in my case.

Expected Behavior

Ask and run

Actual Behavior

Not asking and stalling

The only current way to fix it is to disable autoupdate and revert to 0.2.38

claude config set -g autoUpdaterStatus disabled
npm -g install @anthropic-ai/claude-code@0.2.38

View original on GitHub ↗

23 Comments

reverie · 1 year ago

@hyperknot Are you able to confirm that the same specific command (pnpm typecheck) works on the old version?

hyperknot · 1 year ago

Yes, of course. It's not just this command, any bash command, even if I ask what shell is being used for example.

hyperknot · 1 year ago

https://github.com/anthropics/claude-code/issues/466#issuecomment-2746477883

When I ask it to tell me what shell I'm using, it's asking for permission to run Bash(echo $SHELL), but then it doesn't do anything, keeps waiting infinitely.
wolffiex collaborator · 1 year ago

hi @hyperknot we changed how find the bash or zsh executable around 0.2.38
what shell are you running when you invoke claude?
are you running nix?
can you find an executable for bash or zsh that works when you run it from the command line? if so, what is the path?

hyperknot · 1 year ago

I use a standard macOS setup with homebrew bash.

brew install bash
... edit /etc/shells
chsh -s /opt/homebrew/bin/bash
echo $SHELL
/opt/homebrew/bin/bash
wolffiex collaborator · 1 year ago

thanks for the info. could you please try v0.2.49?

hyperknot · 1 year ago

Not working:

> what shell am i using?

⏺ Bash(echo $SHELL)…

✽ Deliberating… (16s · esc to interrupt)
wolffiex collaborator · 1 year ago

ok and just to confirm, the shell is broken in 0.2.39?
this is most likely a problem with the way we source your bashrc
one way to narrow this down in the latest release would be to condition the logic in your bashrc to skip sections if CLAUDECODE is set and see if there may be some specific lines in there that are causing problems

hyperknot · 1 year ago

This is my bashrc, it's almost empty.

echo '.bashrc start'

if [ -f $HOME/.bash_profile ]; then
    source $HOME/.bash_profile
fi

echo '.bashrc end'
hyperknot · 1 year ago
ok and just to confirm, the shell is broken in 0.2.39?

Yes

wolffiex collaborator · 1 year ago

ok, the change from 38->39 was to cd back to the original working directory after sourcing your bashrc
have you tried running claude from a different directory, especially not $HOME?

hyperknot · 1 year ago

I never run it from $HOME, just some project folders locally.

On 2025. Mar 25., Tue at 18:05, Adam Wolff @.***> wrote:

ok, the change from 38->39 was to cd back to the original working directory after sourcing your bashrc have you tried running claude from a different directory, especially not $HOME? — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/616#issuecomment-2751960491>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AADYVD6ILQC667U2EXXID7T2WGEGLAVCNFSM6AAAAABZXPN5G6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJRHE3DANBZGE> . You are receiving this because you were mentioned.Message ID: @.***> [image: wolffiex]wolffiex left a comment (anthropics/claude-code#616) <https://github.com/anthropics/claude-code/issues/616#issuecomment-2751960491> ok, the change from 38->39 was to cd back to the original working directory after sourcing your bashrc have you tried running claude from a different directory, especially not $HOME? — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/616#issuecomment-2751960491>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AADYVD6ILQC667U2EXXID7T2WGEGLAVCNFSM6AAAAABZXPN5G6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONJRHE3DANBZGE> . You are receiving this because you were mentioned.Message ID: @.***>
vrogojin · 1 year ago

Any fixes here?

wolffiex collaborator · 1 year ago

yes, we have a new shell implementation that we expect to roll out today. stay tuned

hyperknot · 1 year ago

Seems to be working as of today.

hyperknot · 1 year ago

Can you confirm this was changed?

wolffiex collaborator · 1 year ago

oh yes, we have made many changes here. if you see new issues, please let us know!

bf4 · 1 year ago

Any way we can opt-in to the old behavior?

I've been trying to debug my osx bash ~/.bash_profile -> ~/.bashrc -> ~/.profile configuration and what's changed and haven't had success even figuring out what the error is. Claude just says "Error'. 0.2.38 is the last version which I can use which can make bash shell commands. claude 1.0.3 etc and read and write file, but not execute shell commands, and it can't tell me what's wrong. I've even tried just logging everything like

ANTHROPIC_LOG=debug DEBUG=true ~/.claude/local/claude --verbose --debug -p "print the output of the PATH environmental variable to PLAN_DEBUG.md"

but I don't get anything useful. I've stepped through my dotfiles exhaustively and haven't yet figured out what changed after 0.2.38 which makes claude say: "I need permission to use the Bash tool. Could you grant me Bash permissions so I can retrieve the PATH environment variable and save it to PLAN_DEBUG.md?"

I'll open a support case as well, but want to 👍 I've been working around this for a while as well as trying to debug it and wonder if I can just opt in to the old behavior and profit.

Here's my hack to opt myself out

  1. in my .profile, .zshrc, .bash_profile, .bashrc
if [ "${CLAUDE_DOTFILES:-}" != "" ]; then
  return
fi
  1. alias claude="CLAUDE_DOTFILES=true ~/.claude/local/claude"

<Details>

<Summary>

I asked claude to review diff the 0.2.38 to 0.2.39 npm packages for bash profile changes

</Summary>

⏺ Based on my examination of the patch, I can identify a significant
change in how Claude Code handles shell initialization and
environment. The key changes are related to shell profile sourcing.

Here's a prettified JavaScript diff showing the changes:

  class Y6 {
    // ... other class methods ...

    constructor(I, G) {
      this.binShell = this.findSuitableShell();
      this.shell = IM4(this.binShell, ["-l"], {
        stdio: ["pipe", "pipe", "pipe"],
        cwd: I,
        env: {
          ...process.env,
          SHELL: this.binShell,
          GIT_EDITOR: "true"
        }
      });
      G0("persistent_shell_spawn_success", { has_shell_pid:
  Boolean(this.shell.pid) });
      this.cwd = I;
      this.shell.on("exit", (B, w) => this.onExit(B, w));

      let Z = Math.floor(Math.random() * 65536).toString(16).padStart(4,
   "0");
      this.files = {
        status: new NP(Z, "status"),
        stdout: new NP(Z, "stdout"),
        stderr: new NP(Z, "stderr"),
        cwd: new NP(Z, "cwd")
      };
      this.cwd = I;
      this.cwdDirty = false;
      this.files.cwd.write(I);

  +   let W = this.getConfigFile(this.binShell);
  +   if (Ys1(W) && !G)
  +     this.sendToShell(`source ${W} && cd ${I}`);
    }

  + getConfigFile(I) {
  +   let G = I.includes("zsh") ? ".zshrc" :
  +           this.binShell.includes("bash") ? ".bashrc" :
  +           ".profile";
  +   return WM4(tv4(), G);
  + }

    findSuitableShell() {
      // ... shell detection code ...
    }
  }

The key changes in version 0.2.38 are:

  1. A new getConfigFile() method that detects the appropriate shell

configuration file based on the shell type:

  • .zshrc for zsh
  • .bashrc for bash
  • .profile for other shells
  1. During shell initialization, Claude Code now explicitly sources the

user's shell profile file with:
this.sendToShell(source ${W} && cd ${I});

This is a significant improvement because:

  1. Previous versions did not properly source user shell configuration

files, which meant that:

  • Custom aliases
  • User-defined environment variables
  • PATH modifications
  • Shell functions

...defined in .bashrc or .zshrc were not available to commands
executed through Claude Code.

  1. Now, the CLI creates a proper login shell environment that matches

what users would have in their regular terminal, ensuring consistency
between Claude-executed commands and commands run directly in the
terminal.

This change improves the user experience by making Claude Code work
more seamlessly with the user's existing shell setup and environment.

</Details>

wolffiex collaborator · 1 year ago

Sorry that you are stuck. We removed the old functionality so there's no easy way to opt out. You can condition the logic in your dotfiles on the existence or truth of the CLAUDE_CODE env var. If you are able to track down the issue I'll be happy to fix it in the product. What shell do you use to invoke claude code?

bf4 · 1 year ago

@wolffiex Thanks for the quick response. I know this was a bit of issue necromancy... I use bash 4, installed via homebrew on a recent m1 osx. Now that I've isolated it to some effect of sourcing my dotfiles, I can isolate it further.. but since I have something working now, it's less urgent, and more curiosity and being a good OSS citizen :)

bf4 · 1 year ago

@wolffiex I can make a new issue at this point. I isolated it to

_source_if_exists() {
  [ -f "$1" ] && source "$1"
}

# brew install bash_completion
# Homebrew's own bash completion script has been installed to
#   /opt/homebrew/etc/bash_completion.d
#
#   Bash completion has been installed to:
#     /opt/homebrew/etc/bash_completion.d
_source_if_exists "$(brew --prefix)/etc/bash_completion"

and then I further isolated it and determined the fix was to change that line to

_source_if_exists "$(brew --prefix)/etc/profile.d/bash_completion.sh"

some more info in https://gist.github.com/bf4/2d45489f044d3ec2ccaae528e5e98088

wolffiex collaborator · 1 year ago

wow, thank you for tracking this down @bf4 ! I'll make our shell startup logic more robust to config script errors

github-actions[bot] · 11 months ago

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.