How to Use AI for Coding Without Breaking Production
Summary
To use AI for coding safely, give the assistant small, specced tasks, let failing tests judge its output instead of your eyes, cap each diff so review stays real, and ship the result behind a feature flag with an SLO gate. DORA's 2025 data shows 90% adoption but low trust, and METR measured a 19% slowdown for experienced developers. The workflow below keeps the speed and shrinks the blast radius.
How to use AI for coding without breaking production comes down to three habits: hand the assistant small, specced tasks, make tests the judge instead of your eyes, and ship its output behind a flag with an SLO gate. The 3 a.m. page that follows a 900-line AI diff is rarely the model's fault. It is a rollout problem. This guide covers the workflow we see holding up in teams of 50 to 500 engineers.
Start with the task, not the tool
Most advice on AI coding opens with a tool ranking. That is the wrong first decision. The first decision is what you are asking for, because the failure rate of an assistant tracks task size far more than model choice.
Three task shapes work reliably today:
Bounded edits: rename a parameter across a module, add a field to a DTO, convert a callback to async/await.
Test scaffolding: generate table-driven cases for a function that already exists and already has a spec.
Glue code: the retry wrapper, the pagination loop, the config parser nobody wants to write twice.
Three shapes fail often enough that we treat them as opt-in with a second reviewer: auth and permission changes, anything touching money, and schema migrations. The model has no idea what your blast radius is. You do.
Skip "build me the whole service" prompts. They produce code that compiles, passes a happy-path demo, and carries assumptions nobody wrote down. That is how you end up reading a diff for an hour and still not knowing what it does.
Write the spec before the prompt
The single highest-leverage habit is a half-page spec before you open the assistant. Not a prompt. A spec: inputs, outputs, error behavior, what must not change, and the performance budget.
A useful template for a platform team:
Goal: one sentence, with the observable behavior.
Constraints: language version, libraries already in use, no new dependencies.
Invariants: what existing tests must keep passing.
Failure behavior: timeouts, retries, what the caller sees when it breaks.
Out of scope: the files and modules the assistant must not touch.
Paste that, plus the two or three files that define the surrounding conventions. Context beats cleverness. An assistant that sees your error-handling pattern will copy it. One that does not will invent its own, and you will find out in review or in prod.

Which assistant fits which job
Pick the mode by the size of the change, not by brand loyalty. Inline completion suits the 10-line edit where you already know the answer. An agent that reads the repo and runs commands suits multi-file work where the cost is navigation, not typing.
Cursor is the IDE-native option: fast for in-editor edits and multi-file changes you watch happen. Worth it if your team lives in the editor and wants to see every hunk before accepting it. Skip it if your reviewers insist on terminal-driven, scriptable workflows.
Claude Code runs in the terminal and works through a task with the repo, the test runner, and git. It suits larger refactors where you want the agent to run the suite and iterate until it is green. The tradeoff is that you give up the constant inline visibility, so your review discipline has to be stronger, not looser.
GitHub Copilot is the lowest-friction path for an org already on GitHub: completions, chat, and pull request summaries inside the workflow your team already has. It is the easy default for procurement. It is rarely the sharpest tool for a large refactor.
If you are choosing between two of these, we already ran the numbers in our Cursor vs GitHub Copilot comparison. Do not spend a week on this decision. Pilot two tools on the same ticket and compare the diffs.
Let tests be the judge
Here is the habit that separates teams who ship AI code safely from teams who ship it nervously: the tests exist before the assistant writes the implementation.
Write the failing test first, or have the assistant write it from your spec and review that instead. Then ask for the implementation. The loop is short. The assistant proposes, the suite runs, the red tells it what it got wrong. You read the test, which is small, instead of the implementation, which is not.
A minimal example in Go. You write the contract:
func TestBackoff(t *testing.T) {
cases := []struct {
attempt int
want time.Duration
}{
{0, 100 * time.Millisecond},
{1, 200 * time.Millisecond},
{5, 3200 * time.Millisecond},
{20, 30 * time.Second}, // capped
}
for _, c := range cases {
if got := Backoff(c.attempt); got != c.want {
t.Errorf("attempt %d: got %v want %v", c.attempt, got, c.want)
}
}
}The assistant fills in Backoff. The cap at 30 seconds is the line that matters, and it is the line a model most often forgets, because nothing in a happy-path prompt mentions it. A test that pins the cap catches it in two seconds.
Two caveats. First, do not let the assistant write both the test and the code from the same ambiguous prompt, because it will agree with itself. Second, mutation-style spot checks help: change one operator in the implementation and confirm a test goes red. If nothing fails, the suite was decoration.
What the research says about speed
The honest answer on productivity is mixed. In a randomized trial, METR measured experienced open-source developers working on their own repositories and found they took 19% longer with AI tools than without, while believing they were faster. That study covered early-2025 tools and a narrow population, and METR itself cautions against generalizing it.
The useful reading is not "AI is slow". It is "your sense of speed is a bad instrument". Measure cycle time and change failure rate on real tickets for a month, per team, before you write the business case.

The review step is where teams get hurt
The 2025 DORA report on AI-assisted development puts adoption at 90% of surveyed professionals, and reports that roughly 30% trust AI-generated code only a little or not at all. DORA's framing is that AI amplifies the system around it. Strong pipelines get faster. Weak ones get faster at producing incidents.
That matches what we see in post-mortems. The incident rarely traces to a hallucinated API. It traces to a reviewer who approved a large, plausible-looking diff because it read well.
Rules that hold up:
Cap the diff. If an AI-assisted PR is over 400 changed lines, split it. Reviewer attention is the scarce resource.
Label AI-assisted PRs. Not for blame. For measurement. You cannot compare failure rates if you cannot see which changes had help.
Same gates for everyone. Linters, type checks, secret scanning, dependency review. The assistant does not get a fast lane.
Review the prompt too. For anything non-trivial, paste the spec into the PR description. The reviewer needs to know what was asked.
The post-mortem will ask what the author understood. If the answer is "the model wrote it", you have a process gap, not a model gap.
Ship AI-written code behind a flag
This is the part most "how to use AI for coding" guides skip, and it is the part that decides whether a bad diff costs you a minute or a Saturday.
Treat AI-assisted changes as higher-variance changes. You do not need to distrust them. You need to size the blast radius before they reach everyone.
A feature management platform such as LaunchDarkly gives you the mechanism: wrap the new path in a flag, roll it to 1%, then 5%, then 25%, and hold each ring until the numbers say continue. The flag is also your revert. Flipping it off takes seconds. A redeploy takes minutes and a pipeline you hope is green.

The gate is what makes it a rollout instead of a slow deploy. Define it before you ship:
Pick the SLI closest to the change: error rate on the endpoint, p99 latency, queue depth.
Set the threshold from your SLO budget, not from a gut feeling. If the budget burns 10x faster than baseline in the 1% ring, stop.
Automate the stop. A human watching a dashboard at 2 a.m. is not a control. A rule that flips the flag back is.
This is the same logic behind a canary deployment: small exposure, a measurable signal, an automatic exit. The assistant wrote the code in ten minutes. The rollout is what earns it the right to reach everyone.
A weekly loop that keeps you honest
Adopting this without a feedback loop means drifting back to old habits within a month. A lightweight loop:
Monday: pick two or three tickets suitable for assistant work using the three safe shapes above.
During the week: label AI-assisted PRs, keep each one under the diff cap, and flag every rollout.
Friday: look at four numbers per team: lead time for changes, change failure rate, time to restore, and review time per PR. Compare labeled and unlabeled changes.
If change failure rate for labeled PRs is higher after a month, the answer is rarely "ban the tool". It is usually smaller diffs, stronger specs, or a tighter gate. If it is lower, widen the scope one task shape at a time.
What we would actually do on Monday
If you have a platform team and no policy yet, do these five things this week:
Write the half-page spec template and put it in the repo.
Add an
ai-assistedPR label and a 400-line soft cap.Require a failing test before the implementation for any assistant-written logic.
Put the first AI-heavy change behind a flag with a single SLI gate.
Schedule the Friday review for the next four weeks.
That is it. No tool migration, no policy document nobody reads. The assistant is a fast, confident colleague with no memory of your last incident. Your process has to remember it for them.
Which part of your pipeline would catch a plausible, wrong diff today: the review, the tests, or the rollout?