[BUG] CLAUDE_CONFIG_DIR environment variable behavior unclear - still creates local .claude/ directories
Environment
- Platform (select one):
- Anthropic API
- AWS Bedrock
- Google Vertex AI
- Other:
- Claude CLI version: Latest
- Operating System: Linux
- Terminal: bash
### Bug Description
I have the CLAUDE_CONFIG_DIR environment variable set to centralize Claude Code configuration, but Claude Code still creates local .claude/ directories in individual workspaces. The purpose and expected behavior of CLAUDE_CONFIG_DIR is unclear since it's not documented in the official documentation.
Steps to Reproduce
- Set CLAUDE_CONFIG_DIR=/path/to/global/claude/config environment variable
- Start Claude Code session in a workspace directory
- Use Claude Code tools that require permissions (e.g., Bash commands)
- Observe that a local .claude/settings.local.json file is created in the workspace
### Expected Behavior
It's unclear what the expected behavior should be since CLAUDE_CONFIG_DIR is not documented. Possible expectations:
- All configuration centralized: CLAUDE_CONFIG_DIR should prevent any local .claude/ directories from being created
- Hybrid approach: Global config in CLAUDE_CONFIG_DIR, workspace-specific settings still stored locally
- Different purpose: CLAUDE_CONFIG_DIR serves a different purpose than local settings
### Actual Behavior
Despite having CLAUDE_CONFIG_DIR set, Claude Code creates both:
- Global configuration in $CLAUDE_CONFIG_DIR/:
/mnt/bn/xxx/.claude/
├── .claude.json
├── .claude.json.backup
├── .credentials.json
├── projects/
├── shell-snapshots/
├── statsig/
└── todos/
- Local workspace configuration:
/opt/tiger/aiic_verl/.claude/
└── settings.local.json
### Additional Context
- The CLAUDE_CONFIG_DIR environment variable is not mentioned in the official documentation:
- https://docs.anthropic.com/en/docs/claude-code/settings
- https://docs.anthropic.com/en/docs/claude-code/cli-reference
- This makes it impossible to determine if the current behavior is a bug or intended functionality
- Would appreciate clarification on the purpose of this environment variable and whether it should be documented
Request: Could you please document the purpose and behavior of CLAUDE_CONFIG_DIR and clarify whether creating both global and local config directories is the intended behavior?
7 Comments
CLAUDE_CONFIG_DIR seems to work for me in all cases, aside from with the vscode ide. I'm getting the .claude/ide folder created regardless of whether this is set.
Hi, the current behavior of Claude Code with
CLAUDE_CONFIG_DIRactually works quite well for XDG Base Directory compliance, but I believe the naming and documentation could be clarified. Here's what I'd propose:Current Behavior (which I think is mostly correct!)
~/.config/claude-code/- this is the correct location per XDG spec and allows version control~/.claude/) can be relocated via$CLAUDE_CONFIG_DIRto follow XDG conventions (e.g.,~/.local/state/claude-code/).claude/settings.local.json) remain in project directories - this is correct for project-scoped configuration~/.claude.jsonis hardcoded to the home directory and is not affected byCLAUDE_CONFIG_DIRThis separation is actually quite good and follows best practices, though the
.claude.jsonlocation is problematic.Proposed Improvements
1. Rename the environment variable
CLAUDE_CONFIG_DIR→CLAUDE_STATE_DIRThis better reflects what it actually controls: runtime state, not user configuration. The XDG Base Directory spec distinguishes between:
$XDG_CONFIG_HOME(default:~/.config) - user configuration files that should be preserved$XDG_STATE_HOME(default:~/.local/state) - state data that can be regenerated but contains valuable user-specific stateWhat
CLAUDE_CONFIG_DIRcurrently relocates (history, projects, shell-snapshots, statsig, etc.) clearly fits the "state" category per XDG.2. Move
settings.jsonto the config directoryCurrently
settings.jsonlives in the state directory (~/.claude/settings.json), but it should live in~/.config/claude-code/settings.jsonalongside other user configuration files (skills, agents, commands). Thesettings.jsonfile contains user preferences and configuration that should be:This is configuration, not state.
3. Make
~/.claude.jsonrespectCLAUDE_STATE_DIRCurrently,
~/.claude.jsonis hardcoded to the home directory and doesn't respectCLAUDE_CONFIG_DIR. This file contains:This is clearly state data (especially the auth tokens and project history), so it should be relocatable to
$CLAUDE_STATE_DIR/claude.json(without the leading dot, since it's no longer in~/).Proposed structure:
4. Document the intended behavior
Please officially document:
CLAUDE_STATE_DIR(or keepCLAUDE_CONFIG_DIRif you prefer that name)~/.claude.json→$CLAUDE_STATE_DIR/claude.json)~/.config/claude-code/).claude/directories are intentionally not affectedsettings.jsonshould live (config directory)5. Backward compatibility
For the transition:
CLAUDE_CONFIG_DIR(deprecated) andCLAUDE_STATE_DIRwith a deprecation warningclaude.jsonin$CLAUDE_STATE_DIRfirst, fall back to~/.claude.jsonif not foundsettings.jsonfrom state to config directory with a one-time migration prompt~/.claude.jsonto$CLAUDE_STATE_DIR/claude.jsonon first run after updateWhy This Matters
XDG Base Directory compliance is important for:
~/unclutteredThe current behavior is very close to getting this right! It just needs:
CLAUDE_STATE_DIR)settings.jsonto the config directory where it belongs~/.claude.jsonrespect the state directory variable (currently hardcoded to~/)This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
the issue of "
CLAUDE_CONFIG_DIRenvironment variable behavior unclear" is still very much "occurring": the only mention of it i could find in the docs is literally just this: _"Customize where Claude Code stores its configuration and data files"_. if nothing else, because it leaves out the fairly important matter of.claude.jsonfile location undocumented - which is a shame, because that behaviour is... surprising, to say the least.as of v2.0.42-74, when
$CLAUDE_CONFIG_DIRis set -.claude.jsonends up in the path$CLAUDE_CONFIG_DIR/.claude.json(_contrary_ to this report above), right next tosettings.json,.credentials.json, etc., rather than in the usual$HOME/.claude.jsonwhich is _outside_ of$HOME/.claude/dir, when that var is unset. that becomes outright confusing whenCLAUDE_CONFIG_DIR=$HOME/.claude, because then you end up with some systems that use$HOME/.claude.json, some use$HOME/.claude/.claude.jsonwhile they both have the rest of the files in$HOME/.claude. not what i would call a very self-consistent behaviour, which adds to the confusion cause by it being undocumented.This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.