Every productive AI coding session follows the same pattern. Whether you’re building a new feature, fixing a bug, or refactoring legacy code, the loop is the same: plan, prompt, review, commit.
This guide breaks down the full session loop so you can internalize it and move faster.
The Session Loop
Here’s the complete workflow visualized. Every session starts with a clean git state and ends with a committed milestone:
Step by Step
1. Start with a clean slate
Always begin by running git status. If you have uncommitted changes from a previous session, commit or stash them. A clean working tree means you can always roll back if something goes wrong.
2. Read your plan
Open plan.md (or whatever you call your task tracker). If you already know what you’re building, skip to prompting. If not, you need to research first.
3. Research before you build
Before asking AI to generate code, check if the problem has been solved before. Look for:
- Existing implementations in your codebase
- Documentation for the libraries you’re using
- Working examples on GitHub or Stack Overflow
Feed these references to your AI as context. The better the context, the better the output.
4. Write a plan
Define your scope in a markdown file:
- What are you building? (one sentence)
- What are the major components?
- What’s the smallest working version?
- Where are the risky unknowns?
5. Craft your prompt
This is where most people rush. A good prompt includes:
- Goal: What you want to achieve
- Context: Relevant code, file paths, constraints
- Examples: What success looks like
- Anti-patterns: What to avoid
6. Review the output
Don’t blindly paste AI output. Read every line. Ask yourself:
- Does this actually solve the problem?
- Are there edge cases it missed?
- Does it follow the project’s patterns?
7. The debug loop
If the output has issues, you enter the debug loop. Add logging, isolate the problem, and re-prompt with more specific context.
The 15-minute rule: If you’ve been stuck on the same issue for more than 15 minutes, start a fresh chat. Restate your goal from scratch with cleaner context. Stale context is the #1 productivity killer in AI-assisted development.
8. Test and commit
Run your tests. Run your linter. Verify everything works. Then commit with a clear message describing what you built, not how you built it.
9. Consolidation pass
After the feature is complete, do one final pass:
- Remove any debug logging
- Clean up unused imports
- Add documentation if the code isn’t self-explanatory
- Update your plan to check off completed items
The Planning Decision Tree
Before starting any feature, run through this decision tree to make sure you’re building the right thing:
Key Takeaways
- Always start clean —
git statusbefore anything else - Plan before you prompt — 5 minutes of planning saves 30 minutes of debugging
- Context is king — feed your AI real examples, not vague descriptions
- The 15-minute rule — fresh context beats stale context every time
- Commit often — small, atomic commits make rollback painless
- Consolidate at the end — clean code ships faster than messy code
The session loop isn’t just a workflow — it’s a habit. The more you practice it, the faster you’ll move.