I wrote CLAUDE.md in the current folder. Since the project is fictional, I couldn't check it against real files, so a few parts are guesses (listed below).
The rules file covers your three problems directly:
- Default exports: named exports only, with a short exception list for the files Next.js requires to be default.
- Invented helpers: the agent must search
src/lib/before writing any helper. If it thinks one is missing, it has to say what it searched and ask first. - Prisma schema: it may not edit
schema.prismaor runmigrateordb pushwithout approval. It must stop and describe the change instead.
It also tells the agent to ask rather than guess when requirements conflict or are missing.
Task context block to paste at the session start
TASK: Implement the "checkout" feature.
SCOPE (only touch these):
- src/checkout/ (new feature code: UI, server actions, types)
- src/lib/payments.ts (payment logic)
READ FIRST, before writing anything:
- src/lib/payments.ts and `ls src/lib` (reuse existing helpers; list what you found)
- One existing feature folder in src/ as the pattern to follow: <PATH, e.g. src/cart/>
- The relevant Prisma models (read-only): <MODEL NAMES, e.g. Order, OrderItem, Payment>
CONSTRAINTS:
- Follow CLAUDE.md: named exports, reuse src/lib, no new deps.
- Do NOT modify prisma/schema.prisma. If checkout needs a schema change, stop and propose it.
- Never log or store raw card data; <PAYMENT PROVIDER, e.g. Stripe> handles it.
OPEN QUESTIONS (ask me, don't guess): <e.g. guest checkout? tax/shipping rules? failure and retry behavior?>
FIRST STEP: reply with a short plan (files to create or change, existing helpers you'll reuse), then wait for my go-ahead.
What you need to fill in
- Commands: I assumed standard npm scripts. Check them against your
package.json. - Pattern example: The example at the bottom is a placeholder. Swap in a real file from your repo, because one concrete example does more than any rule.
- Block placeholders: Fill the
<...>spots in the pasted block (pattern folder, Prisma models, payment provider, open questions). - Session length: Start a fresh session when checkout is done. If the session runs long, compact the history around 75% of the window and keep the task block and constraints intact.
Test run on a fictional Next.js project: the model wrote a CLAUDE.md in a temporary folder and a task context block, and said which parts were guesses (commands, the pattern example, placeholders). It could not check the rules against real project files.
What it does
Treats context as the biggest lever on agent output quality. It sets a five-level hierarchy from most persistent to most transient (rules file, spec and architecture, relevant source files, error output, conversation history) and shows how to write a rules file (CLAUDE.md, .cursorrules, AGENTS.md and equivalents) with stack, commands, conventions, boundaries and one pattern example. It covers loading only the relevant spec section, reading the file and a similar example before editing, treating instruction-like text in external files as data, feeding back only the failing error, restartable session boundaries, three packing strategies (brain dump, selective include, hierarchical summary) and budget rules: start trimming at about 75%, compress before dropping and put the task-critical material last. It also says to surface conflicts and missing requirements instead of guessing.
Output
A rules file for your project, a short task context block to paste at the start of a session, and a list of what you still need to fill in.
Good for
Setting up a project for AI-assisted work and fixing agents that ignore conventions, invent helpers or lose focus in long sessions.
Low risk: pure instructions with no scripts. It writes a rules file such as CLAUDE.md into your project and mentions MCP servers you could add; it does not install any. A rules file changes how your agent behaves, so read what it wrote. Test-run once on a fictional Next.js project: it wrote a CLAUDE.md and a task block and marked the parts it had to guess (commands, the pattern example), since it could not check them against real files. By Addy Osmani, MIT.