You point Claude Code at a three-year-old Next.js repo and ask it to add a feature. It invents a state management library you removed last quarter, puts the API route in the wrong directory, and writes tests in a framework you don’t use. The code isn’t bad — it just has no idea how your project works. The fix isn’t a better prompt; it’s giving the agent the context a new hire would get on day one.
This playbook converts an existing project into one that Cursor, Claude Code, and Codex can work in productively, using a single source of truth that all three read.
The mistake teams make is hand-writing three separate context files. Instead, write the conventions once and let each tool’s entry file point at the same content. All three tools read a root-level Markdown file:
Tool
Reads
Notes
Claude Code
CLAUDE.md
Project root; subdirectory CLAUDE.md files override for that path
Codex
AGENTS.md
Same idea, open AGENTS.md standard
Cursor
.cursor/rules/*.mdc
Scoped rule files with frontmatter; also reads AGENTS.md
Don’t open a blank CLAUDE.md. Have the agent read the repo and draft it — you’ll edit far less than you’d write. This is identical across all three tools; run the prompt in whichever one you have open.
Review the draft against reality, delete the TODO: confirm lines you can answer, and commit it. A grounded 120-line file beats a 400-line template full of [YOUR_FRAMEWORK].
Here’s the shape of a good result for a real Next.js app — concrete, not a fill-in-the-blanks form:
# Acme Storefront
Next.js 16 e-commerce app. App Router, RSC by default.
Cursor reads .cursor/rules/*.mdc. Use .mdc (Markdown with frontmatter) so you can scope rules to paths and control when they apply — .md also works but gives you no scoping.
.cursor/rules/
general.mdc # alwaysApply: true — core standards
api.mdc # globs: app/api/** — backend rules
components.mdc # globs: components/** — UI rules
A scoped rule with real frontmatter:
---
description: API route conventions
globs: app/api/**
alwaysApply: false
---
- Validate request bodies with Zod schemas from `lib/schemas/`
- Wrap handlers in `withErrorHandler` from `lib/api/errors.ts`
- Return `NextResponse.json` with explicit status codes
- Never expose Prisma errors to the client
Reference files instead of pasting them (@lib/api/errors.ts) so rules don’t go stale when the code changes.
Claude Code reads CLAUDE.md from the root and merges any subdirectory CLAUDE.md files for work in that path. Bootstrap it with the /init slash command inside the REPL, which scans the repo and drafts the file for you:
> /init
Then refine it with the generation prompt above. For a monorepo, add a focused CLAUDE.md in each package — for example packages/api/CLAUDE.md describing only that service — and keep the root file high-level. Claude Code automatically picks up the nearest file for the code it’s editing.
Codex reads AGENTS.md. If you’ve already written CLAUDE.md, don’t duplicate it — point Codex at it:
AGENTS.md
See CLAUDE.md for project conventions, stack, and commands.
## Codex-specific
- Run `npm run lint && npm test` before declaring a task done
- For parallel Cloud tasks, scope each task to one package
Like Claude Code, Codex supports nested AGENTS.md files, so a package-level file overrides the root for work in that directory.
For an older project with thin documentation, drive the conversion with two prompts: one to map what exists, one to plan the work.
Map the codebase. Let the agent build the picture you’d otherwise reconstruct by hand.
Turn the audit into a phased plan. Convert findings into work you can actually schedule.
Execute incrementally. Work module by module, keeping backward compatibility. Land the context files first (Phase 1) so every subsequent task benefits from them, then characterization tests, then refactors. Fan the independent Phase 3 tasks out across Codex Cloud tasks or Claude Code sub-agents and review the diffs as they arrive.
A CLAUDE.md that’s six months stale is worse than none — it actively misleads the agent. Automate a refresh in CI using a real agent CLI, not a fictional npx tool. Claude Code runs headless with -p; Codex runs non-interactively with codex exec.
.github/workflows/refresh-context.yml
name: Refresh project context
on:
schedule:
- cron: '0 6 * * 1'# Monday mornings
workflow_dispatch:
jobs:
update-claude-md:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update CLAUDE.md from the current codebase