claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] Better Monorepo Support

Open rawkode opened this issue 7 months ago • 6 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: 1.0.29<!-- output of claude --version -->
  • Operating System: Linux
  • Terminal: Ghostty

Bug Description

I have a monorepository and I put a .mcp.json and some common commands in .claude/commands; but the way we work within the monorepo is from within service directories.

It would be nice if Claude would detect shared MCP and Commands within a Git root, by searching up.

rawkode avatar Jun 20 '25 13:06 rawkode

Commands in subdirectories should be working, is that not working for you?

ashwin-ant avatar Jun 20 '25 15:06 ashwin-ant

Subdirectories are fine, but when I launch Claude in a subdirectory the MCP config and commands at the root of the repository are not loaded.

rawkode avatar Jun 20 '25 16:06 rawkode

there are a few issues that I can see with monorepos:

  • mcp config as mentionned above (and in #374)
  • setting (like permissions) seem to behave like the mcp config => only current folder seem to be considered project scope
  • setups that rely on shell hooks (direnv, mise-en-place) or have zoxide installed, see #2632

what seems to work well: hierarchical memory

  • repo_root/CLAUDE.md
  • repo_root/service_a/CLAUDE.md

jlgeering avatar Jun 29 '25 14:06 jlgeering

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Oct 10 '25 10:10 github-actions[bot]

Workaround: MCP Server Isolation Using disabledMcpjsonServers

For those running multi-project workspaces or monorepos where different directories need different MCP servers, here's a pattern that works:

The Problem: MCP configs merge down the directory tree. If you have:

/workspace/.mcp.json            ← defines "workspace-tools" server
/workspace/project-a/.mcp.json  ← defines "project-a-tools" server

Opening Claude in project-a/ gives you BOTH servers. There's no "inherit": false flag.

The Solution: Use disabledMcpjsonServers in the subdirectory's .claude/settings.local.json:

{
  "disabledMcpjsonServers": ["workspace-tools"],
  "enableAllProjectMcpServers": false
}

This explicitly blocks the parent's MCP server from loading in that directory.

Full Example:

/workspace/
├── .mcp.json                          ← workspace-level MCP
├── project-a/
│   ├── .mcp.json                      ← project-a MCP
│   └── .claude/
│       └── settings.local.json        ← blocks workspace MCP
└── project-b/
    └── .claude/
        └── settings.local.json        ← blocks workspace MCP

Caveats:

  • Requires restart after config changes
  • Not true isolation (AI could edit the settings file)
  • enableAllProjectMcpServers: false prevents auto-enabling inherited servers

What would be better: A native "inherit": false in .mcp.json, or scoped servers:

{
  "mcpServers": {
    "my-server": {
      "command": "...",
      "scope": "this-directory-only"
    }
  }
}

Hope this helps others until proper scoping is implemented!

isekaiZen avatar Dec 05 '25 02:12 isekaiZen

I made a workaround for using hooks in monorepos: https://github.com/jack-michaud/claude-code-monorepo-hook-router/

jack-michaud avatar Dec 06 '25 21:12 jack-michaud