Support persistent environment variables across Bash calls

Resolved 💬 4 comments Opened Dec 11, 2025 by bukzor Closed Feb 14, 2026

Summary

Provide a mechanism for Claude to set environment variables that persist across Bash() tool calls within a session.

Use Case

Multi-step workflows need to maintain state:

# Step 1: Initialize
GIT_INDEX=$(mktemp)
# Step 2 (later Bash call): Use it
git --index-file=$GIT_INDEX ...  # GIT_INDEX is gone

Currently each Bash() call is a fresh subprocess with no way to carry state forward except via files.

Current Workaround (Linux-only)

We discovered that appending to the session's shell snapshot file (~/.claude/shell-snapshots/snapshot-*.sh) persists variables, since it's sourced before each Bash() call:

# Find snapshot via SID
sid=$(cut -d' ' -f6 /proc/self/stat)
snapshot=$(ps -o cmd= --sid "$sid" | sed -n 's/.*source \([^ ]*snapshot[^ ]*\.sh\).*/\1/p')
# Append export
echo "export MY_VAR=value" >> "$snapshot"

This works but is fragile and Linux-only.

Suggested Implementation

Either:

  1. Parse simple exports: Recognize export VAR=value in Bash output and persist it
  2. Dedicated command: claude-env set VAR=value
  3. Document the snapshot mechanism: If it's intended to be stable, document it

Option 1 aligns with shell semantics and requires no new syntax.

View original on GitHub ↗

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