Shell spawned as non-login shell, missing PATH from .zprofile/.bash_profile

Resolved 💬 3 comments Opened Apr 4, 2026 by KeiYoshio Closed Apr 8, 2026

Problem

Claude Code spawns shells in non-login mode. On macOS, this means ~/.zprofile (zsh) and ~/.bash_profile (bash) are not sourced, so environment variables set there — most notably PATH — are missing.

This is a common source of confusion: commands that work fine in Terminal.app or iTerm2 (which default to login shells) fail in Claude Code with "command not found".

Reproduction

  1. Install any tool via Homebrew (e.g. brew install gauche)
  2. Confirm it works in Terminal: gosh -V → works
  3. In Claude Code, run the same command → gosh not found
  4. Check PATH in Claude Code: only /usr/bin:/bin:/usr/sbin:/sbin

Root cause

Homebrew's installer writes eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile by default. This is the standard macOS convention — login-time environment setup goes in .zprofile/.bash_profile, not .zshrc/.bashrc.

macOS terminal emulators (Terminal.app, iTerm2, Ghostty, etc.) all default to spawning login shells for this reason.

Claude Code spawns a non-login shell, so .zprofile is never read.

Impact

This affects not just Homebrew, but any tool that follows the standard macOS convention:

  • Homebrew (/opt/homebrew/bin)
  • pyenv / nvm / rbenv (often initialized in .zprofile)
  • cargo / go / other language toolchains

Users must manually duplicate their .zprofile setup into .zshrc as a workaround.

Expected behavior

Claude Code should spawn login shells (or equivalent) on macOS so that the user's full environment is available, consistent with how terminal emulators behave.

Workaround

Add the following to ~/.zshrc:

if [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then
  eval "$(/opt/homebrew/bin/brew shellenv)"
fi

Environment

  • macOS (Apple Silicon)
  • Shell: zsh
  • Claude Code (CLI)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗