memory: project resolves path relative to subagent's perceived project root instead of git root
Bug Description
When using memory: project in a subagent definition (.claude/agents/*.md), the memory directory is created relative to the subagent's perceived "project root" rather than the actual git repository root.
Steps to Reproduce
- Have a monorepo structure:
````
/repo-root/ ← git root, has .claude/agents/
/repo-root/frontend/workspace/ ← has package.json, tsconfig.json, vite.config.ts
- Define an agent with
memory: project:
``yaml``
---
name: code-reviewer
memory: project
---
- Prepare the memory directory at the git root:
````
/repo-root/.claude/agent-memory/code-reviewer/MEMORY.md
- Launch the subagent via Task tool to review files under
frontend/workspace/
Expected Behavior
Memory is read from and written to:
/repo-root/.claude/agent-memory/code-reviewer/MEMORY.md
Actual Behavior
The subagent creates a new .claude/agent-memory/ directory inside the subdirectory:
/repo-root/frontend/workspace/.claude/agent-memory/code-reviewer/MEMORY.md
It appears the subagent identifies frontend/workspace/ as the "project root" (likely because it contains package.json, tsconfig.json, etc.) and resolves memory: project relative to that directory.
Suggested Fix
memory: project should resolve the project root using git rev-parse --show-toplevel (or by finding the nearest ancestor directory containing .claude/), not based on the subagent's working directory or the location of package.json.
Environment
- Claude Code version: latest (2026-02)
- OS: macOS (Darwin 25.2.0)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗