Topic 1 of 4 · 4 min read
Feature flags around agent-built features
Goal: Wrap an agent-built change in a feature flag with a clear owner, safe default and removal date.
Ship an agent-built feature dark, behind a flag that has an owner, an off-by-default value and a removal date. Merging code and showing it to users become two separate decisions, and the second one can be undone in seconds.
Check yourself · 1 of 3
What should a new release flag default to when the flag service is unreachable?
Why it matters
An agent such as Claude Code, Codex, Copilot or Cursor can produce a large change in minutes. Review catches a lot, but not everything. A flag means a mistake that slips through reaches nobody until you turn it on, and turning it off again needs no deploy.
How to do it
- Name the flag after the feature, not the ticket:
checkout.new_tax_engine, notflag_2291. - Default to off. If the flag service is down or the key is missing, users must get the old behaviour. Say this in the code, not in your head.
- Keep the old path intact until the flag is gone. The agent must not delete or "tidy" it.
- Record an owner and a removal date next to the flag: a comment, a registry entry or a flag-service field.
- Evaluate once, near the edge. Check the flag at one decision point, not in ten places.
- Plan the cleanup. A release flag is temporary. Once the feature is at 100 percent and stable, delete the flag and the dead branch. Ask the agent to do it in its own small change.
If you use a flag service, a standard such as OpenFeature keeps your code independent of the vendor.
Before and after
An agent was asked to add a new tax calculation. Its first version replaced the old function.
export function calcTax(order: Order) {
return newTaxEngine(order);
}
The fixed version keeps both paths and fails safe.
// owner: payments-team, remove after 2027-02-01
export function calcTax(order: Order, flags: Flags) {
if (flags.bool("checkout.new_tax_engine", false)) {
return newTaxEngine(order);
}
return legacyTax(order);
}
What goes wrong
- Flags that never die. Old flags pile up, and nobody knows which branch is live. Fowler's article on toggles treats short-lived release toggles as inventory to be kept small.
- Wrong default. A default of true means an outage in the flag service turns on untested code.
- Flag inside the flag. Nested checks create combinations nobody tested.
- Agent edits both paths. A "small refactor" of the legacy branch changes behaviour for everyone, flag or not.
Examples
Brief the agent with the flag rules
Add the new tax engine behind flag checkout.new_tax_engine.
- Default false. Do not change legacyTax().
- Add an owner and removal-date comment.
- Check the flag in calcTax() only.
The agent now has the flag name, default, scope and the part it must not touch.
The stale flag audit
A team lists flags older than 90 days. Seven are at 100 percent for months. They ask an agent to open one cleanup PR per flag: delete the check, delete the legacy branch, delete the old tests. Each PR is small and reviewable.
Key points
- Merging code and exposing it to users are separate decisions when a flag sits between them.
- A flag defaults to off, so a missing key or a flag-service outage gives users the old behaviour.
- Every flag has an owner and a removal date written next to it.
- The legacy path stays untouched until the flag is removed, and an agent must not tidy it.
- Removing the flag and the dead branch is its own small change, planned before you ship.
Common mistakes
- Letting the agent replace the old code instead of adding a branch beside it.
- Choosing a default of true because the feature is finished.
- Creating a flag with no owner or removal date.
- Scattering the same flag check across many files.
Check yourself · 2 of 3
An agent's change deletes the old function and calls the new one directly. What is the main problem for a flagged release?
Check yourself · 3 of 3
A release flag has been at 100 percent for four months. What is the best next step?
Practice items, not counted towards your mastery.
Start here
- Feature Toggles (martinfowler.com) (opens in a new tab)ArticleFree
The standard taxonomy of toggles (release, ops, experiment, permission) and why short-lived ones must be removed.
- Canarying releases (Google SRE Workbook) (opens in a new tab)BookFree
How to release to a small slice, pick metrics to compare and decide when to roll back.
- Parallel Change (martinfowler.com) (opens in a new tab)ArticleFree
The expand, migrate, contract pattern behind reversible schema and API changes.
More for this topic
- OpenFeature (opens in a new tab)ToolFree
A vendor-neutral standard API for evaluating feature flags, so code does not depend on one flag vendor.