AI
How to Brief an AI Coding Agent So It Doesn't Wreck Your Repo
Lessons from building and shipping a production Laravel app with an agent doing most of the typing.
AI coding agents have moved from autocomplete to something closer to a junior developer who never sleeps. Give one a clear task and it will scaffold models, write migrations, build admin panels and produce hundreds of passing tests in an afternoon.
Give one a vague task and it will do the same — confidently, quickly, and in the wrong direction.
These lessons come from building a multi-author publishing platform with an agent doing most of the implementation. The app is live; the mistakes along the way were instructive.
Write the spec before the agent writes code
The single most valuable artefact was a long specification file in the repository root: stack, roles, workflow states, security requirements, SEO requirements, design tokens and a list of phases.
It does two jobs. It forces you to decide what you actually want — and it gives the agent something durable to re-read every session. Agents don't remember yesterday's conversation. A file in the repo is the only memory you can rely on.
Keep three kinds of documents:
- The spec: what the product must do and the rules it must follow.
- A context file: current state, production constraints, decisions made and why.
- A development log: what was done in each phase, with test counts and caveats.
Point every new session at these files first, and ask the agent to summarise the current state in ten lines before touching code. If the summary is wrong, you've caught a problem before it became a commit.
Work in phases, and stop between them
"Build the whole CMS" produces a sprawling, shallow result. Breaking the work into phases — foundation, workflow, frontend, SEO, hardening — and instructing the agent to stop and report after each one changed everything.
Each stop is a review point. You read the report, test the feature yourself, and catch direction problems while they're cheap. Several real issues surfaced this way: images served through URLs that expired after an hour (fatal for SEO and social previews), a timezone change that would have silently shifted every stored date by five and a half hours, and a "trusted proxies" setting that would have let attackers bypass login rate limits.
None of those would have been caught by tests alone, because the tests were written to the same flawed assumption as the code.
Protect production with branch rules — in writing
If your main branch auto-deploys, an agent that pushes to it can take your site down. Put the rules in the spec, not just in a chat message:
- Work only on a development branch.
- Never push, merge or rebase onto main.
- Never commit environment files, credentials or dependency folders.
- Tests and the linter must pass before every push.
- Migrations must be additive; never edit one that's already been committed.
Then verify. Ask for git branch and the recent log in every report, and check that main hasn't moved. Agents follow written rules well; they follow rules they've never seen not at all.
Insist on verification that matches reality
Agents report success honestly — according to the checks they ran. The trouble is that their environment often isn't yours.
Three examples from this project:
- Empty folders: tests passed locally, then failed in CI because an empty test directory wasn't tracked by git. The fix became a rule: every phase must pass on a fresh clone, built exactly the way CI builds it.
- Different databases: the agent's local database silently accepted a query that compared an integer column with a date string; CI's stricter database rejected it. Later, a JSON column returned keys in a different order on CI. The fix: run CI on the same database engine and version as production.
- The real server: shared hosting disabled functions the code assumed were available, and the cron system didn't run commands in the expected format. No test suite catches that. Only deploying and watching does.
Ask for evidence, not adjectives. "Tests pass" is a claim; "361 passed, run on a fresh clone against the production database version" is evidence.
Review the decisions, not just the diff
Good agent reports include a "decisions worth flagging" section. Read it carefully — that's where the agent tells you what it chose when your spec was silent.
Most decisions will be sensible. Some won't. In this project an agent chose to trust all forwarded proxy headers so signed URLs would work behind a load balancer. Reasonable on the surface; in practice it meant any client could fake their IP address. The decision was listed openly in the report, which is exactly why it got caught.
Make it easy for the agent to be honest: ask explicitly for decisions, assumptions, limitations and anything it couldn't verify.
Feed production findings back into the docs
When you discover something on the live server — a disabled PHP function, a cron quirk, a hosting limit — don't just fix it. Tell the agent to record it in the context file as a constraint.
Otherwise the next session will happily write code that depends on the thing you just learned doesn't work. Documentation is how an agent with no memory accumulates experience.
Keep humans on the irreversible steps
Agents are excellent at writing code and terrible judges of when to stop. Keep these actions for yourself:
- Merging to production branches
- Running destructive commands on live servers
- Entering credentials anywhere
- Approving changes to security settings
Never give an agent production SSH keys or secrets "to save time." A single mistaken command can delete a database, and keys pasted into a session can end up in logs or commits.
The short version
Treat an AI coding agent like a very fast contractor who reads every word of the brief and remembers none of the meetings. Write the brief down. Break the work into phases. Make it stop and report. Verify in an environment that matches production. Read its decisions. Keep the dangerous buttons for yourself.
Do that, and the speed is real. Skip it, and you'll spend the time you saved debugging production at midnight.
Related reading: Seven prompting habits for better AI output · Laravel queues and cron on shared hosting · Dev–prod parity lessons
Frequently asked questions
Can an AI coding agent build a production app?
Yes, with structure. Agents can implement large parts of a real application quickly, but they need a clear specification, phased work, human review between phases and verification in an environment that matches production.
How do I stop an AI agent from breaking production?
Have it work only on a development branch, write branch and secrets rules into the repo, require tests to pass on a fresh clone, and keep merges to the production branch as a manual human step.
Should I give an AI agent SSH access to my server?
No. Keep credentials and destructive server commands for yourself. Paste error output to the agent instead of giving it access.
Why do agent-written tests pass but production still fails?
Because the agent's environment differs from production — different database engines, untracked files, disabled server functions. Match CI to production and test on a fresh clone.
Related
AI
ChatGPT Advanced Voice Is Being Retired on 11 December: What GPT-Live Changes
On 11 December 2026, ChatGPT retires Advanced and Standard voice and moves everyone to GPT-Live. Here's what GPT-Live does differently, what happens t...
AI
ChatGPT Go Free Year Ending in India: Will You Be Charged ₹399, and How to Cancel
If you claimed free ChatGPT Go in India last year, your 12 months are ending. Here's when the ₹399 charge kicks in, how to cancel on web, Android and...
AI
ChatGPT vs Gemini vs Claude: Which Free AI Plan Is Best in India Right Now?
ChatGPT Free now shows ads in India, Gemini's free tier picks models for you, and Claude's free plan uses Sonnet and Haiku. Here's how the three free...
The stream
All storiesUpcoming Phones in India: December 2026 Launches to Wait For
Xiaomi 18 Pro, iQOO 16 and OnePlus 16R are the big flagships expected in India around December 2026, with Vivo X500 and Motorola Signature 27 already out. Here's what's confirmed so far.
Windows 10 ESU Now Runs to October 2027: How to Check Your PC Is Enrolled
Windows 10 Extended Security Updates for home users now last until 12 October 2027. But only enrolled PCs get them. Here's how to check, how to enroll for free, and when to plan your move.
GTA 6 PC Release Date: Everything Rockstar and Take-Two Have Actually Said
There is no official GTA 6 PC release date. Take-Two says any PC news will come from Rockstar. Based on GTA 5 and Red Dead Redemption 2, the realistic window is late 2027 to 2028.
ChatGPT Advanced Voice Is Being Retired on 11 December: What GPT-Live Changes
On 11 December 2026, ChatGPT retires Advanced and Standard voice and moves everyone to GPT-Live. Here's what GPT-Live does differently, what happens to custom GPTs and video, and your old chats.
ChatGPT Go Free Year Ending in India: Will You Be Charged ₹399, and How to Cancel
If you claimed free ChatGPT Go in India last year, your 12 months are ending. Here's when the ₹399 charge kicks in, how to cancel on web, Android and iPhone, and whether staying on Go is worth it.