claude-code - 💡(How to fix) Fix [BUG] Auto memory system prompt path uses CWD-based path but /memory creates directory at git-root-based path [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#52772Fetched 2026-04-25 06:21:23
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×4subscribed ×1unsubscribed ×1

Error Message

Error Messages/Logs

No error messages — the failure is silent. The Write tool simply fails because the target directory doesn't exist, and Claude is instructed not to check or create it.

Root Cause

No error messages — the failure is silent. The Write tool simply fails because the target directory doesn't exist, and Claude is instructed not to check or create it.

Code Example

~/.claude/projects/-user-work-monorepo-agents-my-agent/memory/

---

~/.claude/projects/-user-work-monorepo/memory/

---

/repo-root/          ← git root
   /repo-root/agents/my-agent/   ← subdirectory with its own CLAUDE.md

---

cd /repo-root/agents/my-agent
   claude

---

You have a persistent, file-based memory system at
   ~/.claude/projects/-user-work-repo-root-agents-my-agent/memory/
   This directory already exists — write to it directly...

---

~/.claude/projects/-user-work-repo-root/memory/

---

ls ~/.claude/projects/-user-work-repo-root-agents-my-agent/memory/
   # → No such file or directory
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
  • I am using the latest version of Claude Code

What's Wrong?

When starting a Claude Code session from a subdirectory of a git repository, the system prompt injects a CWD-based memory path:

~/.claude/projects/-user-work-monorepo-agents-my-agent/memory/

But when running /memory, the directory is created at the git-root-based path:

~/.claude/projects/-user-work-monorepo/memory/

The system prompt also says: "This directory already exists — write to it directly with the Write tool (do not run mkdir or check for its existence)."

Since the CWD-based path doesn't exist and Claude is told not to check, every Write to the memory path silently fails. No auto memories are ever saved for any project where sessions are started from a subdirectory of a git repo.

Session JSONL files are correctly written to the CWD-based project directory, but memory goes to the git-root-based directory — the two paths are inconsistent.

What Should Happen?

The memory path in the system prompt should match the path where /memory actually creates the directory. Either:

  1. The system prompt should use the git-root-based path (matching /memory behavior), or
  2. /memory should create the directory at the CWD-based path (matching the system prompt), or
  3. Both should agree on whichever scoping strategy is intended

Error Messages/Logs

No error messages — the failure is silent. The Write tool simply fails because the target directory doesn't exist, and Claude is instructed not to check or create it.

Steps to Reproduce

  1. Have a monorepo structure:

    /repo-root/          ← git root
    /repo-root/agents/my-agent/   ← subdirectory with its own CLAUDE.md
  2. Start a Claude Code session from the subdirectory:

    cd /repo-root/agents/my-agent
    claude
  3. Observe the system prompt contains:

    You have a persistent, file-based memory system at
    ~/.claude/projects/-user-work-repo-root-agents-my-agent/memory/
    This directory already exists — write to it directly...
  4. Run /memory — the directory is created at:

    ~/.claude/projects/-user-work-repo-root/memory/
  5. Verify the CWD-based memory directory does NOT exist:

    ls ~/.claude/projects/-user-work-repo-root-agents-my-agent/memory/
    # → No such file or directory
  6. Have a conversation where Claude should save a memory. It silently fails because the path in the system prompt doesn't exist.

Claude Code Version: 2.1.119 (Claude Code)

Model: Opus

Is this a regression? I don't know — auto memory may have never worked for subdirectory sessions.

Platform: Anthropic API

Operating System: macOS

Terminal/Shell: iTerm2

Additional Information

  • The CWD-based project directory (-user-work-repo-root-agents-my-agent/) does exist and stores session JSONL files correctly — only the memory/ subdirectory is missing
  • Across 30+ projects on this machine, only 4 have any saved memories — all of them are standalone git repos, not subdirectories
  • autoMemoryEnabled is not explicitly set (defaults to enabled), and CLAUDE_CODE_DISABLE_AUTO_MEMORY env var is not set
  • Related but different: #25140 (subagent memory path), #34437 (worktree sharing), #29505 (docs)

extent analysis

TL;DR

The most likely fix is to ensure consistency between the memory path in the system prompt and the actual directory created by /memory, either by updating the system prompt to use the git-root-based path or by modifying /memory to create the directory at the CWD-based path.

Guidance

  • Verify the intended scoping strategy for memory paths to determine whether the system prompt or /memory behavior should be updated.
  • Check the documentation for Claude Code to see if there are any configuration options or environment variables that can be used to control the memory path behavior.
  • Consider updating the system prompt to use the git-root-based path to match the behavior of /memory, as this appears to be the current implementation.
  • Test the fix by starting a new Claude Code session from a subdirectory and verifying that the memory directory is created at the expected location.

Example

No code snippet is provided as the issue appears to be related to the configuration or implementation of Claude Code rather than a specific code bug.

Notes

The issue may be related to the fact that the autoMemoryEnabled option is not explicitly set, but the default behavior is enabled. Additionally, the CLAUDE_CODE_DISABLE_AUTO_MEMORY environment variable is not set, which may also be relevant to the issue.

Recommendation

Apply a workaround by manually creating the memory directory at the expected location or by updating the system prompt to use the git-root-based path, as this appears to be the current implementation. This will ensure consistency between the system prompt and the actual directory created by /memory.

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 [BUG] Auto memory system prompt path uses CWD-based path but /memory creates directory at git-root-based path [1 participants]