[DOCS] Environment variables don't persist between bash commands - documentation inconsistency
Resolved 💬 9 comments Opened Jun 24, 2025 by isCopyman Closed Dec 2, 2025
Environment
- Platform: Anthropic API
- Claude CLI version: Latest
- Operating System: Windows + VS Code SSH + Docker Desktop Ubuntu container
- Terminal: bash
Documentation Issue
The bash tool documentation at https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool#example-usage states:
How it works The bash tool maintains a persistent session: 1. Claude determines what command to run 2. You execute the command in a bash shell 3. Return the output (stdout and stderr) to Claude 4. Session state persists between commands (environment variables, working directory)
However, testing shows that environment variables do NOT persist between bash tool calls.
Verification Tests
Test 1: Basic environment variable
# Command 1
export TEST_VAR="test_value"
echo "Variable set: $TEST_VAR"
# Output: Variable set: test_value
# Command 2
echo "Variable in next command: '$TEST_VAR'"
# Output: Variable in next command: '' (empty)
Test 2: PYTHONPATH (real-world scenario)
# Command 1
export PYTHONPATH=. && python -c "import sys; print('Current dir in sys.path:', '.' in sys.path)"
# Output: Current dir in sys.path: True
# Command 2
python -c "import sys; print('Current dir in sys.path:', '.' in sys.path)"
# Output: Current dir in sys.path: False
Test 3: Working directory DOES persist (as documented)
# Command 1
mkdir testdir && cd testdir
# Command 2
pwd
# Output: /path/to/testdir ✅ (correctly persists)
Expected vs Actual Behavior
- Expected (per documentation): Environment variables persist between commands
- Actual: Environment variables are reset between commands, only working directory persists
Impact on Development Workflow
This inconsistency affects common development patterns:
- Python projects requiring
PYTHONPATHsetup - Build tools needing custom environment variables
- Development workflows expecting persistent environment state
- Users need workarounds like
export VAR=value && commandfor each bash call
Request for Clarification
Could you please clarify:
- Is the current behavior intended? (environment variables don't persist)
- If so, can the documentation be updated to reflect actual behavior?
- If this is a bug, are there plans to implement environment variable persistence?
Suggested Documentation Fix
Current text:
Session state persists between commands (environment variables, working directory)
Suggested revision:
Session state persists between commands (working directory). Environment variables need to be re-exported in each command or set permanently in shell configuration files.
Thank you for clarifying this behavior\!"
This issue has 9 comments on GitHub. Read the full discussion on GitHub ↗