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.

Two monitors showing code diffs on a night-time engineering desk

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:

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:

  1. Goal: one sentence, with the observable behavior.

  2. Constraints: language version, libraries already in use, no new dependencies.

  3. Invariants: what existing tests must keep passing.

  4. Failure behavior: timeouts, retries, what the caller sees when it breaks.

  5. 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.

Laptop with a small code diff next to a handwritten review checklist

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.

Sticky notes on a glass wall arranged as concentric rollout stages

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:

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.

Breaker panel with one toggle switch flipped down like a kill switch

The gate is what makes it a rollout instead of a slow deploy. Define it before you ship:

  1. Pick the SLI closest to the change: error rate on the endpoint, p99 latency, queue depth.

  2. 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.

  3. 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:

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:

  1. Write the half-page spec template and put it in the repo.

  2. Add an ai-assisted PR label and a 400-line soft cap.

  3. Require a failing test before the implementation for any assistant-written logic.

  4. Put the first AI-heavy change behind a flag with a single SLI gate.

  5. 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?

Frequently asked questions

What is the best way to use AI for coding?
Write a short spec, give the assistant a small bounded task plus the files that define your conventions, and let a failing test verify the result. Review the diff as you would any human PR, and ship it behind a flag.
Is AI-generated code safe to ship to production?
It is safe when it passes the same gates as human code and reaches users gradually. Run linters, type checks and secret scans, then roll out behind a feature flag with an automatic rollback tied to an SLO.
Does AI actually make developers faster?
Evidence is mixed. A METR randomized trial found experienced open-source developers took 19% longer with early-2025 tools while believing they were faster. Measure cycle time and change failure rate on your own tickets.
Which tasks should I avoid giving to an AI assistant?
Be cautious with auth and permission changes, anything touching money, and schema migrations. These have a large blast radius and need a second human reviewer who understands the system.
How big should an AI-assisted pull request be?
Keep it under roughly 400 changed lines. Past that, reviewers skim, and plausible but wrong code gets approved. Split large changes into steps that each have their own tests.
Should I label AI-assisted pull requests?
Yes, for measurement rather than blame. Labels let you compare change failure rate and review time between assisted and unassisted changes, so you can widen or tighten usage with data.