Skip to content

Project Conversion Playbook

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.

  • A real CLAUDE.md / AGENTS.md generated from your repo, not a blank template
  • Cursor .mdc rules scoped to the parts of the codebase they apply to
  • Copy-paste prompts to audit a legacy codebase and produce a phased conversion plan
  • A CI job that keeps your context files current using a real agent CLI — no fictional npm tools
  • A clear view of how each tool consumes context, so you don’t maintain three drifting copies

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:

ToolReadsNotes
Claude CodeCLAUDE.mdProject root; subdirectory CLAUDE.md files override for that path
CodexAGENTS.mdSame idea, open AGENTS.md standard
Cursor.cursor/rules/*.mdcScoped rule files with frontmatter; also reads AGENTS.md

Start by Generating Context, Not Writing It

Section titled “Start by Generating Context, Not Writing It”

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.
## Stack
- Next.js 16.2 (App Router), React 19, TypeScript 5.6 (strict)
- Tailwind CSS 4, Prisma 6 + PostgreSQL 16, Stripe, Auth.js v5
## Conventions
- Server Components by default; add `'use client'` only for interactivity
- Route handlers live in `app/api/`, one folder per resource
- Shared UI in `components/ui/`, feature components beside their route
- Data access goes through `lib/db/` — never call Prisma from a component
- Money is stored and computed in integer cents, never floats
## Commands
- Dev: `npm run dev` | Test: `npm test` (Vitest) | Migrate: `npx prisma migrate dev`
## Watch out
- The legacy `/pages/checkout` route is being migrated to App Router — don't extend it

The conversion workflow diverges by tool once the context file exists. Here’s what to set up in each.

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.

For an older project with thin documentation, drive the conversion with two prompts: one to map what exists, one to plan the work.

  1. Map the codebase. Let the agent build the picture you’d otherwise reconstruct by hand.

  2. Turn the audit into a phased plan. Convert findings into work you can actually schedule.

  3. 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
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Review CLAUDE.md against the current repo. Update the \
stack versions, commands, and directory conventions only where \
they no longer match reality. Output the corrected file." \
--output-format text > CLAUDE.md
- name: Open a PR if anything changed
uses: peter-evans/create-pull-request@v6
with:
commit-message: 'docs: refresh CLAUDE.md from codebase'
title: 'docs: refresh project context'
branch: chore/refresh-context

Minimum viable AI-ready project

  • ☐ Canonical CLAUDE.md (or AGENTS.md) generated from the repo and reviewed
  • ☐ Secondary entry files point at the canonical one — not forked copies
  • .cursor/rules/*.mdc for path-scoped standards (API, components, tests)
  • ☐ Highest-risk untested paths have characterization tests before any refactor
  • ☐ CI refresh job opens a PR, never auto-commits to main
  • ☐ Context files updated in the same PR as structural changes

The goal isn’t a perfect document. It’s a foundation that makes the agent behave like someone who already knows your codebase.