# Install the app on the user phone from chat

> Instructions for AI agents. Human page: https://capgo.app/phone-install/

Use this flow when the user has only a phone and a chat app connected to the hosted Capgo MCP at https://api.capgo.app/mcp. You build the Capacitor app in the Capgo cloud terminal, Capgo Cloud Build compiles it, and the user installs it from a link on the phone. No computer, TestFlight or Expo Go.

Never ask the user to paste a GitHub token, an App Store Connect key or any other secret into the chat or MCP arguments. They enter secrets only in the signed-in Capgo console (MFA supported), from the phone browser.

## 1. One-time setup (the user, in the Capgo console)

Both **Build signing credentials** and **Code sync** are open cards on the app’s **Builds > Credentials** sub-tab:

- **Code sync (GitHub):** `https://console.capgo.app/app/<appId>/builds/credentials#code-sync` (also returned as `setup_url` by `capgo_get_code_sync`). Save a repository and a fine-grained personal access token with Contents: Read and write (plus Administration if Capgo should create the repository). Capgo stores the token AES-256-GCM encrypted and passes it only to root `git` in the sandbox—never visible to chat, MCP, or unprivileged sandbox commands (`uid 1000`).
- **iOS signing key:** `https://console.capgo.app/app/<appId>/builds/credentials#signing-credentials`. Create a team App Store Connect API key with the **Admin** role (required to create a distribution certificate) in App Store Connect (Users and Access > Integrations > App Store Connect API), download the `.p8` file, and save `APPLE_KEY_ID`, `APPLE_ISSUER_ID`, and `APPLE_KEY_CONTENT` in **Builds > Credentials**.
- **Android:** nothing to upload. Every Android build needs a keystore, and `capgo_setup_android_signing` creates one server-side (step 3).

## 2. Build the app in the cloud terminal

1. Call `capgo_whoami` and `capgo_list_apps`. Create the app with `capgo_add_app` if needed; confirm the name and app ID with the user first.
2. Call `capgo_get_code_sync` to check if GitHub Code sync is configured; if not, share its `setup_url` with the user.
3. Call `capgo_start_terminal` with `appId`. If the repository already has pushed code, call `capgo_terminal_git_pull` right away to restore it, then run `npm install`.
4. Create and edit the Capacitor app with `capgo_terminal_run_command`, `capgo_terminal_write_file` and `capgo_terminal_read_file`. See https://capgo.app/cloud-terminal.md for limits.
5. Push explicitly with `capgo_terminal_git_push` after each meaningful change and before `capgo_stop_terminal` or the session limit. Ending a session deletes unsaved workspace files.

## 3. Signing and device registration

- **Android:** call `capgo_setup_android_signing`. Capgo generates an RSA 2048 PKCS#12 keystore server-side (valid 30 years; keeps any existing keystore untouched with `created: false`) and returns the certificate SHA-256 fingerprint. Every Android build needs a keystore, debug builds included.

**iOS Ad Hoc (direct phone install):**

1. Call `capgo_get_ios_device_registration_link` and send the link to the user. The link stays valid for 7 days and supports up to 100 iPhones per app. The user opens it in Safari on the iPhone and installs the small registration profile in Settings. Wait for the user to confirm (you can inspect enrolled devices with `capgo_list_ios_devices` and remove one with `capgo_remove_ios_device`).
2. Call `capgo_setup_ios_signing` with `distribution: "ad_hoc"`. Capgo creates the distribution certificate (reusing a stored one when present), registers enrolled iPhones with Apple, and creates the Ad Hoc provisioning profile. **Check `failed_devices` and verify it is empty** before building; if any intended iPhone failed, resolve the error and rerun `capgo_setup_ios_signing`.
3. For TestFlight / App Store builds later, run `capgo_setup_ios_signing` with `distribution: "app_store"`.

## 4. Build and install

1. In the terminal, package the project (see https://capgo.app/cloud-terminal.md, "Ship a native build"), then call `capgo_request_build` (uses stored credentials automatically):
   - **iOS Ad Hoc:** pass `build_options: {"iosDistribution":"ad_hoc","outputUploadEnabled":true}` (optionally `outputRetentionSeconds` up to `604800` for 7 days; default `3600` = 1 hour).
   - **Android APK:** pass `build_options: {"outputUploadEnabled":true}` (pass `playstore_upload: false` if Play credentials are stored and you do not want to upload to Google Play).
2. Upload the archive to `capgo_get_build_upload_url`, call `capgo_start_build`, and follow `capgo_get_build_status` and `capgo_get_build_logs`.
3. Once the build succeeds, call `capgo_get_build_install_link` and share the returned `url` and instructions with the user:
   - **iPhone:** the page has a one-tap `itms-services` **Install** button (open in Safari on a registered iPhone). On iOS 16+, enable **Settings > Privacy & Security > Developer Mode** once.
   - **Android:** the page has a direct APK **Download** button. Allow the browser to install unknown apps once.

## 5. Keep changing the app

For web code changes, ship a Capgo live update to the installed app (see https://capgo.app/cloud-terminal.md, "Ship a live update"). Rebuild only when the native side changes, for example a new plugin. Push code explicitly with `capgo_terminal_git_push` and stop the terminal with `capgo_stop_terminal` when done.

This uses the build minutes and the cloud terminal minutes of the user plan.

## Reference

- Human page: https://capgo.app/phone-install/
- Docs: https://capgo.app/docs/ai/phone-install/
- Cloud terminal: https://capgo.app/cloud-terminal.md
- Hosted MCP: https://capgo.app/docs/ai/mcp/
- Site index: https://capgo.app/llms.txt
