"Just make a nice login screen." The first pass looks fine. The second pass drifts. By the fifth round of edits, the codebase is a tangle nobody, human or model, can hold in their head. That has happened to me often enough that I now refuse to open a project directory until nine files exist.
This is a pattern I built up across five projects running in parallel and wrote down in chapter 5 of my Claude Code book. It works because the failure mode of vibe coding is not model capability. It is the absence of structure in the prompt. If you walked up to a senior engineer and said "just make a nice login screen," they would ask you five questions before they typed anything. Claude Code does not ask. It builds. And its "nice" and your "nice" are not the same shape.
The nine files are the structure you would otherwise improvise over five sessions. Six of them answer what are we building. Three of them answer where were we last time.
The six definition docs
Write these before you write code. They are not deliverables; they are context you are preloading.
1. PRD.md: what you are building, and what you are not
Two sections do most of the work. "What we are building" is the easy half. "What we are not building" is the half that stops Claude Code from adding a Slack integration you never asked for.
## In scope - Email + password auth - Task CRUD - Labels - Due dates and reminders ## Out of scope (v1) - Team sharing (v2) - Mobile app (web only for v1) - Slack / Calendar integrations - Realtime sync If you skip the "out of scope" list, every feature you did not name becomes a judgment call the model has to make. It will make a plausible one. That is the worst outcome, because the plausible one is hard to catch in review.
2. APP_FLOW.md: screens and transitions
A list of routes and the main user flows between them. Short.
## Screens - /login - /register - /dashboard - /tasks/:id - /settings ## Register flow Login -> "Sign up" -> Register form -> Validation -> Dashboard The point is not completeness. The point is that when Claude Code is halfway through building the dashboard, you can say "follow APP_FLOW.md" instead of re-explaining the navigation.
3. TECH_STACK.md: pinned versions, and a rule
## Frontend - Next.js 14.2.x (App Router) - TypeScript 5.4.x (strict) - Tailwind 3.4.x - shadcn/ui ## Backend - Next.js API Routes - Prisma 5.x - PostgreSQL 16 ## Tests - Vitest 1.x (unit) - Playwright 1.x (E2E) ## Rule: do not add libraries outside this list. The last line is why this file exists. Without it, Claude Code will reach for a new library every time a problem gets mildly awkward. With it, dependency sprawl stops being a thing you fight every session.
4. FRONTEND_GUIDELINES.md: design tokens and component conventions
Primary color, accent color, font families, radii, spacing scale. Which components live where. Which existing components to prefer over new ones. Nothing fancy, but it is what stops the model from inventing a seventh button style.
5. BACKEND_STRUCTURE.md: schema and API contract
The tables, their columns, their relations. The API routes and their shapes.
## tasks | column | type | note | |----------|--------------|----------------------| | id | UUID | PK | | user_id | UUID | FK -> users.id | | title | VARCHAR(500) | | | status | ENUM | pending / done | | due_date | DATE | nullable | ## API - GET /api/tasks -> { data: Task[] } - POST /api/tasks -> { data: Task } - PATCH /api/tasks/:id -> { data: Task } - DELETE /api/tasks/:id -> { success: boolean } Backends are where the "it works but silently returns the wrong shape" bugs live. A table like this up front removes most of them.
6. IMPLEMENTATION_PLAN.md: phases with a verification gate on each
## Phase 1: foundations 1. Next.js scaffolding + TS config 2. Prisma + schema 3. Auth (register / login / logout) 4. VERIFY: register -> login -> logout cycle works end-to-end ## Phase 2: core 5. Task CRUD API 6. Dashboard UI 7. Task create / edit / delete UI 8. VERIFY: full task lifecycle works end-to-end ## Phase 3: extended 9. Labels 10. Due dates + reminders 11. E2E tests 12. VERIFY: integration tests pass The VERIFY: lines are the cheapest quality gate you will ever write. After each phase, you check the verification works, then you give Claude Code the next phase. You never accumulate three phases of unverified work.
The three memory files
Six docs tell the model what to build. The next three keep the model from losing the thread between sessions.
1. CLAUDE.md: project rules and the index
This is the file Claude Code reads first. Make it the index that points at the six definition docs, plus the handful of invariant rules.
# CLAUDE.md ## Project Next.js 14 + TS + Prisma task manager. ## Definitions - Requirements: docs/PRD.md - Flow: docs/APP_FLOW.md - Stack: docs/TECH_STACK.md (do not add libraries outside this list) - Frontend: docs/FRONTEND_GUIDELINES.md - Backend: docs/BACKEND_STRUCTURE.md - Plan: docs/IMPLEMENTATION_PLAN.md ## Traps - IF a new API route is added -> THEN update BACKEND_STRUCTURE.md - IF a Prisma schema changes -> THEN run `npx prisma generate` The "Traps" section is the one that pays for itself fastest. Every time you catch Claude Code tripping over the same thing twice, add a one-liner here.
2. progress.md: the external memory
Four sections: Done, In progress, Next, Blockers. This is the file that answers "where were we?" at the start of a session after /clear or a context compaction.
# progress.md ## Done - [x] Phase 1 (foundations + auth) - [x] Phase 2: Task CRUD API ## In progress - [ ] Phase 2: dashboard UI (list view done, edit modal missing) ## Next - Task edit modal - Delete confirmation dialog ## Blockers - (none) I have Claude Code update this file automatically at the end of every task. Prompt: "when the task is done, update progress.md before you stop."
3. lessons.md: mistakes you only want to make once
## 2026-02-18 - Next.js App Router: `cookies()` only works in Server Components. In API routes, use `request.cookies` instead. ## 2026-02-20 - Tailwind `dark:` requires `darkMode: 'class'` in config when using the class strategy. A lesson here is private. When the same lesson shows up three times, promote it to CLAUDE.md as a trap rule. That is the self-improvement loop.
Why a 9-file setup works where a 100-line CLAUDE.md does not
The temptation when you first try this pattern is to collapse everything into one giant CLAUDE.md. Resist it. The reason is a term I use a lot and borrow from technical debt: cognitive debt.
Technical debt is code quality degrading until future work gets expensive. Cognitive debt is understanding degrading until no one, human or model, can hold the project in their head. Vibe coding accrues cognitive debt faster than any pattern I have seen. One giant CLAUDE.md is better than nothing, but it dilutes signal. A task that needs the backend schema gets the full design tokens too.
Nine separate files let you load exactly what the current task needs. Progressive disclosure, in the Jakob Nielsen sense:
# Phase 1 implementation > Read PRD.md, TECH_STACK.md, BACKEND_STRUCTURE.md. > Implement Phase 1 from IMPLEMENTATION_PLAN.md. # Dashboard UI work later > Read APP_FLOW.md and FRONTEND_GUIDELINES.md. > Build the dashboard screen. Claude Code can follow the references in CLAUDE.md on its own, but spelling it out in the prompt is more reliable. Context ends up tighter, output ends up more on-spec.
Task decomposition: build by feature, not by layer
One last piece, because it compounds everything above. When you break work into tasks, do it by feature, not by technical layer.
# Wrong: "build the backend first" Step 1: whole DB Step 2: whole API Step 3: whole UI # -> three big phases that only integrate at the end # Wrong: "build the whole app" Step 1: build an e-commerce backend # -> one phase that is impossible to verify # Right: by feature Step 1: user registration (DB + API + UI + test) Step 2: product listing (DB + API + UI + test) # -> each step verifiable end-to-end at completion The rule I use is: the smallest unit I can write an integration test around. That is also the largest unit I can finish before cognitive debt starts accumulating.
The nine files, together
The pattern runs on one idea: write down what the model would otherwise guess. The six definition docs are what-to-build guesses. The three memory files are where-we-were guesses. When all nine exist, Claude Code is no longer improvising structure; it is executing against one.
The deeper reason this works: these documents are not for the AI. They are for me. Five projects in, when I come back to a repo I last touched three weeks ago, PRD.md tells me what I was building and progress.md tells me where I stopped. The AI's memory and mine are the same amnesia, solved by the same files.
The rest of the pattern, including the trap rules that catch Claude Code's most common misreads and the implementation-phase prompts that match each definition doc, is in Practical Claude Code (Kindle Unlimited).


![[AWS] Simplifying External Tool Integration for AgentCore Harness with Connections [AgentCore]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fqiita-user-contents.imgix.net%252Fhttps%25253A%25252F%25252Fcdn.qiita.com%25252Fassets%25252Fpublic%25252Farticle-ogp-background-afbab5eb44e0b055cce1258705637a91.png%253Fixlib%253Drb-4.1.1%2526w%253D1200%2526blend64%253DaHR0cHM6Ly9xaWl0YS11c2VyLXByb2ZpbGUtaW1hZ2VzLmltZ2l4Lm5ldC9odHRwcyUzQSUyRiUyRnMzLWFwLW5vcnRoZWFzdC0xLmFtYXpvbmF3cy5jb20lMkZxaWl0YS1pbWFnZS1zdG9yZSUyRjAlMkYxOTI5NDklMkYxYmVjZGE4YTRmMWRiOWU5OTQyZDljOGMwYjZkZDA3NjkwMTM2NjgwJTJGbGFyZ2UucG5nJTNGMTc0MTQ4MzQxMD9peGxpYj1yYi00LjEuMSZhcj0xJTNBMSZmaXQ9Y3JvcCZtYXNrPWVsbGlwc2UmYmc9RkZGRkZGJmZtPXBuZzMyJnM9MDZlM2QxY2EzNTVhN2Y4N2M2ZTQxY2RlYzdmN2M0ODI%2526blend-x%253D120%2526blend-y%253D462%2526blend-w%253D90%2526blend-h%253D90%2526blend-mode%253Dnormal%2526mark64%253DaHR0cHM6Ly9xaWl0YS1vcmdhbml6YXRpb24taW1hZ2VzLmltZ2l4Lm5ldC9odHRwcyUzQ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zVjODI5MDc1ZWM%26mark-x%3D120%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjEuMSZ3PTgzOCZoPTU4JnR4dD0lNDBOYW5hXzc3NyZ0eHQtY29sb3I9JTIzMUUyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1wYWQ9MCZzPTg1YzQ4MzUyMmVkMGVhNmYxYjhkZjU5MjVjYzhiNjQz%26blend-x%3D242%26blend-y%3D454%26blend-w%3D838%26blend-h%3D46%26blend-fit%3Dcrop%26blend-crop%3Dleft%252Cbottom%26blend-mode%3Dnormal%26txt64%3DS0RESeOCouOCuOODo-OCpOODq-mWi-eZuuOCu-ODs-OCv-ODvOagquW8j-S8muekvg%26txt-x%3D242%26txt-y%3D539%26txt-width%3D838%26txt-clip%3Dend%252Cellipsis%26txt-color%3D%25231E2121%26txt-font%3DHiragino%2520Sans%2520W6%26txt-size%3D28%26s%3Da2c44eb6df6b020058c45150d4498ed3)