[BUG] Auto memory system prompt path uses CWD-based path but /memory creates directory at git-root-based path
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] 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:
- The system prompt should use the git-root-based path (matching
/memorybehavior), or /memoryshould create the directory at the CWD-based path (matching the system prompt), or- 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
- Have a monorepo structure:
````
/repo-root/ ← git root
/repo-root/agents/my-agent/ ← subdirectory with its own CLAUDE.md
- Start a Claude Code session from the subdirectory:
``bash``
cd /repo-root/agents/my-agent
claude
- 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...
- Run
/memory— the directory is created at:
````
~/.claude/projects/-user-work-repo-root/memory/
- Verify the CWD-based memory directory does NOT exist:
``bash``
ls ~/.claude/projects/-user-work-repo-root-agents-my-agent/memory/
# → No such file or directory
- 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 thememory/subdirectory is missing - Across 30+ projects on this machine, only 4 have any saved memories — all of them are standalone git repos, not subdirectories
autoMemoryEnabledis not explicitly set (defaults to enabled), andCLAUDE_CODE_DISABLE_AUTO_MEMORYenv var is not set- Related but different: #25140 (subagent memory path), #34437 (worktree sharing), #29505 (docs)
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗