The short version
Start from a clean commit. Give the AI one clear task. Read what it wrote. Let lint, typecheck and tests decide if it’s done. Commit. When you’re going in circles, stop and start a fresh session with a short handoff note.
Every productive AI coding session follows the same rhythm, whether you’re building a feature, fixing a bug or refactoring. This guide is that rhythm. What the AI should know before the session starts is in AI Context Files.
The loop
Before you prompt: plan
Five minutes of planning saves an hour of debugging. Before the first prompt, write down in plan.md:
- To do: What you’re building, in one sentence.
- To do: Whether it has been built before. If so, find a working example or the library’s docs and give them to the AI.
- To do: The main parts, and what data passes between them.
- To do: The riskiest unknown. If there is one, try it in a small throwaway test first.
- To do: The smallest version that would work.
Then ask the AI for two or three approaches with their trade-offs before it writes any code. Its first instinct isn’t always its best.
The session, step by step
- Run
git status. If anything is uncommitted, commit it or stash it, so you always have a clean point to return to. Secrets and Git Discipline covers committing safely. - Open
plan.mdand pick the next item. - Prompt one task. Include the goal, the relevant files, an example of what success looks like, and anything to avoid.
- Read every line of the output. Does it solve the problem? Does it follow the project’s patterns? If you don’t understand part of it, ask the AI to explain it in plain English before you accept it.
- Run lint, typecheck and the tests. If they fail, give the AI the exact error, not a description of it.
- Commit with a message that says what changed, then push.
- Pick the next item, or finish the session.
Understand it, don't rewrite it
You don’t need to be able to write the code yourself. You need to know what each part does, because when it breaks you have to point the AI in the right direction.
When to start fresh
Long conversations degrade. Older details get summarised or dropped, and the AI starts forgetting decisions it made an hour ago.
Start a fresh session when you see any of these:
- It suggests a fix it already tried.
- You’ve explained the same thing twice.
- About 15–20 messages on one problem without progress.
- You’re starting a genuinely new feature.
In Claude Code, /clear starts a new conversation with empty context, and /compact summarises the conversation so far to free up room while you keep going. Other tools have a “new chat” button that does the same as /clear.
The handoff note
Before you clear a session, or at the end of the day, ask for a handoff:
Before we finish, write HANDOFF.md with:
1. What we built
2. What worked and what didn't
3. The current state of the feature
4. What needs to happen next
5. Decisions or patterns to carry forward
Next session: Read HANDOFF.md and continue from there. It takes 30 seconds and saves a lot of re-explaining.
Session checklist
Before starting
- To do:
git statusis clean. - To do:
plan.mdsays what this session is for. - To do: Fresh session, with the context file loaded.
During
- To do: One task per prompt.
- To do: Read the output before accepting it.
- To do: Lint, typecheck and tests after each change.
Before finishing
- To do: Final work committed and pushed.
- To do:
plan.mdandHANDOFF.mdupdated. - To do: Any file over 400 lines noted for the next consolidation pass.
Next: How to Keep a Vibe-Coded Codebase from Rotting, or back to the full guide.
