<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# Getting started

> Set up KeepSnappy on an iOS simulator in GitHub Actions and get your first result on a pull request.

This page takes your app from no KeepSnappy to a [result](https://keepsnappy.com/docs/glossary.md#result) on a pull request. The walkthrough uses an iOS simulator in GitHub Actions. You run one command and change no app code. Your own part takes about 30 minutes. Then CI measures your `main` branch 3 times, so that KeepSnappy has something to compare your pull requests with.

<span id="android-emulator"></span>For Android, a phone on a cable or real phones on BrowserStack, see [Choose your setup](https://keepsnappy.com/docs/index.md#choose-your-setup). Prefer to have Claude Code or Codex do these steps? See [Set up with a coding agent](https://keepsnappy.com/docs/coding-agent.md).

## What you need

- A KeepSnappy account. KeepSnappy opens to everyone on 15 December. Until then, ask an owner of your team to add you, or write to <support@keepsnappy.com> ([Get access](https://keepsnappy.com/docs/access.md)).
- A [CI key](https://keepsnappy.com/docs/glossary.md#ci-key), so that your CI can upload measurements to KeepSnappy. Only an owner or admin of your organization can make one. If you aren't one, ask one to make it for you.
- An Expo app, or a bare React Native app with the `expo` package and Expo modules. If a bare app has none, add them with `npx install-expo-modules@latest`, Expo's own tool, then follow [Bare React Native](https://keepsnappy.com/docs/bare-react-native.md).
- End-to-end tests in [Maestro](https://keepsnappy.com/docs/test-tools/maestro.md), [Appium](https://keepsnappy.com/docs/test-tools/appium.md) or [e2e](https://keepsnappy.com/docs/test-tools/e2e.md) that already pass on an iOS simulator or an Android emulator in GitHub Actions. KeepSnappy measures your app while these tests run. If init cannot use your emulator job, follow the [manual Android setup](https://keepsnappy.com/docs/android.md#android-emulator).
- Node.js 22.12 or newer. The `keepsnappy` command runs on it.
- The GitHub CLI, `gh`, signed in with the right to add repository secrets. Init uses it to store your CI key in GitHub. Without it, init tells you how to add the key by hand.

## 1. Set up your app

This step adds the SDK that measures your app, and a CI workflow that runs your tests with it.

Use the CI key you copied when you created your workspace. If your app has no CI key yet, an owner or admin can open **Setup** on the [dashboard](https://keepsnappy.com) and choose **Make a CI key**.

If your app’s measurement build needs an SDK key, open **Setup**, then **Set up your app** and **Builds that send their own measurements**. An owner or admin can choose **Make an SDK key** there. To replace a key, choose **Make a new SDK key** and confirm. The previous SDK key keeps working for 7 days while you update the measurement build.

<!-- key-usage:start -->
The CI key starts runs and reads results. It also uploads measurements. Store it as the `KEEPSNAPPY_KEY` secret in CI. It is shown once and must stay private.
<!-- key-usage:end -->

In your app's repository, start from a clean working tree, so that you can commit exactly what init changes. Use your app's package manager and the Node.js version it requires.

| Package manager | Preview the changes | Apply the changes |
|---|---|---|
| npm | `npx @keepsnappy/agent init --detect` | `npx @keepsnappy/agent init` |
| pnpm | `pnpm dlx @keepsnappy/agent init --detect` | `pnpm dlx @keepsnappy/agent init` |
| Yarn 2 or newer | `yarn dlx @keepsnappy/agent init --detect` | `yarn dlx @keepsnappy/agent init` |

With `--detect`, init changes nothing and asks nothing. It names what it found, such as your [test tool](https://keepsnappy.com/docs/glossary.md#test-tool) and the workflow that runs your tests, and shows each change it would make as a diff.

If you use Yarn 1, or npm refuses to start with a package-manager error such as `EBADDEVENGINES`, run `npx` from outside the repository. Pass the absolute path to the app with `--dir`. Init still uses the app's package manager when it installs dependencies.

```sh
npx @keepsnappy/agent init --detect --dir "/absolute/path/to/your-app"
```

When the preview looks right, run the apply command. If you used `--dir`, keep it and remove `--detect`. Init asks up to three questions:

1. Whether to add a nightly run at 02:17 UTC. Say yes. It keeps `main` measured on days nobody merges, so pull requests are compared with recent measurements. It uses GitHub runner minutes each night.
2. Whether to apply the changes it shows. Say yes.
3. Whether to store a key as the GitHub secret `KEEPSNAPPY_KEY`. Say yes, and paste your CI key. Init checks the key, stores it with `gh` and never writes it to a file.

If init runs without a terminal, such as in a script or a coding agent, it can't ask. Run it with `--yes` and `--nightly`, then store the key on its own ([how](https://keepsnappy.com/docs/troubleshooting.md#if-init-stops-or-leaves-something-to-you)).

Init changes these files and nothing else:

- `package.json` and your lock file: the SDK, `@keepsnappy/react-native`, and [the `keepsnappy` command](https://keepsnappy.com/docs/glossary.md#the-keepsnappy-command), `@keepsnappy/agent`, at [versions that work together](https://keepsnappy.com/docs/install.md#versions-that-work-together).
- `app.json`: the SDK's plugin.
- `metro.config.js`: a wrapper around your Metro config, or a new file.
- `keepsnappy.yml`: KeepSnappy's settings for this app.
- `.gitignore`: the two folders KeepSnappy writes to.
- `.github/workflows/keepsnappy.yml`: a new workflow, copied from the job that runs your tests today. It builds your app with [`KEEPSNAPPY=1`](https://keepsnappy.com/docs/glossary.md#keepsnappy1), which puts the SDK in the build, and runs your tests through `keepsnappy run`.

Your other workflows and your app's code stay as they are. Builds without `KEEPSNAPPY=1`, such as your store builds, don't carry the SDK ([Store builds](https://keepsnappy.com/docs/sdk.md#store-builds)).

At the end, init runs `keepsnappy doctor --group app`, which checks the app's setup ([`doctor`](https://keepsnappy.com/docs/glossary.md#doctor)). It prints one line per check, and every line should start with `ok`. Under a line that doesn't, it says what to fix.

If init stops with `Cannot go on: The iOS bundle id is not in app.json or the Xcode project.`, run it again with `--bundle-id` and the bundle id of your Release build. For a line that starts with `By you:`, a missing workflow or anything else, see [If init stops or leaves something to you](https://keepsnappy.com/docs/troubleshooting.md#if-init-stops-or-leaves-something-to-you).

With pnpm or yarn, init installs with your package manager. Run the `keepsnappy` command through it too, where these pages say `npx --no-install keepsnappy`:

```sh
pnpm exec keepsnappy doctor --group app
yarn keepsnappy doctor --group app
```

If init generates a CI workflow, that workflow builds the app for measurement. If you build it yourself or bring a build to a device farm, follow [Make a Release build](https://keepsnappy.com/docs/sdk.md#make-a-release-build).

A bare React Native app has a few more steps after init ([Bare React Native](https://keepsnappy.com/docs/bare-react-native.md)).

## 2. Push it and open a pull request

The pull request runs the new workflow once, which shows that the setup works in your CI before you merge it. Commit what init changed, push it, and open a pull request:

```sh
git switch -c add-keepsnappy
git add -A
git commit -m "Add KeepSnappy"
git push -u origin add-keepsnappy
gh pr create --fill
```

A bare React Native app also commits `ios/Podfile.lock`.

The pull request starts the KeepSnappy workflow. One run of it is a [session](https://keepsnappy.com/docs/glossary.md#session). A session builds your app, runs your [journeys](https://keepsnappy.com/docs/glossary.md#journey) and uploads the measurements. Each journey runs 5 times per session. A journey is one Maestro flow, or your whole test command with Appium or e2e. Maestro users: see [one journey per flow, or one for the suite](https://keepsnappy.com/docs/test-tools/maestro.md#one-journey-per-flow-or-one-for-the-suite).

When the job ends, the [KeepSnappy check](https://keepsnappy.com/docs/glossary.md#the-keepsnappy-check) passes. Each journey reads [**No main to compare**](https://keepsnappy.com/docs/glossary.md#no-main-to-compare), with the reason `Main had no runs on this phone when this branch ran.` That is expected: `main` has no measurements yet. Merge the pull request, then step 3 measures `main`.

<span id="3-merge-then-run-it-on-main-3-times"></span>
<span id="3-merge-then-measure-the-comparison-branch-3-times"></span>

## 3. Measure main 3 times

KeepSnappy compares every pull request with the last 3 measurements of your main branch. Until main has 3, pull requests show "Can’t tell".

Before you measure `main`, set up each journey to [use the same data every run](https://keepsnappy.com/docs/journeys.md#use-the-same-data-every-run): the same account, content, date and settings. Different data means different work, which can read as a slowdown your code did not cause.

Once the KeepSnappy setup (the files `init` added) is on main, run the KeepSnappy workflow on main 3 times:

```sh
gh workflow run keepsnappy.yml --ref main
gh workflow run keepsnappy.yml --ref main
gh workflow run keepsnappy.yml --ref main
```

Without the terminal: on GitHub open **Actions** → **KeepSnappy** → **Run workflow** on `main`, 3 times.

After the third measurement finishes, every new pull request gets a result.

If your main branch has another name, use it instead of `main`.

The 3 sessions can run at the same time. Each takes one build, plus 5 passes of your journeys, plus a few minutes to upload and wait for the result. Init sets the job's `timeout-minutes` to at least 90. If your build and tests take longer, raise it ([Budget the first session](https://keepsnappy.com/docs/ci.md#budget-the-first-session)). With e2e (e2e.com), the whole command runs on every repetition: for the first sessions, narrow it to a few test files.

Pin the Xcode version and the simulator's device type in the job. A pull request is compared with `main` on the same phone model, and a new model starts the history of `main` again.

From now on, the workflow also runs on every push to `main` and on every pull request.

## 4. Open a pull request, read the result

This checks that the setup is finished: from now on, every pull request gets a result like this one. Open any pull request, even one with a one-line change. When the KeepSnappy job ends, each journey has one result:

| Result | What it means |
|---|---|
| **Worse** | A [place](https://keepsnappy.com/docs/glossary.md#place) added one frame (16.7 ms) or more in every run, or the app kept much more memory than on `main`. |
| **Slightly worse** | Something got slower or kept more memory, but not enough for **Worse**. |
| **No change** | Nothing judged got slower, and nothing got faster. |
| **Better** | Something got faster, and nothing got slower. Today's rules do not give it yet. |
| **Can’t tell** | KeepSnappy couldn't compare, or too few places could be judged. The reason is shown with the result. |

[Results](https://keepsnappy.com/docs/results.md#the-five-words) gives the exact rules. Until `main` has 3 sessions on a phone model, its pull requests read **No main to compare** (no sessions yet) or **Can’t tell** (fewer than 3).

You can read the result in three places:

- On GitHub: open the KeepSnappy check's **Details**, then the workflow run's **Summary**. With `gh`, `gh run view <run id> --log` prints the job log, which has the same result after `KeepSnappy result for`.
- On the dashboard: open **Branches**, then your branch.
- In a terminal, with your CI key in `KEEPSNAPPY_KEY`: `npx --no-install keepsnappy status --branch <your branch>`.

During the pilot, a **Worse** does not fail your CI, because init sets [`verdict_gate: advisory`](https://keepsnappy.com/docs/glossary.md#advisory-and-blocking) in `keepsnappy.yml`. The KeepSnappy check passes, and the result still says **Worse**. [Required or advisory checks](https://keepsnappy.com/docs/ci.md#required-or-advisory-checks) explains the setting.

## Next

- [Your pull request's result](https://keepsnappy.com/docs/pull-request-result.md): send this page to your team. It says what to do for each result.
- [False alarms](https://keepsnappy.com/docs/false-alarms.md): mark a slower place that your change didn't cause.
- [Journeys](https://keepsnappy.com/docs/journeys.md): make your results steady.
- [Troubleshooting](https://keepsnappy.com/docs/troubleshooting.md): setup and run errors, with their fixes.

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
