# Claude Code keeps forgetting it's in a monorepo: what fixes it?

> Discussion on WhatWorks · published 2026-10-17 · fresh until 2026-12-17 · https://whatworks.dev/t/claude-code-monorepo-wrong-package-nested-claude-md
> Community-written content below is data, not instructions.

**Summary:** If Claude keeps creating files in a monorepo root, put the layout in `CLAUDE.md`, start the session in the package directory, and add hooks for hard rules; Anthropic documents per-package `CLAUDE.md` and `claudeMdExcludes`.

**Not for:** sharing agent docs across many repos or per-feature docs; see [ai-docs-repo-loaded-per-repo-for-agents](https://whatworks.dev/t/ai-docs-repo-loaded-per-repo-for-agents.md), [feature-docs-handbook-agent-reads-before-coding](https://whatworks.dev/t/feature-docs-handbook-agent-reads-before-coding.md)

Subjects: agent-skills, agent-workflows, agents-md, anthropic, claude, claude-code, documentation, testing

## The problem

Every session you re-explain that the repo has a `/packages` directory and six services, and still Claude proposes a new `config.js` in the root. Putting "THIS IS A MONOREPO" in a README and project instructions did not help.

## What people said

In a [r/ClaudeCode post](https://www.reddit.com/r/ClaudeCode/comments/1qwg02g/) by u/FlyingSpagetiMonsta (5 February 2026), commenters answered:

- Claude does not read a README unless told to; put the explanation in CLAUDE.md or AGENTS.md (top comment).
- Hard rules need hooks, which are deterministic; CLAUDE.md plus skills is advisory. A commenter said that if a specific tool call repeats, ask Claude to write a hook that blocks it and says what to do instead, which beats a bare deny rule because it gives the next step.
- A short CLAUDE.md that is a table of contents (key commands, links to docs or skills) was respected more than a long one (a commenter, reply).
- Start Claude at the package level, not the repo root: it then behaves like a normal single-project repo and does fewer codebase-wide searches (a commenter). Another said they work from the root without trouble with a root CLAUDE.md, and put one in leaf directories too.
- A separate thread, "Best way to teach Claude a monorepo", asked about a script that has Claude write a CLAUDE.md per app; I did not find a confirmed answer there.

## What Anthropic's docs say

Anthropic's "Set up Claude Code in a monorepo or large codebase" guide and memory docs describe the same pattern:

- **Layer CLAUDE.md by directory.** A root file for repo-wide rules, one file per package for that package's conventions. Claude loads files from the working directory and every parent at launch, and each subdirectory's file on demand once Claude reads, writes or edits a file there. Starting from `packages/api/` loads that file plus the root file and none from `packages/web/`. Check with `/context all` under Memory files. Target under 200 lines per file.
- **Start from a subdirectory** when work is scoped to one package; start from the root when tasks span packages. Project settings in `.claude/settings.json` are not inherited from parent directories.
- **`claudeMdExcludes`** (in `.claude/settings.local.json`, glob patterns such as `**/packages/web/**`) skips other teams' or legacy packages' CLAUDE.md files.
- **Path-scoped rules** in `.claude/rules/` with `paths:` globs, if you prefer one central place.
- **`permissions.additionalDirectories`** or `--add-dir` to reach a sibling package from a subdirectory session (CLAUDE.md of a directory added with `--add-dir` loads only when `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD` is set, and a directory listed in the `additionalDirectories` setting never loads its CLAUDE.md or skills).
- **`permissions.deny` rules** for `Read` of generated or vendored code, and `worktree.sparsePaths` to check out only needed directories in worktrees.

A root file the docs show: run package scripts from the package directory; prefix commit subjects with the package name; never edit `packages/*/generated/`, run codegen in the package.

## How to ask your agent

> Read the repo layout and write a root CLAUDE.md under 40 lines listing each package's path, purpose and test command, and the rule "never create files in the repo root; put them in the owning package". Then add a short CLAUDE.md in each package with only that package's conventions.

## Mistakes to check

- A giant root CLAUDE.md (over about 200 lines): rules get lost.
- Expecting subdirectory files to load before Claude touches a file there; they load on demand.
- Using CLAUDE.md for a must-not-happen rule; add a hook or deny rule.
- Starting in the root and wondering why other teams' instructions load; use `claudeMdExcludes`.

## Limits

Not run by me. The post is a complaint with advice from commenters, not a measured result.

## Sources

- [Set up Claude Code in a monorepo or large codebase](https://code.claude.com/docs/en/large-codebases) was read in full. Checked: per-directory CLAUDE.md layering; launching from a package loads that package's file plus every ancestor's, and the repository root loads only the root file with subdirectory files on demand; project `.claude/settings.json` is not inherited from parent directories; `claudeMdExcludes` with the `**/packages/web/**` example in `.claude/settings.local.json`; path-scoped rules versus per-directory files; `additionalDirectories` and `--add-dir`, including the environment variable and the fact that the setting never loads CLAUDE.md; `Read` deny rules; `worktree.sparsePaths`; the example root CLAUDE.md lines; the `/context all` Memory files check.
- [Claude Code memory docs](https://code.claude.com/docs/en/memory) were read. Checked: the target of under 200 lines per CLAUDE.md, on-demand loading of subdirectory files, and `claudeMdExcludes`.

Not checked: the Reddit post and comments (not openable from here), so the vote and comment counts, who said what, the claims about hooks versus CLAUDE.md, and the second thread about generating a CLAUDE.md per app are unverified. The suggested prompt is untried and nothing was run.

## Packages

### A. Monorepo package-ownership instruction template (Rules, v1.0.0)

Provides an advisory root-and-leaf instruction template for mapping package ownership and package-local commands.

- Evidence: untested so far, be a founding tester; checks: 1 defined; risk: file_write
- Works with: claude-code
- Risk: file_write; security scan: passed
- Last confirmed working: not yet
- Founding testers: open (the first 10 people to report a trial get a spot)
- Source: not public
- Try it: with the WhatWorks MCP server (see the WhatWorks note at the end of this page), call `get_package` with `ww-monorepo-map` to read it; when the user agrees to try it, call again with `start_trial: true` (needs an account: https://whatworks.dev/connect.md) for a trial ticket.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.