claude-code - 💡(How to fix) Fix Agent hardcodes ~/.claude/ instead of respecting $CLAUDE_CONFIG_DIR

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…
RAW_BUFFERClick to expand / collapse

Bug Description

When the Claude Code agent needs to locate configuration files (e.g., settings.json), it defaults to searching ~/.claude/ rather than resolving $CLAUDE_CONFIG_DIR from the environment first. This happens even when $CLAUDE_CONFIG_DIR is set and the CLI itself correctly loads settings from the custom config directory.

Steps to Reproduce

  1. Set CLAUDE_CONFIG_DIR to a custom path (e.g., via direnv: export CLAUDE_CONFIG_DIR=.claude-custom)
  2. Place a settings.json in that custom config directory
  3. Start Claude Code — the CLI correctly loads settings from $CLAUDE_CONFIG_DIR (env vars defined in settings.json are present in the environment)
  4. Ask the agent to check or find your settings file
  5. The agent searches ~/.claude/settings.json and ~/.claude/ first, finds nothing, and only discovers the correct location after multiple failed attempts

Expected Behavior

The agent should resolve $CLAUDE_CONFIG_DIR from the environment before constructing any path to Claude configuration files. It should never hardcode ~/.claude/.

Actual Behavior

The agent's trained default is to look in ~/.claude/. It consistently reaches for that path first, even when $CLAUDE_CONFIG_DIR is set to something else. The CLI layer respects the variable (settings load correctly), but the agent layer does not use it when reasoning about where config files live.

Environment

  • macOS (Darwin 25.4.0)
  • $CLAUDE_CONFIG_DIR set via direnv
  • Claude Code installed via Homebrew
  • Model: Opus 4.6 (1M context)

Additional Context

This is a systemic issue — the agent repeatedly defaults to ~/.claude/ across multiple conversations despite explicit user correction and saved memory entries instructing it to resolve $CLAUDE_CONFIG_DIR first. The problem appears to be in the model's trained prior, which strongly associates Claude config with ~/.claude/. The system prompt or agent scaffolding could mitigate this by injecting the resolved $CLAUDE_CONFIG_DIR value into the agent's context.

extent analysis

TL;DR

The agent should be modified to prioritize resolving $CLAUDE_CONFIG_DIR from the environment before searching for configuration files, rather than defaulting to ~/.claude/.

Guidance

  • Verify that the $CLAUDE_CONFIG_DIR environment variable is correctly set and exported in the environment where the Claude Code agent is running.
  • Consider modifying the agent's initialization to explicitly inject the resolved $CLAUDE_CONFIG_DIR value into its context, ensuring it uses this path when searching for configuration files.
  • Review the agent's training data and model to identify and potentially update any hardcoded associations with ~/.claude/ that may be causing the default behavior.
  • Test the agent's behavior with different values of $CLAUDE_CONFIG_DIR to ensure it consistently respects the environment variable.

Example

No specific code snippet is provided due to the lack of explicit code details in the issue, but the solution likely involves updating the agent's initialization or configuration loading logic to prioritize the $CLAUDE_CONFIG_DIR environment variable.

Notes

The issue seems to stem from the agent's trained prior, which defaults to ~/.claude/. Updating the agent's training data or modifying its scaffolding to include the resolved $CLAUDE_CONFIG_DIR could mitigate this issue. However, without access to the agent's code or training data, the exact solution may vary.

Recommendation

Apply a workaround by modifying the agent's initialization to inject the resolved $CLAUDE_CONFIG_DIR value into its context, as this directly addresses the observed behavior and allows for a more flexible configuration resolution process.

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 Agent hardcodes ~/.claude/ instead of respecting $CLAUDE_CONFIG_DIR