# Ship AI-written features behind a flag you can switch off

- Author: RomanMotion (https://wurk.fun/user/RomanMotion)
- Published: 2026-11-03
- Canonical (HTML): https://wurk.fun/blog/ship-ai-written-features-behind-a-flag-you-can-switch-off
- Cover image: https://ik.imagekit.io/wurk/browser-uploads/f1c626b5c17e7f0a61dfbbe7a20d85ae7b33a20527243aeec2ee1d0a8b87562a/f954e5e9-ce04-4b00-b4ee-7fb085518d83/cover-flags.jpg?wurkUpload=v1.J4vAdwjUq5KHDVH7dpzsEyy2_icNPax51wvRPQkFnRw

---

You asked your coding agent for one small feature, it wrote a few hundred lines, and now that change is sitting there waiting to go live. The part that should worry you is not the review, it is what happens the second it merges: every visitor gets it, and if it breaks you are stuck pushing a fix, waiting on a build, and watching real people hit errors in the meantime. A feature flag turns that into a choice you can undo with one setting, and it needs nothing more than a value in your config.

The direct answer: wrap the new code in an if-statement that reads a setting from your environment or config file. Merge and deploy with the setting off, so the new code sits in production but no one runs it. Turn it on for yourself, then for a few people, then for everyone. If something misbehaves, flip the setting back and the old path takes over, with no code revert and no new build.

## The problem: deploy means release

In most small apps, deploying and releasing are the same act. The build goes out and the feature is live to everyone at once. That is fine when the change is a label or a color. It is not fine when the change touches payments, sends an email, or writes to a database.

Your coding agent writes confidently and fast, and that speed is exactly why the risk is real. A helper that worked on your machine, an API call that behaves differently under load, an edge case the tests never covered. The point is not to distrust the code. It is to stop betting the whole site on the first deploy. The idea itself is not new, and Martin Fowler's [article on feature toggles](https://martinfowler.com/articles/feature-toggles.html) lays out the concepts if you want the deeper version.

## What a feature flag is

A flag is one condition around the new code path, plus one setting to control it. Here is the whole idea in JavaScript:

```javascript
// feature-flags.js
export const flags = {
  newCheckout: process.env.FEATURE_NEW_CHECKOUT === "true",
};

// checkout.js
import { flags } from "./feature-flags.js";

if (flags.newCheckout) {
  renderNewCheckout();
} else {
  renderOldCheckout(); // untouched, still the default
}
```

In Python it is the same shape, reading an environment variable and branching. The old code is not deleted or rewritten, it just keeps running until you decide the new path is better. You can read the value from a plain config file, a secret, or your host's environment settings. No paid service is required to start.

One honest caveat: an environment variable is usually read when the app starts, so on most hosts changing it means a restart (still no code change, no revert, no new build). If you need the switch to work instantly, have the app read the flag from a config file or a database row on each request instead.

## Ask your coding agent to build it this way

The trick is to give the agent the flag in the instructions, not after. Paste something like this:

```
Add [feature] behind a feature flag.

- Default the flag to OFF, so current behavior is unchanged on deploy.
- Do not modify or remove the existing code path.
- Route all new logic through the flag check.
- Add a test for the flag ON and a test for the flag OFF.
- Read the flag from config/env. Keep it a plain value, no external service.
```

Three things matter in that prompt. Default off means the merge is safe the moment it lands. The old path staying untouched means switching off actually restores the previous behavior instead of a half-rewritten mess. And the two tests mean you can prove both branches work before anyone else sees them. If you want an agent setup to run this prompt in, you can [try the zcode agent harness free](https://zcode.z.ai/invite/ALWM9JUA) (our referral link).

## Rollout: off, just you, everyone, delete

Turn it on in stages, not all at once.

1. Deploy with the flag off. The code is in production, dormant.
2. Turn it on for yourself only, usually by checking your user id or a query parameter like `?newCheckout=1` on your staging or preview URL.
3. Turn it on for a small slice, a test account or a percentage, and watch it for a day.
4. Turn it on for everyone.
5. Delete the flag and the old path.

Step two is where you learn the most, because you are using the real feature in the real environment without putting anyone else at risk. Step five is the one people skip, and it is the one that matters most.

## Clean up: flags are debt

A flag that stays forever becomes a maze. Six months later nobody remembers which branch is live, and the "temporary" condition is welded into the code. Treat every flag as a loan you pay back.

The habit that fixes this costs nothing: put a removal date in a comment next to the flag the day you create it.

```javascript
// FEATURE_NEW_CHECKOUT: remove by 2026-12-01
```

Once the feature has been on for everyone and stable for a week or two, do the cleanup pass: delete the flag, delete the old code path, delete the flag-off test, keep the flag-on test.

That cleanup is a good job to hand back to your coding agent: it is small, it has a clear finish line, and the remaining test tells you it worked. If you are choosing a plan for that kind of steady agent work, our referral link gives you [10% off GLM coding plans](https://z.ai/subscribe?ic=R0K78RJKNW).

## Kill-switch checklist for money and messages

Some features should never ship without a flag. If it spends money, sends a message, or changes data, run this list before you merge:

```
[ ] Flag defaults to off in every environment.
[ ] I can turn it off without a code change, from config or an environment variable.
[ ] The old path still works with the flag off.
[ ] There is a test for the flag-off path, not just the new one.
[ ] I watched it run with the flag on, using my own account.
[ ] There is a dated comment to remove the flag.
```

Anything that charges a card or fires off an email belongs behind this list. The cost of skipping it is a live bug that keeps spending or sending while you scramble to build a fix. If you are wiring this into a bigger setup, the [CI check post](https://wurk.fun/blog/add-a-ci-check-so-your-coding-agent-can-t-merge-broken-code) on our blog covers catching a bad merge before it ever reaches production, and there is [more on our blog](https://claw.rommark.dev) about working with coding agents.

If this saved you a bad deploy, a tip on WURK goes a long way. Thanks for reading.
