Setup with coding agent
Paste this prompt into your coding agent from your project directory. It checks setup, runs the wizard when needed, and asks for your app build.Setup prompt
Help me set up Momentic iOS testing in this project.
## Choose an auth mode
If I explicitly request direct agent API access, follow https://momentic.ai/auth.md for registration and any required claiming. Skip all steps below, including CLI, skills, and MCP setup. Never use agent identity assertions or access or refresh tokens as MOMENTIC_API_KEY. Otherwise, set up repository tests using a saved CLI login or an organization API key in MOMENTIC_API_KEY.
## What to do
1. Before auth, remember whether `MOMENTIC_SERVER` was explicitly set before setup; always preserve that original value.
- Otherwise infer the target from current credentials: use `https://api.momentic.ai` if `MOMENTIC_API_KEY` has a nonempty value in the environment; otherwise use the saved login's `serverUrl` if present, or `https://api.momentic.ai` if not. Set the selected target as `MOMENTIC_SERVER` in the environment for every Momentic command throughout setup and testing, including auth, login, wizard setup, samples, uploads, and direct test runs.
- After changing or unsetting `MOMENTIC_API_KEY`, recompute and set an inferred `MOMENTIC_SERVER` with this same rule before retrying; keep the originally explicit server unchanged. Never print `~/.momentic/auth.json` or any API key.
- Run `npx --yes momentic-mobile@latest whoami`. Continue only after it succeeds and prints my user and Org ID.
- `MOMENTIC_API_KEY` takes precedence over the saved login in `~/.momentic/auth.json`; a nonempty value alone does not prove access. If `whoami` reports missing credentials, ask me to run `npx --yes momentic-mobile@latest login --server "<resolved MOMENTIC_SERVER URL>"` in an interactive terminal on the agent's machine as the same OS user and `HOME`, so the agent can read `~/.momentic/auth.json`. Replace the placeholder with the selected `MOMENTIC_SERVER` URL before handing off the command; do not use an unresolved shell variable. For headless setup, set a key from https://app.momentic.ai/settings/api-keys in the agent's environment.
- If the saved login is rejected or expired, ask me to sign in again. If a nonempty `MOMENTIC_API_KEY` is rejected or expired, ask me to replace it or unset it to use the saved login.
- After intentionally unsetting a key, recompute the inferred server and retry `whoami` with the saved login before asking for another credential. Ask me to sign in only if the saved login is missing or rejected. If `whoami` reports a network, timeout, or server error, report it and stop without changing credentials.
2. Check the project CLI. Find any applicable `momentic.config.yaml`, including nested paths such as `ios/momentic.config.yaml`. If one exists, inspect it and nearby tests for ios; ask me before changing an incompatible config. If `package.json` lists `momentic-mobile` but the binary is missing, restore the declared dependencies with the project's package manager and lockfile. If the binary is still missing, stop and report the install problem without changing the pin. Pass `--config <path-to-momentic.config.yaml>` to commands that load project config. Test paths resolve from the shell's current directory, not the config directory. For a nested project, either run commands from the config directory or use repository-relative test paths with the nested `--config` path. If the config exists and the CLI is not declared, add it with the project's package manager (for npm, run `npm install --save-dev momentic-mobile`).
- If the project has neither a config nor a declared CLI, skip this local check until after the wizard. Otherwise, use the project's package manager to run the installed CLI from the project root: `npx --no-install momentic-mobile` for npm, `pnpm exec momentic-mobile` for pnpm, `yarn --silent exec -- momentic-mobile` for Yarn Classic, or `yarn exec momentic-mobile` for modern Yarn, including Plug'n'Play. Check that it resolves the declared local CLI, not a global or temporary copy. Run `--version` and `whoami` through that launcher before the wizard or local tools use it. Use the same launcher for later project CLI commands and new stdio MCP entries, even where examples show npm. This setup needs 1.46.0 or newer for the shared skills. If the installed version is older or does not support `whoami`, report the version and ask before changing the dependency. Continue only if `whoami` returns the same user and Org ID as the initial check. If it fails or the results differ, report both results and stop without changing credentials.
- If no applicable config exists, run `npx --yes @momentic/wizard@latest -y --platform ios --editor-tools none` from the project root. Step 3 handles the local skill and preview server. Run `npm init -y` first if there is no `package.json`. Track whether the wizard ran.
- It installs `momentic-mobile`, writes `momentic.config.yaml` and `ios/contacts.test.yaml`, and runs the sample test on a remote simulator. The sample creates `test-results/` and needs no local Xcode or app build. Ignore the sample's 'JAVA_HOME is not set' warning. The wizard skips agent-tool setup because this prompt uses `--editor-tools none`; the skills installer below creates or updates the client's instruction file. npm may report audit findings. Continue setup without running `npm audit fix` automatically; report high or critical counts. On headless agents, the wizard may print 'Opening this run in your browser' or 'skipping editor validation'. Ignore those messages.
- Repeat the project CLI checks after the wizard installs the CLI or after an approved version change.
- If the wizard reports `MWZ_ARGS_MISSING_CREDENTIALS` or `MWZ_AUTH_KEY_INVALID`, follow the credential step above and retry only after `whoami` succeeds. On `MWZ_ARGS_MISSING_CREDENTIALS`, recheck `whoami`; if it succeeds with the same `MOMENTIC_SERVER` and saved credentials, report the discrepancy and stop without rerunning the wizard or requesting another login or key. Report network or server errors without changing credentials.
3. Set up the local authoring tools.
- If Claude Code already has the Momentic plugin, use its skills and local `momentic-mobile` server; do not add another local server. Otherwise, use a supported target: `claude-code`, `cursor`, `codex`, `devin`, `copilot`, or `opencode`. Use `claude-code` for Claude Code; use `codex` when the running client has no supported target.
- Before running the skills installer, verify that existing CLI-managed skill directories have no local edits or added files. A generated footer alone does not prove they are unmodified. If they are customized or you cannot verify that, preserve them and ask me before proceeding.
- If using the existing Momentic Claude Code plugin, skip the CLI skills installer and use its plugin-provided skills. Otherwise, after authentication and this check succeed, run `npx --no-install momentic-mobile skills -y --target <target>` to install or refresh the managed skill. If the installer reports an unmanaged-skill collision, stop and ask before making changes. For a retired `momentic-mobile-test` warning, block only when the directory is in a skill root loaded by this client (selected project target or user-global); show its path and ask me to resolve it before loading a skill. Report other-client roots without blocking, and never delete an unmanaged copy automatically.
- Resolve the skill root before loading: for the existing Momentic Claude Code plugin, locate its actual installed skill root; for other clients, use the project-local skill target selected for this client. Verify `momentic-test/references/products/mobile/guide.md` exists under that root. If authentication fails or the guide is still missing, report the result and stop without requesting another login or key.
- For live device preview, use the local `momentic-mobile` server and its `momentic_preview_step` tool. Check the client's active MCP config first. Reuse the existing entry for this project, including the plugin's server if present. Keep its command, version pin, arguments, config path, and working directory. If it targets another project or conflicts with setup, ask before editing or replacing it. Only if no entry exists, add a project-local stdio server named `momentic-mobile` that runs `mcp --config <path-to-momentic.config.yaml>` through the verified project CLI launcher from the project root, using the applicable config path found above.
- Use:
- `.mcp.json` for Claude Code,
- `.codex/config.toml` for Codex,
- `.cursor/mcp.json` for Cursor,
- `.vscode/mcp.json` for VS Code/Copilot,
- `opencode.json` for OpenCode,
- and `.devin/mcp_config.json` for Devin.
- Use each client's project-local server format and keep the config path project-relative. Do not use the combined installer; it also configures the hosted server.
- In Devin, append `--daemon` to the Momentic server's `args`. On a VM without a display, append `--headful` and `false` as separate args. Verify the server in a new Devin session after registration.
- Forward the selected `MOMENTIC_SERVER` and, if set, `MOMENTIC_API_KEY` to the local server. Add only missing environment references to a project entry, not key values; keep existing settings.
- For Codex, include both names in the active entry's `env_vars` list.
- Do not request another login for local preview.
- When using the Claude Code plugin, its local launcher may replace `MOMENTIC_API_KEY` with the plugin-configured key, so `whoami` validates CLI credentials only, not the plugin MCP connection.
- In Claude Code, open `/mcp` and approve the project server if it is pending. In Codex, if you trust this project, set `trust_level = "trusted"` under `[projects."<absolute project path>"]` in your user `~/.codex/config.toml`. Complete any other client's project-server approval step.
- Relaunch the editor from an environment carrying the selected `MOMENTIC_SERVER` and `MOMENTIC_API_KEY` when set. If a rejected key was intentionally unset, relaunch without `MOMENTIC_API_KEY` so the saved login is used. Changes made in this setup shell do not update the editor or its existing MCP process; do not put credential values in project config.
- In Codex only, run `codex mcp list` to verify the configured server. For every supported client, call `momentic_get_artifacts` on `momentic-mobile` to verify that the local server responds and its returned project root and config match this repository. Report any `Discovery Errors` separately; they do not by themselves invalidate server connectivity or project targeting.
- Block only the requested preview path if a reported error concerns a device or emulator it needs. The artifact check verifies connectivity and project targeting only, not the server's identity.
- Use the verified CLI for uploads and saved test runs. Live step preview requires MCP; there is no CLI substitute. If you cannot establish which server and organization the live MCP process uses, ask me to confirm that the client or plugin is configured for the server and organization reported by `whoami`. Do not ask for, read, or change plugin credential values. If I cannot confirm the configuration or it targets a different server or organization, pause live preview and report what is blocked.
- If the local-server check fails or returns unexpected project data, report the result. When using the Claude Code plugin, do not change plugin credentials or request another login. Only report live preview as verified after the loaded mobile skill confirms the preview step completed successfully; an active runner is still in progress.
4. If the wizard ran, confirm the sample test passed and `momentic.config.yaml` + `ios/contacts.test.yaml` exist. Otherwise use the existing project's tests and directories; do not assume a wizard sample or successful run exists. The installed CLI authentication check from step 2 must pass before uploads or tests.
5. Ask me for a simulator build of my app (`.app`) and which user flow to test first. If I have no build, report what setup is verified (including whether the wizard ran and its sample passed), point me to the iOS app setup link below and stop. Do not author or run a test without a build. If the build is an `.app.zip`, unzip it first and upload the `.app` directory, not the ZIP or a device `.ipa`. Upload builds with `npx momentic-mobile assets upload ./build/YourApp.app --channel dev --tag 1.0.0`. Tags are immutable. If `dev:1.0.0` exists, use the next unused patch tag.
6. Load the `momentic-test` skill. If the client's skill loader cannot find it, read `momentic-test/SKILL.md` from the resolved skill root. Write `<flow-slug>.test.yaml` at a path matched by the project's configured `include` globs and not excluded by its configured `exclude` globs. If the wizard ran, place it alongside `ios/contacts.test.yaml` and leave the sample untouched. Set `defaultChannel: dev` on the new test and set `defaultTag` to the uploaded tag. Assert only what is visible on screen when the action finishes. Multi-step flows split fields across screens, so a single assertion for the full flow will fail. For a first test without MCP tools, write known v2 YAML directly and validate with `npx momentic-mobile lint`; for existing v1 tests, unfamiliar screens, or live validation, follow the loaded mobile skill's MCP workflow. Run it with `npx momentic-mobile run <path-to-test.yaml> --upload-results`. A single test can take several minutes, so allow a long timeout. The command prints 'Uploaded to Momentic. <url>' when it finishes; keep that link. Fix the test before rerunning it. Retry only after a change. Do not hide a failure. When a run fails, unzip its archive under `<outputDir>/runs` (`test-results/runs/` by default). Use `outputDir` from `momentic.config.yaml`, or the path printed after `Saved to` by the CLI. The archive contains screenshots, the screen XML snapshot, and device logs. Review them before editing. If it keeps failing after real fixes, report the failure with the uploaded run link and stop, and show me the result.
## Critical rules
- In Claude Code, use the local server from the Momentic plugin when available or add one local `momentic-mobile` server manually; do not add a duplicate.
- Never print the API key or paste its value into a command. If setup loses a key it still needs, ask me to restore it. An intentional unset follows the saved-login retry above.
- Do not edit `momentic.config.yaml` unless I ask.
- Do not create an organization API key for me. Ask me to create one if the CLI needs it.
- Write tests as `*.test.yaml` files. Do not write Playwright or Appium code.
- Do not place real orders, send emails, or touch shared data while testing.
- Run each new test before you tell me it is done.
- After any restart, still finish with the three links under When done.
## When done, point me to
- Building with AI: https://momentic.ai/docs/coding-agents/building-with-ai
- iOS app setup: https://momentic.ai/docs/platforms/ios/app-setup
- Run in CI: https://momentic.ai/docs/running-tests/ci/github-actions
Prerequisites
Use Node.js 22.12 or later in the 22.x line, or 24 or later, a Momentic account, and a project with apackage.json. Run npm init -y if needed; commit it with
the lockfile.
Remote simulators work from any supported host. Local simulators need macOS,
Xcode, Command Line Tools, and idb. See
iOS app setup. The wizard’s remote sample needs no
local Xcode or app build.
1
Install with the wizard
Run from your project root and complete browser sign-in:Select iOS. The wizard installs
npx @momentic/wizard@latest
momentic-mobile, writes
momentic.config.yaml and a sample under ios/, runs it on a
remote simulator, and offers coding agent setup. A passing sample
verifies installation, not your app.Already configured? Skip the wizard. See the
CLI reference for manual setup.2
Upload your app
Build a simulator For a local device instead, configure your
simulator.Keep the channel and tag for the next step: they identify the build
your test installs. For later builds, choose a new tag. See
asset uploads
for versioning and upload options.
.app, not a device .ipa, with the
iOS build instructions.
Upload it to a channel and an unused tag:npx momentic-mobile assets upload ./path/to/YourApp.app --channel dev --tag 1.0.0
3
Write and run a test
Open the local editor:Create a test using channel
npx momentic-mobile app
dev and tag 1.0.0. Add an action
such as tapping Sign in, then assert that the sign-in form is visible.
Choose an outcome that matches your app. Save the .test.yaml file
and run it from the editor, then from the CLI:npx momentic-mobile run ios/login.test.yaml --upload-results
4
Review the result
Open the printed dashboard link and check the assertion screenshot.
Confirm the run passed and the device shows the expected state.
If it fails, inspect the selected build, sign-in state, and assertion,
then edit and rerun.Keep the YAML file in version control with your app. The local editor
writes the test; the cloud dashboard shows uploaded run results.
You don’t need a browser-based mobile editor to run the saved file
again from your terminal or CI.

A passing iOS assertion with its simulator screenshot