DEV Community

Beyen
Beyen

Posted on

Keeping AGENTS.md, CLAUDE.md, and Cursor Rules in Sync

If you run Claude Code in the terminal while someone else opens the same repository in Cursor or Codex, instruction files drift apart fast.

Copy-pasting a 400-line style guide into every tool's config file doesn't just double your maintenance. Depending on the client, it can silently truncate nested package rules or add thousands of static tokens to every turn.

Here is how each instruction format actually loads, three traps worth avoiding, and a minimal layout that keeps one source of truth.

TL;DR

  • Root AGENTS.md -> put shared build, test, and repo conventions here (read natively by Codex, Cursor, Windsurf, Cline, and Copilot)
  • CLAUDE.md -> keep it tiny with a single @AGENTS.md import plus Claude-only notes
  • .cursor/rules/*.mdc -> reserve for path-scoped globs rules that shouldn't load globally
  • SKILL.md -> use for occasional multi-step workflows so only the short metadata loads at startup

πŸ—‚οΈ How each file loads

File Read by Loading behavior & budget
AGENTS.md Codex, Cursor, Windsurf, Cline Loaded along directory chain (root -> cwd); 32 KiB cumulative cap in Codex
CLAUDE.md Claude Code Loaded in full at session start (@path imports expand immediately)
.cursor/rules/*.mdc Cursor (v0.45+) Loaded conditionally when active files match YAML globs
SKILL.md Claude Code, Codex, Goose Progressive disclosure: only name + description (~50 tokens) load until triggered

⚠️ Trap 1: Codex's 32 KiB limit is cumulative

OpenAI Codex walks from ~/.codex/AGENTS.md to your repo root AGENTS.md and down to your current working directory.

By default, project_doc_max_bytes is 32,768 bytes (32 KiB) across that entire chain, not per file. If your root AGENTS.md is a 28 KiB architecture essay, a package-specific packages/api/AGENTS.md deeper in the tree gets truncated or dropped without a loud warning.

Keeping root AGENTS.md under ~150 lines of concrete build, lint, and test commands leaves plenty of room for subdirectory overrides.

πŸ”‘ Trap 2: @path imports in CLAUDE.md don't save context

A common assumption in Claude Code is that splitting a large CLAUDE.md into imports like this keeps the context window lean:

@docs/architecture.md
@docs/coding-standards.md
Enter fullscreen mode Exit fullscreen mode

It helps human readability, but it does not defer loading. Claude Code expands @path imports into the session context at launch.

If a rule only applies to database migrations or API routes, put it in path-scoped rules (.claude/rules/*.md or .cursor/rules/*.mdc) or an on-demand SKILL.md instead of importing it into root CLAUDE.md.

🧩 Trap 3: SKILL.md fails silently on folder-name mismatch

Agent Skills validate YAML frontmatter strictly:

  • name: 1–64 characters, lowercase alphanumeric and single hyphens only (^[a-z0-9]+(-[a-z0-9]+)*$), and it must match the parent folder name (db-check/SKILL.md -> name: db-check)
  • description: 1–1,024 characters stating both what the skill does and when to use it

If name has uppercase letters, underscores, or doesn't match the folder name, the agent skips it silently.

βš™οΈ One repo layout that stays in sync

Instead of hand-editing the same rules in three places:

  1. Put shared build, test, and architecture constraints in root AGENTS.md.
  2. Point CLAUDE.md at AGENTS.md and only add Claude-specific slash commands or hooks:
# Project Instructions

@AGENTS.md

## Claude Code Notes
- Run `/clear` between unrelated tasks to avoid re-caching long threads.
Enter fullscreen mode Exit fullscreen mode
  1. Put personal local ports or sandbox paths in CLAUDE.local.md (gitignored).
  2. Keep .cursor/rules/*.mdc strictly for directory-specific globs (like src/components/**/*.tsx).

Wrapping up

Most instruction drift comes from treating AGENTS.md and CLAUDE.md as separate documents. Pick AGENTS.md as the base, import it from CLAUDE.md, and push situational workflows out to skills or glob-scoped rules.

If you want to check byte budgets or generate the boilerplate files side by side, there's a small browser-based linter and converter and a set of MIT starter templates on GitHub.

Related: Why Your MCP Config Works in Cursor but Not in VS Code

How are you organizing repo instructions when teammates use different coding agents?

Top comments (5)

Collapse
 
crisstiank profile image
Cristian K •

The cumulative 32 KiB cap in Codex is the trap I'd have missed. The single @AGENTS.md import in CLAUDE.md is a neat way to keep one source of truth. A cheap safeguard: a CI check that fails if CLAUDE.md grows beyond the import plus a few lines, so Claude-only notes don't slowly turn into a second copy of the style guide.

Collapse
 
beyenai profile image
Beyen •

That CI line-count gate is a really practical ideaβ€”it catches drift right at PR time before CLAUDE.md quietly turns into a parallel guide.

You can also pair it in the same CI step with a byte-size check across each directory's AGENTS.md chain (leaving a little headroom below Codex's default 32,768-byte project_doc_max_bytes cap for any personal ~/.codex/AGENTS.md), so oversized updates fail loudly in CI instead of getting silently truncated.

Collapse
 
dosaygo profile image
dosaygo •

When a nested package has its own AGENTS.md, how do you stop an agent started at the repo root from building a duplicate helper before opening that subdirectory?

Collapse
 
beyenai profile image
Beyen •

Good questionβ€”nested AGENTS.md files aren't loaded at repo-root startup (they're either skipped when your cwd is the root or only picked up once the agent opens files in that directory), which creates that exact blind spot. A lightweight pattern that avoids bloating the root file:

  1. Keep a 1-line package map in the root AGENTS.md β€” just the path and what lives there (e.g., packages/shared/ β€” HTTP client, auth helpers, date formatting), without duplicating the package's full rules.
  2. Add an explicit "check before creating" rule at the root β€” instruct the agent to search the shared package (or read the target package's AGENTS.md) before adding any new cross-cutting helper.
  3. Keep shared utilities under one predictable entry point β€” clean barrel exports or path aliases (like @repo/shared/*) make a quick rg/grep from the root surface existing helpers immediately instead of relying on prompt memory alone.

That way the root AGENTS.md stays small as an index, while detailed package conventions stay scoped to the nested files.

Collapse
 
dosaygo profile image
dosaygo •

A root check before creating line still loses in practice unless the agent has to output the exact @repo/shared/* symbol and file path it is extending before generating any diff; otherwise it runs rg, sees ten barrel exports, and writes a fresh wrapper anyway. AI Lint packages that root pre-flight checklist and parallel-solution reject doctrine so coding agents must name the existing shared helper they are building on before writing code: ai-lint.dosaygo.com/go/forum-20261...