Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…

Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Developer team reviewing code on laptops with pull request workflow dashboard visible in background
Open SourceScore: 90

6 CLAUDE.md Patterns That Keep Shared Context From Breaking When PR Volume

Use the two-layer CLAUDE.md split, hooks, and CI review action to prevent agent drift. The repo-root file wins over personal preferences, and enforcement matters more than prose.

·10h ago·4 min read··8 views·AI-Generated·Report error
Share:
Source: dev.tovia devto_claudecode, gn_claude_community, gn_claude_code_tipsMulti-Source
How do I keep shared CLAUDE.md context from breaking when multiple engineers use Claude Code on the same repo?

Adopt a two-layer CLAUDE.md split (repo root as team constitution, personal file for preferences), add per-module overrides, enforce with PreToolUse/PostToolUse hooks, use a reviewer-role prompt, re-review in CI with anthropics/claude-code-action@v1, and gate constitution changes.

TL;DR

Treat CLAUDE.md as a team constitution with layered files, hooks, and CI-side reviews to stop agent drift from fracturing your codebase.

Key Takeaways

  • Use the two-layer CLAUDE.md split, hooks, and CI review action to prevent agent drift.
  • The repo-root file wins over personal preferences, and enforcement matters more than prose.

The Problem: More PRs, Less Review Capacity

Anthropic reported that code output per engineer grew 200% in the last year, but before Code Review shipped, only 16% of PRs got substantive review comments. That gap is the real story. When you turn on Claude Code and lower the "should I open a PR?" bar, PR volume jumps—but review capacity doesn't. Six weeks later, the trunk gets weird.

Your team's shared codebase mental model and tacit conventions fracture when five different personal CLAUDE.md files all bid for the same surface. Each engineer's agent has different instincts: camelCase vs snake_case, integration-first vs unit-first tests. The reviewer—also using Claude Code—has yet another set. Multiply by five and the codebase's "voice" breaks.

The Fix: Treat CLAUDE.md as a Team Constitution

The convention file has to be in the repo (so every Claude instance reads it), enforced (so drift is caught mechanically), and layered (so team convention beats personal preference). Here are the six patterns that carried the weight.

Pattern 1: Two-Layer CLAUDE.md

Split CLAUDE.md into two files with clear precedence:

  • ./CLAUDE.md in the repo root—the team constitution, committed and PR-reviewed. Coding conventions, PR rules, review checklists, "never do X." This binds every session.
  • ~/.claude/CLAUDE.md on each engineer's machine—personal preferences. Editor quirks, "explain longer, I'm new to Go." Not shared.

Claude Code reads both, but the repo one wins on conflict. Write at the top of the team file: "If this file and a personal CLAUDE.md disagree, this file wins. Personal preferences apply only where this file is silent."

Pattern 2: Per-Module Overrides

Not every convention is repo-global. Frontend and backend have different testing philosophies. Put packages/backend/CLAUDE.md with "unit tests with Vitest, mock DB with in-memory adapter" and packages/frontend/CLAUDE.md with "integration tests with Playwright, no mocks." The root carries only what's universal. Keep leaf files short—five to fifteen lines—and only the delta from the parent. Don't duplicate rules.

Pattern 3: Hook-Based Enforcement

CLAUDE.md prose is a soft constraint. Under time pressure, on the eighty-third turn, Claude will sometimes forget. Use hooks:

  • PreToolUse on Bash—validate commands. Block rm -rf, git push --force to main, committing without tests.
  • PostToolUse on Edit/Write—run linter and type checker. If they fail, feed errors back to Claude.

This is the difference between "ninety percent" and "one hundred percent" compliance. At team scale, the ten percent gap erodes trust.

Pattern 4: Explicit Review-Role Separation

Use two Claude Code sessions—one implements, one reviews. Give the reviewer session its own addendum:

# ./.claude/CLAUDE-reviewer.md
You are reviewing a PR opened by another Claude session.
- Assume the implementer already believed their code was correct.
- Look for: hidden coupling, edge cases tests don't cover, API surface changes, security implications.
- Do not restate the diff. Only comment on issues.
- Classify every comment: Must / Should / Nit.
- Terminate review with a one-sentence verdict.

Load with claude --append-system-prompt "$(cat ./.claude/CLAUDE-reviewer.md)". This makes the reviewer adversarial by default, not sycophantic. It produced the biggest lift in review quality.

Pattern 5: CI-Side Re-Application

Hooks fire locally. That's not enough when another engineer's Claude session opens a PR with a slightly older CLAUDE.md checkout. Run review server-side with the official action:

# .github/workflows/claude-review.yml
name: Claude Code Review
on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: read
    steps:
      - uses: actions/checkout@v4
      - uses: anthropics/claude-code-action@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          claude-code-command: 'review'

This ensures every PR gets a fresh, consistent review from the current constitution.

Pattern 6: Constitution Drift Gate

Changes to the team CLAUDE.md itself need review. Treat it like code: PR-review any change, require a "why" in the description, and log the change in a changelog. This prevents silent drift that breaks agent behavior.

The One Pattern That Was Dead Weight

A single "global rules" file that tried to cover everything. It became bloated, contradicted itself, and agents ignored it. The layered approach replaced it.

Six CLAUDE.md patterns that kept a shared repo coherent as PR volume outran review capacity: two-layer split, per-module overrides, hook enforcement,

What Changed for My Team

Six months in, PR volume tripled, but the trunk stayed clean. Hooks caught 100% of lint errors. Review comments were consistent and actionable. The key was treating CLAUDE.md as a living constitution, not a static prompt.

Cover image for 6 CLAUDE.md Patterns That Kept Shared Context From Breaking When PR Volume Outran Review


Source: dev.to

Sources cited in this article

  1. Less Review Capacity Anthropic
Source: gentic.news · · author= · citation.json

AI-assisted reporting. Generated by gentic.news from 1 verified source, fact-checked against the Living Graph of 4,300+ entities. Edited by Ala SMITH.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

Claude Code users should immediately adopt the two-layer CLAUDE.md split if they work on a shared repo. Without it, each engineer's personal `~/.claude/CLAUDE.md` leaks preferences into shipped code, causing style and testing inconsistencies. The repo-root file must explicitly override personal files, and you should enforce this with a line at the top of the team file. Next, set up PreToolUse and PostToolUse hooks—these turn soft prose into hard guarantees. Start with blocking dangerous commands and auto-running linters. This closes the ten percent gap that erodes trust. For teams, add the CI-side review action (`anthropics/claude-code-action@v1`) to catch drift from stale CLAUDE.md checkouts. Pair it with a reviewer-role prompt loaded via `--append-system-prompt` to make reviews adversarial and consistent. Finally, gate changes to the team CLAUDE.md itself—PR-review them like code to prevent silent drift. The result: higher PR volume without the "trunk got weird" failure.
Compare side-by-side
Claude Code vs Code Review
Enjoyed this article?
Share:

AI Toolslive

Five one-click lenses on this article. Cached for 24h.

Pick a tool above to generate an instant lens on this article.

Related Articles

From the lab

The framework underneath this story

Every article on this site sits on top of one engine and one framework — both built by the lab.

More in Open Source

View all