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.
できること
コンテキストを、エージェントの出力品質を左右する最大のてこと捉えます。最も永続的なものから最も一時的なものまでの5層(ルールファイル、仕様とアーキテクチャ、関連するソースファイル、エラー出力、会話履歴)を示し、ルールファイル(CLAUDE.md、.cursorrules、AGENTS.md など)の書き方を、技術スタック、コマンド、規約、境界、パターンの例1つとともに示します。関連する仕様の節だけを読み込む、編集前にそのファイルと似た例を読む、外部ファイルの中の指示のような文章はデータとして扱う、失敗した箇所のエラーだけを渡す、再開できるセッションの区切り、3つのまとめ方(ブレインダンプ、選択的な取り込み、階層的な要約)、そして予算のルール(約75%で絞り始める、捨てる前に圧縮する、タスクで最も重要な内容を最後に置く)も扱います。矛盾や不足している要件は推測せず、表に出すよう求めます。
出力
プロジェクトのルールファイル、セッションの冒頭に貼れる短いタスクコンテキスト、あなたがまだ埋める必要のある項目の一覧。
こんな場面に
AI 支援開発のためにプロジェクトを整えるとき、規約を無視する、ヘルパーを勝手に作る、長いセッションで集中を失うエージェントを直したいとき。
低リスク:指示のみのファイルでスクリプトはありません。プロジェクトに CLAUDE.md のようなルールファイルを書き込み、追加できる MCP サーバーにも触れますが、インストールはしません。ルールファイルはエージェントの振る舞いを変えるので、書かれた内容を読んでください。架空の Next.js プロジェクトで一度試用し、CLAUDE.md とタスクブロックを書き、実際のファイルで確認できなかった推測部分(コマンド、パターンの例)を明示しました。作者 Addy Osmani、MIT。