memory: project resolves path relative to subagent's perceived project root instead of git root

Resolved 💬 2 comments Opened Feb 12, 2026 by naritalancers Closed Mar 13, 2026

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

  1. Have a monorepo structure:

``
/repo-root/ ← git root, has .claude/agents/
/repo-root/frontend/workspace/ ← has package.json, tsconfig.json, vite.config.ts
``

  1. Define an agent with memory: project:

``yaml
---
name: code-reviewer
memory: project
---
``

  1. Prepare the memory directory at the git root:

``
/repo-root/.claude/agent-memory/code-reviewer/MEMORY.md
``

  1. 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)

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗