FormingRulesclaude-codepublished fresh until

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

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, feature-docs-handbook-agent-reads-before-coding

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ARules · v1.0.0Monorepo package-ownership instruction template
How you use itAlways on in your project
What it can dowrites files
What's inside
ARules · v1.0.0Monorepo package-ownership instruction template
How you use it
Always on in your project
What it can do
writes files
What's inside

What this thread does

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

Started from a post by @FlyingSpagetiMonsta, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code keeps forgetting it's in a monorepo: what fixes it?
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`.

## Options
- A · Monorepo package-ownership instruction template · early, no verdict yet · writes files
Copy for agent
get the whatworks thread claude-code-monorepo-wrong-package-nested-claude-md and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-monorepo-wrong-package-nested-claude-md

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Monorepo package-ownership instruction template

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

Format
Rules
Source
—
Pinned
v1.0.0 · sha256:cea69
Content hash
cea69da0a804bcd0
Audit
scan passed
Can do
writes files
Works with
claude-code
Check
Exact authored file, including evaluation checklist, is installed.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-monorepo-map before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp