---
name: gates
description: Ship a feature behind a Gates feature flag in an Expo / React Native app, roll it out gradually, or kill it. Use when the person mentions Gates, usegates.app, @withgates/expo, feature flags, kill switches, staged rollouts or "ship my first flag" in an Expo project.
---

# Gates: ship a feature behind a flag

Gates evaluates flags on the device from the last snapshot it saved. A flag
read never waits on the network, so the app renders at once and keeps working
offline. You work through the `gates` CLI (`npx @withgates/cli`) or, when it
is configured, the `gates` MCP server; both act on the person's account.

## Before anything

Run `npx @withgates/cli whoami`. If it fails, tell the person to run
`npx @withgates/cli login` in their terminal and stop until they have.
Never ask for, type or store a Gates password. The CLI signs in with a
code the person approves in their browser.

## The procedure

1. **Find the project.** `gates projects` lists what the account can see.
   In the app directory, `gates link <projectId>` records it in
   `.gates.json` (safe to commit). Every later command reads that file;
   pass `--project <id>` to override it.
2. **Install the SDK** in the Expo app's directory:
   `npx expo install @withgates/expo expo-application expo-updates @react-native-async-storage/async-storage`.
   Use the package manager the lockfile implies for anything else.
3. **Wire the provider.** `gates env keys` prints the public `ek_…` key per
   environment; `gates init --env development` prints the provider snippet
   with the right key filled in. Wrap the root component in
   `<GatesProvider projectKey environment user>`. Pass `user={{ id }}` when
   the app has sign-in and `null` when signed out. Build with the
   development key; production builds use the production key. The key is
   public and read-only, so it may live in source; it is not a secret.
4. **Create the flag.** `gates flags create <key> --name "<Name>"`. Keys
   are lowercase with dashes, like `new-checkout`. A new flag is off
   everywhere until it has a rollout.
5. **Read it in code.** `useFlag("<key>")` returns a boolean and never
   throws. `<Flag name="<key>">…</Flag>` renders children only when on and
   fails closed; `<Switch>` fails open. Put the new code behind `true`
   and leave the current code as the `false` branch.
6. **Verify.** Run the app once, then `gates flags --env development`
   shows the flag; the dashboard's Installations page shows the device after
   its first sync.
7. **Roll out.** `gates flags rollout <key> --env production --percent 10`
   serves the feature to that share of devices, deterministically per
   device. Raise the number over time. The same devices stay in.

## Rules that must hold

- Evaluation never waits on the network. Do not `await` anything from
  Gates before rendering; do not block on `ready`.
- A kill switch is `gates flags kill <key>`: off wins over every rule in
  every environment on the next sync. Do not delete the flag to turn a
  feature off; deleting loses its history and its rollout seed.
- Flags are booleans. There is no variant, string or number flag; model a
  choice as a flag per option.
- Do not create flags the person did not ask for, and do not change rules
  in `production` without saying so first.
- Targeting attributes the SDK reports: platform, appVersion, buildVersion,
  runtimeVersion, updateId, plus `user.*` traits passed through `identify`.
  OTA channel and branch are reported, not targetable.

## When a command fails

The CLI prints the API's own message and a hint. `Not signed in` means
step 0. `No project linked` means `gates link`. A 409 on create means the
key exists; reuse it rather than inventing a variant. Anything else, show
the person the output verbatim.

Docs: https://usegates.app/docs. CLI reference: https://usegates.app/docs/cli.
