How to interpret a confidence interval step-by-step

Most people who work with confidence intervals are using a definition that's subtly wrong — and that wrong definition quietly corrupts every decision they make downstream.
The most common version goes something like: "there's a 95% probability the true value falls between X and Y." It feels right. It's also not what a confidence interval actually says. The 95% is a property of the method that built the interval, not a probability statement about the specific interval in front of you. Getting that distinction right is the foundation everything else in this article builds on.
This guide is for engineers, PMs, and data analysts who work with experiment results and statistical outputs — especially anyone who reads CI numbers off a dashboard and needs to know what to actually do with them. It moves step by step through the mechanics and the meaning, without assuming a statistics background. Here's what you'll learn:
- What a confidence interval actually tells you — and the formal definition most people get wrong
- A three-step template for how to interpret a confidence interval correctly, across any parameter type
- The four most common CI misinterpretations, why each one is wrong, and how to avoid them
- What interval width reveals about your data — including how sample size and variability drive it
- How to use CIs to make ship decisions from A/B test results, including what it means when an interval straddles zero
The article is structured to build in order. The first section clears out the misconception so the rest of the framework sits on solid ground. The middle sections give you the practical tools — the interpretation template, the misinterpretation checklist, the width diagnostics. The final section applies all of it to A/B testing, where these concepts translate directly into product decisions.
What a confidence interval actually tells you (and what it doesn't)
Before you can interpret a confidence interval correctly, you need to clear out the definition most people are working with — because it's wrong, and it corrupts every downstream judgment you make. This isn't a minor technical quibble.
The misunderstanding is so common that statistician Kristoffer Magnusson has called CIs "as unintuitive and as misunderstood as p-values," and the peer-reviewed literature includes papers dedicated entirely to correcting it. If you've been doing this work for years and something about CIs has always felt slightly off, this is probably why.
What the definition actually says (and why most people have it wrong)
A confidence interval is a range computed from sample data using a procedure that, over many repetitions, would capture the true population parameter at the stated confidence level. When you see a 95% CI, that 95% is a property of the method used to construct the interval — not a property of the specific interval sitting in front of you.
The true population parameter — the mean, proportion, or effect size you're trying to estimate — is a fixed value. It doesn't move. It either falls inside your interval or it doesn't. There is no probability to assign to that question once the interval has been computed, because neither the parameter nor the interval is random at that point. The randomness existed in the sampling process, and it's already been resolved.
The frequentist procedure: what "95% confident" actually refers to
The right way to think about a 95% CI is through the lens of repeated sampling. Imagine running the same experiment 100 times, each time drawing a new sample from the same population and computing a new confidence interval. Approximately 95 of those 100 intervals would contain the true parameter. About 5 would not — and you'd have no way of knowing which ones.
As Magnusson puts it: "95% confidence is a confidence that in the long-run 95% of the CIs will include the population mean. It is a confidence in the algorithm and not a statement about a single CI."
This is sometimes called the "dance of CIs" — a framing developed by statistician Geoff Cumming to capture the idea that each interval is one draw from a long-run process. The specific interval you computed in your study is just one step in that dance. It may or may not contain the true value.
The 95% guarantee describes how the process performs across many repetitions — not whether this particular interval succeeded.
The single-interval trap
Here's the interpretation you've almost certainly heard — and probably used yourself: "There is a 95% probability that the true value lies between X and Y."
It's wrong, and understanding why matters. In frequentist statistics, probability statements require a random variable. The true population parameter isn't random — it's fixed, even if unknown. And once you've computed your interval from your data, that interval is also fixed. There's no randomness left to attach a probability to. As Magnusson states plainly: "In frequentist terms the CI either contains the population mean or it does not."
The reason this error is so persistent is that it feels right. You're uncertain about the true value, so it seems natural to express that uncertainty as a probability. But that kind of uncertainty — the uncertainty that comes from not knowing a fixed fact — is handled by a different framework entirely.
Bayesian credible intervals are specifically designed to produce the probability statement most people think they're getting from a frequentist CI. They're a legitimate and useful tool, but they require different assumptions and a different computational approach. A frequentist CI is not a Bayesian credible interval wearing different clothes.
One more implication worth flagging before moving on: interval width doesn't tell you whether your specific interval captured the true value. Even a very narrow CI can miss the true parameter entirely.
Width reflects the precision of your estimation procedure — how tightly your method can constrain the estimate given your sample — but it says nothing about whether this particular interval is one of the 95% that succeeded or one of the 5% that didn't. That distinction will matter when you get to interpreting width as a diagnostic signal.
Three steps that prevent the most common confidence interval errors
Most interpretation errors happen not because someone misunderstands statistics, but because they skip a step. They see two numbers and a percent sign and jump straight to a conclusion.
The three-step template below slows that process down in a useful way: identify what's being estimated, state the confidence level explicitly, then read the bounds as a plausible range. Each step does real work, and skipping any one of them opens the door to the misinterpretations covered later in this article.
Name the parameter before you read a single number
Before you read a single number, establish what the confidence interval is actually bounding. Is it a population mean? A proportion? A difference in means between two groups? A relative lift from a treatment? The answer changes how you phrase the interpretation and what the bounds actually mean in context.
This step is less obvious than it sounds. In A/B testing, for example, a platform like GrowthBook produces CIs on both absolute effects — the raw difference in means between control and treatment — and relative effects, which express that difference as a percentage lift.
Both are confidence intervals, but they're bounding different parameters. Treating a CI on relative lift as if it were a CI on an absolute difference will produce a meaningfully wrong interpretation. Identifying the parameter first prevents that error.
The confidence level is load-bearing, not a formality
The confidence level belongs in every interpretation statement, not as a formality but because it's load-bearing information. A 90% CI and a 99% CI on the same data produce different bounds, and a reader who doesn't know which procedure generated the interval can't evaluate what the bounds mean.
The standard phrasing template is: "We are [X]% confident that the [parameter] is between [lower bound] and [upper bound]." That phrasing is worth using almost verbatim, because it encodes the correct frequentist framing — it's a statement about the procedure's reliability, not a probability claim about this specific interval. The distinction matters and is addressed in detail in the next section of this article.
Bounds define plausibility, not certainty
The lower and upper bounds define the range of parameter values that are consistent with your observed data at the stated confidence level. Values inside the range are plausible given what you observed; values outside are less consistent with the data, though not ruled out entirely.
The classic worked example from Penn State's STAT 200 course puts this concretely: "We are 95% confident that the mean IQ score in the population of all students at this school is between 96.656 and 106.422." That sentence does all three steps in one pass — it names the parameter (mean IQ score of all students at the school), states the confidence level (95%), and reads the bounds as a plausible range (96.656 to 106.422). The precision of those bounds reflects the underlying data; they come from a point estimate plus and minus a margin of error derived from the standard error of the sample.
The same three steps work across every parameter type
The same three-step structure transfers directly to any parameter type. For a proportion, the interpretation might read: "We are 95% confident that the true conversion rate is between 3.2% and 4.8%." A treatment effect follows the same pattern: "We are 95% confident that the treatment increased revenue per user by between $0.12 and $0.87." The structure is identical — parameter, confidence level, plausible range — even though the underlying variance formulas differ substantially between a binomial proportion and a mean metric.
That last point matters for practitioners using experimentation platforms. Some experimentation platforms handle mean metrics, proportion metrics, ratio metrics, and quantile metrics with distinct variance estimation approaches, which means the bounds you're reading were computed differently depending on the metric type.
The interpretation template doesn't change, but the "identify the parameter" step should include knowing what kind of metric generated the interval — because that affects how much weight to put on the precision of those bounds.
One scoping note: this template applies to frequentist confidence intervals. A Bayesian experimentation engine produces credible intervals, which carry a subtly different interpretation. The three-step structure is a reasonable starting point for credible intervals too, but the confidence level statement means something different in that framework.
The most common confidence interval misinterpretations to avoid
These aren't beginner mistakes. A 2014 study by Hoekstra, Morey, Rouder, and Wagenmakers, published in Psychonomic Bulletin & Review, found that individuals across all levels of statistical expertise — from students to seasoned researchers — routinely endorsed false statements about confidence intervals.
Morey et al. followed up in 2015 defending and reinforcing those findings against academic criticism, making the point even harder to dismiss: CI misinterpretation is a documented, peer-reviewed problem, not an anecdote about people who skipped their stats class.
Understanding where the errors cluster, and why each one is wrong, gives you a practical filter you can apply when reading a paper, reviewing a dashboard, or explaining results to a stakeholder.
"There's a 95% probability the true value falls in this interval"
This is the most pervasive misconception, and it's intuitive enough that even careful researchers fall into it. The error is treating a realized interval as if it carries a probability. It doesn't. Once you've computed a confidence interval from a specific sample, that interval is fixed — it's a pair of numbers. The true population parameter is also fixed, even if unknown. Either the interval covers it or it doesn't. There's no probability left to assign.
As established in the opening section, the 95% is a property of the sampling procedure — not a probability statement about the interval you're currently looking at. A useful analogy: imagine a machine that produces balls, 95% of which are black across many production runs.
Once a ball has been produced and is sitting in front of you, asking "what's the probability this ball is black?" doesn't quite make sense in the frequentist frame — it either is or it isn't. The same logic applies to a realized confidence interval. The probability statement belongs to the sampling procedure, not to the specific interval it generated.
"The mean will fall within the interval 95% of the time"
This is a close cousin of the first misconception but distinct enough to address separately. It conflates the long-run frequency property of the CI procedure with a claim about a single interval's reliability over time. The correct statement is that 95 out of 100 intervals constructed from repeated independent samples would contain the true population mean.
The mean isn't bouncing around relative to one fixed interval — the intervals themselves vary from sample to sample, and 95% of them, across that process, would capture the parameter. Any single interval you've computed doesn't have a 95% "hit rate" on its own; it either contains the true mean or it doesn't.
"Values outside the CI are impossible or ruled out"
The bounds of a confidence interval are not hard cutoffs. A value sitting just outside the interval is nearly as consistent with the data as a value sitting just inside it. The CI represents a range of parameter values that are plausible given the observed data and the chosen confidence level — it's a gradient of support, not a fence.
Treating the boundary as a definitive exclusion zone leads to overconfident conclusions, particularly when the interval is wide or the sample size is small. The correct framing is that values outside the CI are less supported by the current data, not that they've been ruled out.
"A 95% CI means 95% of my data points fall within that range"
This confusion mixes up two fundamentally different statistical objects: a confidence interval and a data distribution (or prediction interval). A confidence interval is a statement about a population parameter estimate — the mean, a proportion, a regression coefficient. It narrows as sample size increases, because more data produces a more precise estimate.
A range that captures 95% of individual observations behaves entirely differently and doesn't shrink the same way as you collect more data. If you're seeing a CI reported on a dashboard and interpreting it as a description of where most of your users or data points land, you're reading the wrong quantity for that question.
Misreading any of these can have real consequences in practice. In an experimentation context, incorrectly treating a CI as a probability statement about a single result can lead to overconfident ship decisions or misplaced certainty about effect sizes — exactly the kind of inference error that rigorous experiment analysis is designed to prevent.
What the width of a confidence interval reveals about your data
Most practitioners read a confidence interval by checking whether it includes or excludes a null value — does the interval cross zero, or doesn't it? That's a reasonable starting point, but it only uses half the information the interval contains.
The distance between the lower and upper bounds is a diagnostic signal in its own right. It tells you how precise your estimate is, and it reflects two measurable properties of your data: how many observations you collected and how variable the underlying metric is.
How sample size shrinks (or widens) a confidence interval
The mechanics here follow directly from the standard error formula for a mean: SE = s / √n. Because sample size appears under a square root, the relationship between n and interval width is nonlinear in a way that matters enormously for study design.
Consider a concrete example. Suppose you're measuring weekly screen time across a student population, with a sample mean of 23.4 hours and a standard deviation of 5.1 hours. At n = 100, a 95% CI has a margin of error of roughly 1.02 hours, producing an interval of (22.38, 24.42) — a width of about 2 hours.
Drop the sample size to n = 25, keeping everything else identical, and the margin of error nearly doubles to 2.11 hours, giving an interval of (21.29, 25.51). The same data-generating process, the same confidence level, and the same underlying variability — but the interval is now twice as wide simply because you collected fewer observations.
The practical implication of the square-root relationship is worth stating explicitly: to cut your margin of error in half, you need to quadruple your sample size. This is the most actionable lever practitioners control at the design stage, and understanding it prevents the common mistake of expecting linear returns from incremental sample increases.
How data variability affects interval width
Sample size is a lever you can pull. Population variance often isn't. When the underlying metric is inherently noisy — revenue per user, for instance, rather than a binary conversion event — the standard deviation in the SE formula is large, and the resulting interval will be wide regardless of how many observations you collect.
This distinction matters for interpretation. A wide CI on a high-variance metric is not a study failure. It's an honest reflection of the data. The interval is telling you that the true parameter could plausibly sit across a broad range, and that's a real property of the measurement, not an artifact of poor methodology.
Conflating wide intervals with bad data leads analysts to dismiss valid results or, worse, to keep collecting data past the point where more observations can meaningfully narrow the interval.
The two drivers — sample size and variability — are independent. A study with a large sample and a high-variance metric can still produce a wide interval. A study with a small sample and a low-variance metric may produce a surprisingly tight one. Reading width correctly means asking which of these two forces is at work.
A wide CI straddling zero is a power problem, not a null result
Width becomes especially diagnostic when an interval straddles zero or a null value. The tempting interpretation is that no effect exists. But a wide interval straddling zero carries a different meaning: both a meaningful positive effect and a meaningful negative effect are statistically plausible. The study can't distinguish signal from noise — not because there's no signal, but because the estimate isn't precise enough to find it.
This is the retrospective version of statistical power. If the interval is so wide that it encompasses effect sizes ranging from "worth shipping" to "actively harmful," the experiment was likely underpowered. The CI width is telling you that the study needed more data, not that the intervention had no impact.
This is also where variance reduction techniques become relevant. GrowthBook implements CUPED (Controlled-experiment Using Pre-Experiment Data), which reduces the variance of treatment effect estimates by accounting for pre-experiment covariates. Lower variance means a smaller standard error, which means narrower confidence intervals — and narrower intervals mean more precise estimates from the same number of observations. It's a direct application of the variability-width relationship described above.
When you look at a CI, the width deserves as much attention as the position. A narrow interval centered on a small effect is telling you something different from a wide interval centered on the same point estimate. The first is precise; the second is uncertain. Treating them identically discards information you already have.
What a confidence interval's position and width tell you about an A/B test
A confidence interval on an A/B test result isn't decoration — it's the primary instrument for making a defensible ship decision. The p-value tells you whether to take a result seriously; the CI tells you what the result actually means in magnitude and direction.
Once you understand how to read the interval's position relative to zero and what its width signals about your experiment's precision, you have everything you need to move from statistical output to product decision.
How CIs are computed on treatment effects
In an A/B test, the CI isn't built around either group's mean in isolation. It's built around the difference between treatment and control — the estimated treatment effect. The standard frequentist formula is: CI = point estimate ± (critical value is approximately 1.96 under a normal distribution × standard error). At a 95% confidence level, the critical value is approximately 1.96 under a normal distribution. The point estimate sits at the center; the bounds define the range of plausible effect sizes consistent with your data.
One important nuance worth flagging: platforms like GrowthBook default to Bayesian statistics, which produces a credible interval rather than a frequentist confidence interval — typically flagging results as significant when there is a 95% probability the variation outperforms baseline. The interpretation is subtly different from a frequentist CI, but in practice both types of intervals are used similarly when making ship/no-ship calls.
When the CI sits entirely above zero
This is the win scenario. Both the lower and upper bounds of the interval are positive, meaning every plausible effect size consistent with your data points in the same direction: the treatment helped. The lower bound is particularly useful here — it represents the most conservative estimate of the effect at your chosen confidence level, which is the number to use when forecasting minimum business impact.
That said, a CI entirely above zero still carries a 5% false positive rate at the 95% confidence level. GrowthBook's documentation states this directly: a statistically significant positive result means the variation is actually better than baseline 95% of the time — which means 5% of the time, it isn't.
Factor that into how aggressively you act on borderline wins. A narrow CI above zero gives you more precise effect size estimates; a wide one above zero still supports shipping, but with less certainty about the magnitude.
When the CI straddles zero
A CI that crosses zero is the inconclusive outcome, and it's the one most commonly misread. It does not mean there's no effect. It means your experiment didn't collect enough evidence to distinguish a real effect from noise. Both a meaningful positive effect and a meaningful negative effect remain statistically plausible given the data you have.
A wide CI straddling zero is the power problem described in the previous section — both a meaningful positive and a meaningful negative effect remain plausible. The appropriate response is not to call it a null result.
Consider running longer, increasing sample size, or applying variance reduction techniques like CUPED, which narrows CIs by reducing noise in the outcome metric. If the true effect size is smaller than the experiment's Minimal Detectable Effect, the test may never reach significance even if a real effect exists — and that's a design problem to solve before the next experiment, not a verdict on the current one.
When the CI sits entirely below zero
Both bounds negative means the treatment performed worse than control across the full range of plausible effects. This is the loss scenario, and it's more common than most teams expect — a meaningful share of A/B tests result in the treatment actively hurting the metrics being measured. A CI entirely below zero is the statistical signal that catches these cases before they reach production.
It's worth reframing what this outcome means for the team running the experiment. As GrowthBook's documentation puts it, "failing fast through experimentation is success in terms of loss avoidance, as you are not shipping products that are hurting your metrics of interest."
A narrow CI entirely below zero is actually a high-quality result — it gives you a precise estimate of how much harm the treatment causes, which can inform whether a modified version is worth testing or whether the hypothesis should be abandoned entirely.
The one distinction that makes every other CI judgment easier
Every practical skill covered in this article — reading bounds as plausible ranges, diagnosing width as a power signal, using CI position to make ship decisions — depends on one foundational distinction: the 95% belongs to the procedure, not to the interval.
Once that distinction is genuinely internalized, the rest of the framework follows naturally. The misinterpretations stop feeling like arbitrary rules to memorize and start feeling like obvious errors. The width diagnostics stop feeling like secondary concerns and start feeling like essential information. The A/B test decision framework stops feeling like a checklist and starts feeling like a coherent way of reading evidence.
Three questions that do most of the interpretive work
When you encounter a confidence interval in the wild — on a dashboard, in a paper, in a stakeholder presentation — three questions do most of the interpretive work:
- What parameter is this bounding, and is that the parameter I actually care about?
- What confidence level generated it, and what does that imply about the false positive rate?
- What does the width tell me about the precision of this estimate and the power of the underlying study?
The first question prevents the parameter confusion described in the three-step section. The second question keeps the confidence level load-bearing rather than decorative. The third question extracts the diagnostic signal that most practitioners leave on the table. Running through all three takes about ten seconds and catches the majority of interpretation errors before they propagate into decisions.
Translating CI results for stakeholders without losing precision
The standard frequentist phrasing — "we are 95% confident that the true value lies between X and Y" — is technically correct but often lands poorly with non-technical stakeholders. The word "confident" sounds like a probability claim, which is exactly the misinterpretation this article has been working to prevent.
One approach that preserves precision while improving accessibility: lead with the point estimate and use the interval to communicate uncertainty. "Our best estimate is that the treatment increased conversion by 2.1 percentage points. The data are consistent with effects ranging from 0.8 to 3.4 points." That framing conveys the same information without triggering the probability misread.
If your team runs on a Bayesian experimentation engine, the credible interval it produces actually does support a more direct probability framing — something like "there's a 95% probability the treatment outperforms control given the data we observed." That statement is technically valid in the Bayesian framework and is often easier for stakeholders to act on. The key is knowing which framework generated the interval before choosing how to describe it.
From knowing the definition to defaulting to the right frame
Statistical fluency around confidence intervals isn't primarily about memorizing the correct definition — it's about defaulting to the right frame automatically, under time pressure, when a result is sitting in front of you and a decision needs to be made.
The right frame is: this interval was produced by a procedure that works 95% of the time. This specific interval either contains the true value or it doesn't. The width tells me how precise the estimate is. The position tells me what direction the evidence points. Those four pieces of information are everything the interval actually contains.
What to do next: Pull up the most recent A/B test result your team has run. Identify the parameter being estimated. Check whether the CI is frequentist or Bayesian. Read the width as a power diagnostic — is it narrow enough to distinguish meaningful effects from noise? Read the position relative to zero — does it sit entirely above, straddle, or sit entirely below? Then write out the interpretation using the template from this article.
If the phrasing feels unfamiliar, that's the signal that the old frame is still running in the background. The goal is to make the correct frame the default — and the only way to get there is to practice applying it to real results until it stops requiring conscious effort.
Related insights
Related Articles
A magazine's home page shows two recent issues. The design team wants subscribers to try a shelf with four. All four covers are public, and changing editions while the page is open should update the shelf immediately. That gives you a small React feature with a useful acceptance test. Click from guest to subscriber and back, and count the covers each time.
We'll put the display limit in a typed local flag, evaluate it inside a React component, and leave the choice of edition with the app. The example runs in a client-rendered React app without a GrowthBook account, an SDK key, or a request for flag rules. For the wider workflow, free feature flags for coding agents explains what to ask an agent to implement and how to review the result.
Define what one flag controls
Start with an existing React and TypeScript app, or create a Vite React project for the example. Install both GrowthBook packages so the definitions and the hooks resolve against compatible SDK versions.
Create src/flags.ts. Here the feature value is a number, which lets the component use the same rendering code for either edition. A future change from four covers to three is one edit to the rule.
A guest falls through to the default of two. A subscriber matches the rule and gets four. This rule applies to every subscriber, so the ID has no effect on the result here. If you later roll the shelf out to a percentage of subscribers, you already have an identity to use for repeatable assignment.
The type registration release note explains the version requirement for LocalFeatures. The registration connects the definition, the attributes, and the value returned by the hook. For the TypeScript mechanics, see Jeremy Dorn's Register pattern walkthrough.
Put the current reader above the shelf
Replace src/App.tsx with the component below. The edition switch is a local fixture so anyone reviewing the change can reproduce both states. In an existing app, take those two values from the active reader in your session layer.
The provider receives an instance initialized with the current reader and the checked-in rules. React can render the correct shelf on the first pass for that reader. If the app is still loading a session, decide what should occupy the shelf in the meantime. For this public list a two-cover guest view is reasonable. On a page where a switch would interrupt the reader, wait for the session before mounting the shelf.
Give your agent the React setup
Use the local flags guide to ask for a typed definition, a provider with the current reader, and a test that changes the edition.
Open the Agent GuideThe useMemo dependencies include the ID and the edition. If a reader subscribes while signed in, their ID can stay the same while their edition changes. Depending only on the ID would leave the old SDK instance in place. Passing a fresh object as the dependency on every render would create unnecessary instances. The example uses the two primitive values the rule setup actually needs.
Read the numeric flag where React renders the list
Create src/IssueShelf.tsx. Keep one stable ID per issue and let the component use the resolved value to select how many items to render.
Keep the hook at the top of the component, inside the provider's subtree. The React SDK supplies the flag value through that provider. Calling a hook inside a click handler or inside the list loop would break the Rules of Hooks. Use the returned number in ordinary render logic.
There are two places you can see the number two in this implementation. The definition's defaultValue is what an ordinary guest gets through evaluation. The 2 passed to the hook is a fallback for a value the SDK can't supply. Giving them the same value makes the basic shelf a sensible fallback, but checking only the guest case would let a broken provider arrangement or missing definition go unnoticed. The subscriber case proves that the component actually received the rule.
The list keys identify magazine issues. Keep those keys independent of the flag. Switching from two covers to four should preserve the identity of the first two rows. There's also no need to remount the whole app with an edition-specific key. React preserves state according to component position and keys. For example, a search input outside the shelf shouldn't lose its text because someone subscribed.
Check the transition in both directions
Use the template's build script to type-check and bundle the app. Once that passes, start the dev server and open the local address it prints.
On first load, the page says guest and lists November and October. Click Switch edition. The same page should say subscriber and add September and August. Click again. The list should return to the original two issues, in order. This last check catches code that appends more results on upgrade and never removes them on downgrade.
For a compile-time check, temporarily replace the numeric fallback with the string "2". Run the build again and inspect the error on the hook call. Then restore 2 and rebuild. If the string compiles, check that src/flags.ts belongs to the same TypeScript project as the component and that the package manager resolved compatible core and React versions.
Look for the core package used by your app and by the wrapper. If the app has several incompatible installations, align the versions before diagnosing the JSX. A team using an existing build script should also confirm it actually runs the TypeScript checker.
Hand off a React change someone can review
Give your coding agent the one-shot local feature flags guide and a short description of the observable behavior. For this shelf, the request can be as specific as the test.
The shelf controls how many public titles to display. If your actual feature unlocks paid articles, enforce access when the server serves an article. A client-rendered flag only decides what to show in that browser. Whenever a change to the display limit can wait for a deployment, the small local file keeps the decision reviewable alongside the component. When an editor needs to change it between issues without an engineering release, that's the point to consider managed rules.
Manage the shelf in GrowthBook
Start a GrowthBook workspace when your magazine team is ready to manage shelf rules between deployments.
Get Started with GrowthBookTwo customers download the same weekly report. One has agreed to preview a new CSV column. The other feeds the old two-column format into an importer. Both requests can land on the same Node.js process, and each needs the right file even if the other request arrives while the report is loading.
This tutorial builds that endpoint with one checked-in feature flag. The process loads the rules once. Each request supplies its own workspace attributes and receives its own evaluation. You can run the whole example on your machine without an account, a client key, or a flag server. The free feature flags for coding agents walkthrough introduces the local approach. Here we'll give the agent a server-specific test to pass.
Set up a small TypeScript service
Use Node.js 22 or newer for this example. In an empty directory, create an npm project that uses ES modules, install the core SDK, and add the TypeScript tools.
Create tsconfig.json at the project root. The sample runs TypeScript directly with tsx and checks types in a separate step. Type checking with tsx explains why the two commands serve different purposes.
The following files all live next to that configuration. The server imports ./flags.js even though the source file is flags.ts. That spelling follows TypeScript's Node.js module resolution for ESM and works with this runner.
Define the report contract in one flag
Create flags.ts. The public format has two columns. The sample preview workspace gets one additional column. The only targeting attribute the rule needs today is reportPreview. Carry the workspace ID too, so two people downloading a report on behalf of the same workspace can share an assignment if you introduce a percentage rollout later.
The SDK type registration update covers this rule syntax and the 2.2.0 minimum. If you misspell reportPreview in a condition or use a string where the boolean flag expects a value, TypeScript can point at the definition. The Register pattern also makes the same feature name available in other modules without threading a generic type through each handler.
Before you add the endpoint, decide what belongs to the process and what belongs to the request. The feature definitions are identical for both customers. Their identity and preview enrollment can differ. If a handler changes an attribute on a single shared user instance before awaiting a database query, another handler could replace that attribute before the first handler resumes.
Give your agent a server-side task
Use the one-shot guide to add checked-in rules. Ask your agent to keep workspace attributes local to each request and demonstrate both CSV formats.
Open the Local Flags GuideCreate a scope when the request arrives
Create server.ts. The Node.js SDK provides GrowthBookClient for the process and createScopedInstance for the current request. The two fixture paths below stand in for two authenticated workspaces. The server binds to the loopback address so you can exercise it locally.
The HTTP handler looks up a workspace, creates its scope, and holds that scope across an asynchronous operation. The short promise-based timer gives a second request time to arrive. In a real export, that's where the database or storage read would happen. Keep the stable client at module scope and the scoped instance inside the handler. If a formatter needs the decision, pass it the boolean or the scoped instance.
In production, resolve the workspace and its access rights from the authenticated session before reading the report. The two selectable paths here are fixtures for public sample data. A caller's choice of a header, query string, or workspace slug can't establish permission to read another customer's report. The endpoint also prevents shared response caching. If you cache real exports, the cache needs to distinguish the workspace and the report format, along with any other inputs that change the response.
Test two requests that overlap
In the first terminal, type-check the service and start it. A successful type check exits quietly. The next command prints the loopback address and keeps the server running.
Save the following as verify.mjs. In a second terminal, run node verify.mjs. Node's built-in fetch calls the local server. Strict assertions compare the full header and data row, including where each row ends.
You should see the single success line. Testing just the preview workspace proves that the code can add a column. Testing both responses catches the more expensive mistake of silently changing an existing customer's export. Keeping the old format assertion around is especially valuable when the downstream importer belongs to someone outside your team.
To check the compile-time boundary, temporarily change gb.isOn("includeUniqueReaders") to gb.isOn("includeUniqueReader") and rerun npx tsc --noEmit. The diagnostic should identify the misspelled key. Restore it before running the server again. A coding agent can include the before-and-after type check and the two CSV headers in its pull request.
Decide when to expand the report
When one preview customer is ready, leave everyone else on the default. If the next step is to enroll a fraction of workspaces, choose an attribute that matches the promise you're making. Hashing a workspace ID lets colleagues downloading the same report share a format. Hashing each user's ID could give two analysts in the same company different column sets. The one-shot guide shows how to express a percentage and hash attribute in a local rule.
A new rule in flags.ts reaches a process through your deployment. During a rolling deploy, the same workspace might hit old and new processes. If customers need a durable choice of export schema, keep supporting the agreed format in the API itself. When the operational requirement is to change targeting between deploys, you can keep the scoped evaluation in the handler and change how the process receives its rules.
Manage report targeting in Cloud
Create a GrowthBook workspace when the team supporting exports needs to expand the preview independently of a server release.
Get Started with GrowthBookYour conference agenda has a new “Show room” button. Reviewers should see it on the first page load. Everyone else should get the existing agenda. If a Server Component renders the old agenda and a browser hook independently decides to show the new button, the first HTML and the browser can disagree.
In the Next.js App Router, the server can make this decision once and pass a boolean to the interactive component. We'll define the flag in the repo, select the preview audience with a local test cookie, and verify the actual HTML for both visitors. Clicking the button will still work after hydration. You can follow along without a GrowthBook account or client key. If you're assigning this work to an agent, the free feature flags for coding agents walkthrough gives the background.
Keep the flag definitions on the server
Use a TypeScript App Router project, or create a small one with create-next-app. These paths assume the project has an app directory at its root. If yours uses src/app, put both app and lib under src so the relative imports still match.
Keep the starter's root layout. Create lib/agenda-flags.ts with the following code. The SDK type registration update explains how LocalFeatures checks the flag and its rule against the registered types. This setup requires version 2.2.0 or later.
The module can reuse the client and rules across requests handled by the same process. It only holds the current visitor's audience inside the function call. Two requests can therefore use the same flag file and get different results. The Node.js SDK documents the scoped client used under the App Router here.
This particular rule has no percentage and needs no visitor ID. The two audiences are sufficient. If the team later asks for a rollout to 10% of attendees, add a stable attendee or registration ID and choose which of those units should stay together. Jeremy Dorn's Register pattern article explains how a change to an attribute type reaches the call sites that construct it.
Read the cookie for this request
Create app/agenda/page.tsx. The static heading can render for everyone. The request-specific content sits behind a Suspense boundary, so the fallback can show a neutral loading message until the server has the cookie.
The App Router's cookies function reads the incoming request asynchronously. Read it inside the visitor-specific component. Keeping that read out of shared cached code lets the surrounding page reuse common content without treating one visitor's decision as another's. This placement also accommodates App Router projects using Cache Components.
Give your agent the Next.js setup
Use the local flags guide with a concrete request to evaluate one flag on the server and return the same decision to the browser.
Open the Local Flags GuideThe cookie in this demo is a convenient way to preview a public UI treatment. Anyone with that cookie can see the room label. To target paying attendees or private sessions, obtain the audience from the verified session on the server and authorize the underlying data separately.
Pass one decision to the interactive component
Create app/agenda/Agenda.tsx. It's a Client Component because a visitor can open and close the room details. Its initial branch comes directly from the boolean supplied by the page.
The client boundary takes a serializable prop. The component receives true or false. The SDK instance, targeting rules, and cookie handling stay in the server module. You don't need a React provider for this component because its only browser-side choice is whether the visitor has clicked the button.
Follow one page load through server rendering and hydration. For a preview visitor, the server can send a section with a “Show room” button. React's first client render gets the same showRoom value and starts with open set to false. Hydration attaches the click handler. Opening the room detail then updates component state and doesn't require another flag evaluation.
Verify the HTML and the click separately
Build the production app and start it on port 3100.
In a second terminal, save this as verify-agenda.mjs in the project root and run node verify-agenda.mjs. The test makes two requests to the same route and looks for a marker on the rendered section. A marker in the HTML helps catch an implementation that only adds the intended layout after JavaScript runs.
Now open http://localhost:3100/agenda in a fresh browser profile. You should see the session title without a room button. In that local page's browser console, set the demo cookie and reload.
Click Show room and look for Room 204. Click Hide room and the room should disappear. This second check proves the component became interactive. If the server response test passes but the click fails, inspect the browser console for a hydration error before changing the flag rules.
Remove the fixture and reload once more. The button should disappear and the agenda title should remain.
The reload is deliberate. Editing the cookie in an already open document doesn't rerun its Server Component. In your app, use the normal session-change flow to request a fresh server render when a visitor signs in, signs out, or leaves a preview group.
Choose where the next flag should be evaluated
For a decision needed in the initial HTML, give the agent an observable requirement. Ask it to show the two HTTP responses, then click the interactive control in the preview. The first check catches an incorrect layout. The second catches correct HTML that never becomes interactive.
If a later feature depends on an action entirely within the browser, evaluate whether its flag belongs in the client tree. The one-shot local flags guide covers both placements. This agenda only needs one server decision. Updating its checked-in rule takes a deployment. Keep that tradeoff in view if the event organizer needs to pause a preview while attendees are already arriving.
Manage the agenda rollout in Cloud
Create a GrowthBook workspace when the organizer needs to adjust a preview audience while your Next.js app is serving attendees.
Get Started with GrowthBookReady to ship faster?
No credit card required. Start with feature flags, experimentation, and product analytics—free.



