A practical workflow for building with an AI coding assistant
An AI coding assistant writes code quickly, which means it can also break things quickly. The fix is not to slow the assistant down but to work in a loop that catches mistakes early. This playbook describes that loop step by step.
The core loop
- Commit the current working state.
- Describe one small change.
- Let the assistant make it.
- Read the diff.
- Run the tests and try the feature.
- Commit if good; revert if not.
Everything else in this guide supports that loop.
Step 1: put the project under version control first
Before the assistant touches anything, run git init and make a first commit. Version control is your undo button for the whole project. Commit after every change that works, with a message that says what changed:
git add -A
git commit -m "Add CSV export to the orders page"
If a later change goes wrong, git diff shows exactly what moved, and git restore . throws away uncommitted edits. Add a .gitignore early so build output and secret files never enter history.
Step 2: make changes small
A good request fits in a few sentences and touches a few files. Compare:
Too big: “Add user accounts, a settings page and email notifications.”
Right size: “Add a settings page at /settings with one toggle for dark mode, saved in the existing preferences table. Do not change other pages.”
Small changes give small diffs, and small diffs are actually read. A two-thousand-line diff is usually accepted on trust, which defeats the purpose of reviewing.
Step 3: write or request tests before the feature
Tests turn “it seems to work” into “it does what we said”. A useful pattern:
- Describe the behaviour in plain words, including edge cases.
- Ask the assistant to write tests for that behaviour first, and check that they fail.
- Ask for the implementation, and run the tests until they pass.
- Read the tests yourself. Make sure they check results, not just that code runs.
Watch for an assistant that “fixes” a failing test by weakening the test. A changed assertion deserves a close look.
Step 4: keep a task note
Assistants lose track of decisions across long sessions. Keep a short text file in the project with:
- What the project does and how to run it.
- Conventions: language version, folder layout, naming style.
- Decisions already made and why.
- Things not to touch.
Point the assistant at this file at the start of each session. Update it when a decision changes.
Step 5: protect secrets and data
- Keep keys in environment variables or a local file listed in
.gitignore. - Use a test database or sample data while developing.
- Do not paste production credentials into a chat.
- Give any automated tool the least access that works.
Step 6: add automatic checks
Once the project matters, run tests and a linter automatically on every push using a continuous integration service. That way a broken change is caught even on a day you forget to run the tests by hand.
Signs the session is going badly
| Sign | What to do |
|---|---|
| The same error keeps coming back after “fixes” | Revert to the last good commit and describe the problem differently. |
| Files you did not mention keep changing | Tell it which files it may edit; reject the rest. |
| You no longer understand the structure | Stop adding features. Ask for an explanation and simplify. |
| Tests are being deleted or loosened | Restore them and ask why they failed. |
Questions
How often should I commit?
After every change that works and that you would be sorry to lose. Several times an hour is normal during active work.
Should I let the assistant run commands itself?
For reading files and running tests, it can save time. Keep approval on commands that delete, deploy or push.