{
  "id": 18215955,
  "title": "Claude Code Env Vars Don't Persist: 3 of 80 Runs Fell Back to Prod",
  "url": "https://urgent.news/2026/11/05/claude-code-env-vars-dont-persist-3-of-80-runs-fell-back-to-prod",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-05T00:43:59.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ji_ai/claude-code-env-vars-dont-persist-3-of-80-runs-fell-back-to-prod-p85"
  },
  "original_language": "en",
  "account": "Claude Code env vars do not persist between Bash tool calls, which led to inconsistencies in the results of a test run. Claude Code starts a new shell with each Bash tool call, so any environment variables held in memory are lost. The only thing that persists across calls is the working directory.\n\nTo make Claude Code env vars persist, you can set them before the session starts. For plain values, add them to the settings.json file. For virtual environments, use a SessionStart hook to write the activation command and environment variables to a $CLAUDE_ENV_FILE file that is sourced by every subsequent Bash call. Alternatively, you can set the CLAUDE_ENV_FILE environment variable to a file containing the activation command and variables, and launch Claude from that file.",
  "summary": "I told Claude Code export APP_ENV=staging . My next message said to run the script. It printed target = production . Nothing got deployed. target.py is a one-line stub in a throwaway repo, built around os.environ.get(\"APP_ENV\", \"production\") , a default you've probably seen in real code. But Claude Code env vars don't persist between Bash tool calls, and I wanted to know how often that actually…",
  "key_points": [
    "Claude Code env vars not persisted between Bash calls",
    "New shell starts with each Bash tool call",
    "Only working directory persists across calls"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}