← Blog

How-to5 min read

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.

Running Claude Code and Codex across separate packages and worktrees in MirasimRunning Claude Code and Codex across separate packages and worktrees in 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 directoryFile access (Claude Code)Instructions loaded at start
Repository rootEvery file in the repoRoot CLAUDE.md only; subdirectory files load on demand
A package subdirectory (e.g. packages/api)That subtree only, unless granted more via --add-dirThat directory's plus every ancestor's CLAUDE.md (and AGENTS.md in Codex)

Layer CLAUDE.md, AGENTS.md, and per-package skills

Typical two-level layout for a monorepo
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 /doctor in Claude Code if CLAUDE.md grows 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: unlike CLAUDE.md, Claude Code does not inherit .claude/settings.json from 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 Read deny 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.sparsePaths so Claude Code checks out only the directories a worktree task needs.
Cross-package access (--add-dir)
When you start Claude Code in packages/web but need to check a type in packages/shared (or a sibling repo), pass --add-dir ../shared or configure additionalDirectories.
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 in packages/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.

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.md loading). Launch from the repository root when edits span multiple packages.
Are .claude/settings.json files inherited from parent directories?
No. Anthropic's large-codebase docs note that unlike CLAUDE.md, project .claude/settings.json files 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.

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