en.killbait.com
Claude Code's Shell Command Issues on macOS: Understanding the BSD vs. GNU Toolchain Conflict
The article discusses a common issue faced by macOS users who utilize Claude Code, an AI-powered coding assistant. The core problem is that Claude Code generates shell commands that fail on macOS due to fundamental differences between macOS's BSD-based toolchain and the GNU tools assumed by most shell examples. The author explains two primary reasons for this issue: first, Claude Code's 'Bash' tool actually runs the user's login shell (zsh on macOS since Catalina), not bash, causing subtle command behavior differences; second, macOS uses BSD versions of standard tools (like sed, date, and stat) rather than GNU versions, which have different syntax and options. The article details how common commands like 'sed -i' behave differently on BSD versus GNU systems, often leaving behind backup files or causing errors. The author provides a practical solution involving environment variables (CLAUDE_CODE_SHELL and CLAUDE_ENV_FILE) to force the use of GNU tools through Homebrew's coreutils package. This solution allows users to maintain their existing shell environment while ensuring Claude Code functions correctly with GNU tool syntax. The article concludes by noting that these issues are not due to Claude Code's limitations but rather the macOS environment, and that a simple two-minute fix resolves the problem. The author has created a GitHub repository with a plugin to automate this configuration for users.