claude-code - 💡(How to fix) Fix [BUG] CLAUDE_ENV_FILE variables not available in Bash on resumed sessions (--continue/--resume) [2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52774Fetched 2026-04-25 06:21:19
View on GitHub
Comments
2
Participants
1
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×5commented ×2closed ×1

Error Message

Error Messages/Logs

Root Cause

This was previously reported in #12418, which was auto-closed as a duplicate of #11649. However, #11649 is a different bug (plugins not receiving CLAUDE_ENV_FILE at all). The resume-session issue is a separate root cause and was not addressed by the fix for #11649.

Code Example

$ echo $HOOK_TEST
hello_from_hook     ← ✓ works

---

$ echo $HOOK_TEST
                    ← ✗ empty

---

$ cat /Users/.../.claude/session-env/<session-id>/sessionstart-hook-0.sh
export HOOK_TEST=hello_from_hook

---

{
     "hooks": {
       "SessionStart": [
         {
           "matcher": "",
           "hooks": [
             {
               "type": "command",
               "command": "echo 'export HOOK_TEST=hello_from_hook' >> \"$CLAUDE_ENV_FILE\""
             }
           ]
         }
       ]
     }
   }
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Environment variables written to CLAUDE_ENV_FILE during a SessionStart hook are available in Bash tool calls on fresh sessions, but not on resumed sessions (--continue, --resume, /resume).

The hook executes successfully in both cases — the env file is written with correct content — but the file is not re-sourced into the Bash environment on resume.

This was previously reported in #12418, which was auto-closed as a duplicate of #11649. However, #11649 is a different bug (plugins not receiving CLAUDE_ENV_FILE at all). The resume-session issue is a separate root cause and was not addressed by the fix for #11649.

What Should Happen?

Variables written to CLAUDE_ENV_FILE during SessionStart hooks should be available in all subsequent Bash tool calls, regardless of whether the session is fresh or resumed.

Error Messages/Logs

Fresh session:

$ echo $HOOK_TEST
hello_from_hook     ← ✓ works

Resumed session:

$ echo $HOOK_TEST
                    ← ✗ empty

The env file exists and has the correct content in both cases:

$ cat /Users/.../.claude/session-env/<session-id>/sessionstart-hook-0.sh
export HOOK_TEST=hello_from_hook

Steps to Reproduce

  1. Add a SessionStart hook to .claude/settings.local.json:
    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": "echo 'export HOOK_TEST=hello_from_hook' >> \"$CLAUDE_ENV_FILE\""
              }
            ]
          }
        ]
      }
    }
  2. Start a fresh session: claude
  3. Run echo $HOOK_TEST → outputs hello_from_hook
  4. Exit and resume: claude --continue
  5. Run echo $HOOK_TEST → outputs empty string ✗

Claude Model

Opus

Is this a regression?

I don't know

Claude Code Version

2.1.119 (Claude Code)

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

  • The SessionStart hook runs on resume (confirmed by writing a debug log to /tmp).
  • CLAUDE_PROJECT_DIR and CLAUDE_ENV_FILE are both available inside the hook during resume.
  • The env file is written correctly — the issue is that it's not sourced into the Bash tool environment after resume.
  • #12418 was auto-closed as duplicate of #11649, but they are different bugs: #11649 was about CLAUDE_ENV_FILE not being set for plugin-installed hooks; this is about the env file not being sourced on resumed sessions regardless of hook source.

extent analysis

TL;DR

The issue can be fixed by ensuring the CLAUDE_ENV_FILE is sourced into the Bash environment after a session is resumed.

Guidance

  • Verify that the SessionStart hook is executing correctly on resume by checking the debug log written to /tmp.
  • Check if the CLAUDE_ENV_FILE is being overwritten or modified after the SessionStart hook runs on resume.
  • Consider adding a command to the SessionStart hook to source the CLAUDE_ENV_FILE explicitly, e.g., source $CLAUDE_ENV_FILE.
  • Investigate if there are any differences in how the Bash environment is initialized between fresh and resumed sessions.

Example

# Add this to the SessionStart hook command
source "$CLAUDE_ENV_FILE"

Notes

The issue seems to be related to how the Bash environment is handled on resumed sessions. The fact that the SessionStart hook runs correctly on resume, but the env file is not sourced, suggests that there might be a specific issue with how the environment is initialized or updated on resume.

Recommendation

Apply a workaround by adding a command to the SessionStart hook to source the CLAUDE_ENV_FILE explicitly, as this will ensure that the environment variables are available in the Bash environment after a session is resumed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] CLAUDE_ENV_FILE variables not available in Bash on resumed sessions (--continue/--resume) [2 comments, 1 participants]