Setting up Claude Code and Codex in a monorepo or large codebase
How to set up Claude Code and Codex for a monorepo or large codebase: nested CLAUDE.md/AGENTS.md, Read deny rules, --add-dir, sparse worktrees, and Mirasim.


The short answer
In a large monorepo, putting every package's rules into one giant root file wastes context on every turn. Split instructions into a lean root CLAUDE.md / AGENTS.md plus per-package files, start the agent inside a package when work stays local (or at the root when changes span packages), block reads of generated or vendored folders, and use sparse worktrees when isolating parallel tasks.
| Start directory | File access (Claude Code) | Instructions loaded at start |
|---|---|---|
| Repository root | Every file in the repo | Root CLAUDE.md only; subdirectory files load on demand |
A package subdirectory (e.g. packages/api) | That subtree only, unless granted more via --add-dir | That directory's plus every ancestor's CLAUDE.md (and AGENTS.md in Codex) |
Layer CLAUDE.md, AGENTS.md, and per-package skills
monorepo/
CLAUDE.md # repo-wide build & commit rules (or AGENTS.md)
packages/
api/
CLAUDE.md # API conventions, test commands
.claude/skills/ # API-only workflows
web/
CLAUDE.md # frontend conventions
shared/
CLAUDE.md # shared library rules- Keep root files short: put only repo-wide standards (like commit prefixes and “never edit
packages/*/generated/”) at the root, and run/doctorin Claude Code ifCLAUDE.mdgrows too large. - Codex mirrors this hierarchy: Codex reads every
AGENTS.md(and trusted.codex/config.toml) from the Git root down to the folder you launch in. - Note for
.claude/settings.json: unlikeCLAUDE.md, Claude Code does not inherit.claude/settings.jsonfrom parent directories when you start in a subdirectory. - Auto memory shares across worktrees: Claude Code's per-repository auto memory (
MEMORY.md, loaded up to the first 200 lines or 25KB) is shared across all worktrees of the same repo.
Keep searches fast and worktrees light
- Block generated and vendored reads (
permissions.deny) - Add
Readdeny rules in Claude Code's settings for build artifacts, generated code, and vendored dependencies so the agent never wastes context opening them. - Sparse worktrees (
worktree.sparsePaths) - In giant repos where checking out every package is slow, configure
worktree.sparsePathsso Claude Code checks out only the directories a worktree task needs. - Cross-package access (
--add-dir) - When you start Claude Code in
packages/webbut need to check a type inpackages/shared(or a sibling repo), pass--add-dir ../sharedor configureadditionalDirectories. - Code intelligence plugins
- For typed languages, language-server plugins let Claude jump straight to definitions and callers instead of grepping and reading dozens of candidate files.
Working across packages side by side in Mirasim
- One pane per package or worktree: run one session in
packages/api(for example on Codex) and another inpackages/web(on Claude Code) in the same window — each in its own Git worktree with its own terminal and diff panel, grouped by folder and worktree in the sidebar. - Inspect every agent's memory files in one tab: Mirasim's Workspaces › Memory tab lists
CLAUDE.md,.claude/rules,CLAUDE.local.md,AGENTS.md,AGENTS.override.md, and Claude Code's auto memory for that folder so you can read and edit them without hunting through hidden folders.
Article · AGENTS.md and CLAUDE.md: what they are, and one file for Claude Code and Codex → How `AGENTS.md` and `CLAUDE.md` work, and sharing one file across both agents.
Questions
- Should I launch Claude Code from the monorepo root or inside a package?
- Launch from a package subdirectory when the task stays inside that package (tighter file scope and automatic ancestor
CLAUDE.mdloading). Launch from the repository root when edits span multiple packages. - Are
.claude/settings.jsonfiles inherited from parent directories? - No. Anthropic's large-codebase docs note that unlike
CLAUDE.md, project.claude/settings.jsonfiles are not inherited from parent directories. - Does Claude Code auto memory stay synced across Git worktrees?
- Yes. Auto memory (
MEMORY.md) is scoped per repository and shared across its worktrees, loading up to the first 200 lines or 25KB into sessions with auto memory enabled.
Article · Running two coding agents in one repository → Isolating parallel Claude Code and Codex sessions with Git worktrees and `.worktreeinclude`.
Article · Cutting Claude Code and Codex token usage: /context, /compact, prompt caching, and model routing → Keeping context small and cutting token spend with `/context`, `/compact`, and subagents.
Article · Claude Code for teams: access, shared setup, and working in one session → Rolling out shared conventions and sessions for a team using Claude Code.
Sources
Checked on November 29, 2026 against Anthropic's Claude Code docs (code.claude.com/docs: Set up Claude Code in a monorepo or large codebase, How Claude remembers your project) and OpenAI's Codex AGENTS.md docs (learn.chatgpt.com/docs). Check those pages for updated settings.
Keep reading

Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.

Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mirasim.