Tutorial 02 Brownfield 8 steps · 40 to 60 min · Intermediate

Add a feature to a codebase you did not write

Bring your own repo, or clone any open-source app you like. The worked example adds rate limiting to an existing API endpoint, but the shape applies to any feature in any brownfield system. Brownfield is where agents do the most damage, so the emphasis is on context, verification, and reversibility.

Add a feature to a codebase you did not write
1

Prime the agent on the codebase

Prompt (paste into your agent)
Follow the context-engineering skill. Read this repo and write a short rules file (CLAUDE.md or AGENTS.md) capturing its conventions: structure, patterns, test commands, and the things a newcomer would get wrong.
What happens

The agent surveys the repo and records its conventions where every future session will read them.

Why it matters

An agent starts every session cold and fills gaps with confident guesses. Writing the conventions down once stops it re-deriving your project from zero and inventing patterns you do not use.

Checkpoint. A rules file exists that matches how the repo actually works.
2

Ground the approach in the real docs

Prompt (paste into your agent)
Follow source-driven-development. For adding rate limiting in this stack, verify the approach against the official docs of the framework and libraries in use, cite the sources, and flag anything you could not confirm.
What happens

The agent checks the framework docs rather than pattern-matching from memory, and cites what it used.

Why it matters

Brownfield stacks pin specific versions. Source-cited decisions keep the agent from reaching for an outdated or wrong pattern.

Checkpoint. The proposed approach is backed by citations you can open.
3

Spec the feature against existing patterns

Prompt (paste into your agent)
Follow spec-driven-development, but scope it to a change inside this existing system. Spec rate limiting for one endpoint: where it hooks in, config, limits, error response, and what must not change.
What happens

The agent writes a focused spec that fits the current architecture instead of a greenfield design.

Why it matters

The spec now describes a change to a living system, including the invariants you must not break. You review the decision before it is built.

Checkpoint. A short spec that names the integration point and the non-goals.
4

Doubt the plan before touching production code

Prompt (paste into your agent)
Apply doubt-driven-development to this plan. In fresh context, extract every non-trivial claim about how the existing code behaves, try to refute each one against the actual source, and reconcile.
What happens

A skeptical pass re-checks the plan’s assumptions about the existing code before any change lands.

Why it matters

In code you did not write, a confident wrong assumption is cheap to catch now and expensive to debug in production later.

Checkpoint. Assumptions about current behavior are confirmed against the source.
5

Pin current behavior, then build in slices

Prompt (paste into your agent)
Follow incremental-implementation and test-driven-development. First add characterization tests that pin the endpoint’s current behavior, then add rate limiting behind a feature flag in thin, committed slices.
What happens

The agent locks in existing behavior with tests, then adds the feature incrementally behind a flag.

Why it matters

Characterization tests make change observable, and the flag makes it reversible. You are changing a system people depend on, so both matter.

Faster path. Too many stops? /build auto implements the remaining tasks in one approved pass, and still pauses on failures and risky steps. In code you did not write, it is worth keeping the manual stepping for the riskiest tasks and letting /build auto sweep the routine ones.
Checkpoint. Old behavior is pinned, new behavior is flagged off by default.
6

When something breaks, find the root cause

Prompt (paste into your agent)
A test broke after the change. Follow debugging-and-error-recovery: reproduce it, localize it, reduce it to the smallest failing case, fix the root cause, and add a guard so it cannot regress.
What happens

The agent runs a systematic triage instead of guessing at fixes.

Why it matters

Brownfield failures hide in the corners. A disciplined reproduce-localize-reduce-fix-guard loop beats trial and error.

Checkpoint. The failure is understood and guarded, not just made to pass.
7

Review as a change to the system

Prompt (paste into your agent)
Follow code-review-and-quality. Keep the change near ~100 lines, check that it fits existing patterns, and run security-and-hardening on the new limits and error paths.
What happens

The agent reviews the diff for correctness and fit, and hardens the new surface.

Why it matters

The bar for brownfield is "does this improve the system and follow its conventions," not "is it how I would have written it from scratch."

Checkpoint. The change is small, fits the codebase, and is hardened.
8

Roll out behind the flag

Prompt (paste into your agent)
Follow shipping-and-launch. Plan a staged rollout using the feature flag, add the monitoring you would want on a rate limiter, and write the rollback. Give me a go or no-go.
What happens

The agent plans a gradual, monitored rollout with a clear rollback and a recommendation.

Why it matters

You flip the flag for a slice of traffic, watch the signals, and can turn it off instantly. That is how you change production without holding your breath.

Checkpoint. A staged rollout plan with monitoring and a one-switch rollback.
What you end up with

A feature merged into a system you did not write, with the existing behavior pinned, the change small and reversible, and a rollout you can watch. The same sequence works for any brownfield feature.

context-engineering The agent stopped guessing your patterns
doubt-driven-development Wrong assumptions caught before prod
incremental-implementation A small, flagged, reversible change
debugging-and-error-recovery Root cause, not a papered-over test
shipping-and-launch A staged rollout you could turn off