Urgent.News

What's breaking now, across thousands of outlets.

AI

Why Claude Code keeps writing shell commands that fail on your Mac

Disclaimer: AI helped me write this since I am not that good with words :) Claude wrote this, mid-task, while refactoring something unrelated: sed -i 's/old/new/' config.yml It's correct. It's the form you'll find in almost every StackOverflow answer, every blog post, every Dockerfile. It exited 0. And it left a file called config.yml-e sitting in my repo, because on macOS that command means…

Claude Code, an AI assistant, has been writing shell commands that fail on Mac systems. This issue occurs because the Bash tool used by Claude Code is not the default Bash on macOS, but rather the zsh shell. This mismatch between the expected and actual shell behavior leads to unexpected errors and incorrect command execution.

There are two primary reasons behind this issue. First, the Bash tool runs commands using the login shell, which is zsh on macOS since Catalina. This means that the command-line tools and options Claude Code uses may behave differently than expected. For example, the `rm -f` command behaves differently in zsh compared to bash, leading to non-zero exit codes and potential errors.

Second, Claude Code assumes GNU versions of standard tools, such as `sed` and `date`, while macOS ships with BSD versions. This discrepancy causes issues when executing commands like `sed -i s/a/b/ file`, as GNU sed is expected but BSD sed behaves differently. In the case of `sed -i`, the tool creates a backup file with a different suffix and performs the substitution, which is not the intended behavior on macOS.

To resolve these issues, two solutions have been documented. First, the `CLAUDE_CODE_SHELL` environment variable can be set to `bash` in the Claude Code settings.json file. This ensures that Claude Code uses the default Homebrew Bash installation instead of the zsh login shell. Additionally, the `CLAUDE_ENV_FILE` environment variable can be used to append shell statements, such as modifying the PATH to include GNU versions of tools like `coreutils`, `findutils`, `gnu-sed`, `gnu-awk`, `gnu-tar`, `gnu-which`, and `grep`. This allows Claude Code to use the correct GNU tools while still operating within the zsh shell.

By implementing these fixes, users can avoid the frequent failures and confusion caused by Claude Code's shell commands on Mac systems, ensuring a smoother and more reliable coding experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Is the AI industry really ready to slow down?

On Equity, we debated whether Ai executives are serious about wanting to slow down.

  • Anthropic's Dario Amodei proposes AI development pacing plan
  • Nvidia CEO Jensen Huang dismisses AI backlash concerns as hoax
  • AI safety advocates emphasize need for third-party evaluators and international coordination

JEV assisted LLM Trading

We gave our LLM trading bot an auditor that never sees the chart Every hour, on the hour, a vision model looks at three forex charts and decides whether our bot should buy, sell, or sit out.

  • Geminisnapflash is a Python trading bot making hourly forex decisions.
  • JEV, a System-One model, grades the bot's directional calls for consistency.
  • JEV's verdict is recorded and compared with the bot's actual trade direction.

More from Sunday 20 September →