claude-code - 💡(How to fix) Fix [BUG] --bare --add-dir re-enables global ~/.claude/CLAUDE.md discovery [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#52267Fetched 2026-04-24 06:11:42
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×5cross-referenced ×1

Error Message

Error Messages/Logs

No error - the global CLAUDE.md is silently loaded. The only observable signal is inflated token counts and the model following instructions from ~/.claude/CLAUDE.md that should not be present in --bare mode.

Fix Action

Workaround

Use --append-system-prompt-file to inject a specific project CLAUDE.md instead of --add-dir:

claude --bare --append-system-prompt-file "$PWD/CLAUDE.md" "$@"

Code Example

# Baseline: --bare without --add-dir
echo "say POTATO" | claude --bare -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"input_tokens":[0-9]*'
# Result: ~1,700 tokens (vanilla system prompt)

# Bug: --bare WITH --add-dir (any path, even /tmp)
echo "say POTATO" | claude --bare --add-dir /tmp -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"cache_creation_input_tokens":[0-9]*'
# Result: ~5,400 tokens (global CLAUDE.md loaded)

# Workaround: --append-system-prompt-file instead of --add-dir
echo "say POTATO" | claude --bare --append-system-prompt-file ./CLAUDE.md -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"input_tokens":[0-9]*'
# Result: ~1,700 + project CLAUDE.md size (no global CLAUDE.md)

---

claude --bare --append-system-prompt-file "$PWD/CLAUDE.md" "$@"
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?

When running claude --bare --add-dir <any-path>, the --add-dir flag causes the user-level ~/.claude/CLAUDE.md to be loaded into the system prompt. This happens regardless of which path is passed to --add-dir - even --add-dir /tmp triggers it.

--bare is supposed to skip all CLAUDE.md auto-discovery. --add-dir should only add the specified directory, not re-enable global discovery.

Related: #38676 (same class of issue - --bare not fully isolating from user config - but different vector: MCP servers vs CLAUDE.md)

What Should Happen?

--bare --add-dir <path> should load only the CLAUDE.md from the specified directory (if one exists), not the global ~/.claude/CLAUDE.md.

Steps to Reproduce

Requires a ~/.claude/CLAUDE.md with identifiable content.

# Baseline: --bare without --add-dir
echo "say POTATO" | claude --bare -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"input_tokens":[0-9]*'
# Result: ~1,700 tokens (vanilla system prompt)

# Bug: --bare WITH --add-dir (any path, even /tmp)
echo "say POTATO" | claude --bare --add-dir /tmp -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"cache_creation_input_tokens":[0-9]*'
# Result: ~5,400 tokens (global CLAUDE.md loaded)

# Workaround: --append-system-prompt-file instead of --add-dir
echo "say POTATO" | claude --bare --append-system-prompt-file ./CLAUDE.md -p --output-format stream-json --verbose 2>&1 \
  | grep -o '"input_tokens":[0-9]*'
# Result: ~1,700 + project CLAUDE.md size (no global CLAUDE.md)

The token delta (~3,700 tokens) matches the size of ~/.claude/CLAUDE.md plus its referenced files.

Error Messages/Logs

No error - the global CLAUDE.md is silently loaded. The only observable signal is inflated token counts and the model following instructions from ~/.claude/CLAUDE.md that should not be present in --bare mode.

Workaround

Use --append-system-prompt-file to inject a specific project CLAUDE.md instead of --add-dir:

claude --bare --append-system-prompt-file "$PWD/CLAUDE.md" "$@"

Claude Model

Opus 4.6

Is this a regression?

I don't know

Claude Code Version

2.1.118 (Claude Code)

Platform

Amazon Bedrock

Operating System

macOS (Darwin 24.6.0)

Terminal/Shell

Kitty / zsh

Additional Information

No response

extent analysis

TL;DR

Use --append-system-prompt-file instead of --add-dir to load a specific project CLAUDE.md without triggering global discovery.

Guidance

  • The issue seems to be caused by the --add-dir flag not respecting the --bare mode, leading to the global ~/.claude/CLAUDE.md being loaded.
  • To verify, compare the token counts with and without the --add-dir flag, as shown in the provided steps to reproduce.
  • As a workaround, use --append-system-prompt-file to inject a specific project CLAUDE.md, as demonstrated in the provided example.
  • Be aware that this issue may be related to a larger problem with --bare mode not fully isolating from user config, as mentioned in the related issue #38676.

Example

claude --bare --append-system-prompt-file "$PWD/CLAUDE.md" "$@"

Notes

The provided workaround should mitigate the issue, but it may not be a complete fix. The root cause of the problem is unclear, and it is uncertain whether this is a regression or a long-standing issue.

Recommendation

Apply the workaround using --append-system-prompt-file until a more permanent fix is available, as it provides a reliable way to load a specific project CLAUDE.md without triggering global discovery.

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