settings.json env vars not propagated to background (bg-spare) session processes

Status Fixed / completed
Maintainer reply None cached
Activity 2 comments · opened Sep 3, 2026 · closed Sep 3, 2026

Description
Environment variables intended to control subagent model selection (CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE) are not inherited by background job worker processes (claude bg-spare --bg-spare ...), even when correctly present in the parent daemon's environment. This was reproduced using claude agents view.

Steps to reproduce

  1. Export CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 and CLAUDE_CODE_SUBAGENT_MODEL=<model> in shell profile (e.g. .zshrc).
  2. Restart the Claude Code daemon (claude daemon run ...) so it picks up the new shell env — confirmed via ps eww <daemon-pid> that the daemon process itself has both vars set correctly.
  3. Start any background session/job (dispatched via the background agent daemon, spawned as claude bg-spare --bg-spare <socket>).
  4. Inside that background session, run env | grep -i SUBAGENT.

Expected: the bg-spare child process inherits the daemon's environment, including these two vars.
Actual: env | grep -i SUBAGENT returns nothing — confirmed both via the shell builtin inside the session and via ps eww <bg-spare-pid> from outside. The vars are present on the daemon (parent) but absent on the bg-spare (child) it spawns.

Impact: settings.json's top-level env block (and exported shell env picked up by the daemon) cannot reliably control subagent model selection for any session started as a background job — only genuinely foreground-launched sessions may be unaffected (untested).

Environment: macOS (Darwin 25.6.0), Claude Code CLI, daemon-managed background sessions (bg-spare architecture).

View original on GitHub ↗

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