
# Quickstart: an existing app

Start here if you already have code. `agc init` creates the app on Agent Cloud and writes an `agentcloud.toml` that says how to run it, without overwriting your files. It worked when it answers `"linked": true`; the app is live once `agc ship` exits 0 with `"outcome": "live"`.

```bash
agc init --name camp-bookings --bring
```

## Execution contract

- **Before starting:** Work in the existing repo. Review what `agc init` inferred, whether the app needs its existing data, and what it does in a rehearsal (`AGC_RUN=rehearsal`, with app secrets).
- **Do:** Run `agc init`, review `agentcloud.toml`, then `agc doctor`, `agc up --detach`, `agc migrate` and `agc check`. Ship only when deployment is intended.
- **Success:** The intended checks pass; release success requires exit 0 and `"outcome": "live"`.
- **If blocked:** If the app needs existing production data, stop before the first ship: import completion is unavailable at this revision. For anything else, follow the error's `fix`.
- **Human handoff:** Relay the claim link, or the first ship's `data.relay`; wait for the person. Inspect [rehearsal side effects](/docs/concepts/rehearsals.md) before shipping integrations.

## Ask your agent

Open your coding agent in the repo's root folder and paste:

```text
Get this repo running on Agent Cloud using the verified setup steps below and the local AGENTS.md that agc init writes. Keep the code as it is unless something has to change to run there, and tell me what you changed.
```

You'll get a claim link, or after the first ship a preview link and a publish link that puts it live.

## Steps

**1. Link the repo.** In the repo root:

```bash
agc init
```

agc names the app from `package.json`'s `name` or `pyproject.toml`'s `[project] name`, lowercased. With neither, or with a placeholder like `my-app` or `demo`, it refuses with `init.name_needed`. Then pass a name and `--bring` (`--name` alone, in a folder with files or inside a git repository, fails with `init.not_new_folder`):

```bash
agc init --name camp-bookings --bring
```

The answer, abbreviated:

```json
{
  "ok": true,
  "product": "agent.cloud",
  "command": "init",
  "data": {
    "app": "camp-bookings",
    "url": "https://camp-bookings.ac0.app",
    "claim_url": "https://agent.cloud/claim/camp-bookings?code=…",
    "manifest": "/Users/you/camp-bookings/agentcloud.toml",
    "linked": true,
    "created_app": true,
    "gitignore_env_mirror": true,
    "agents_md": "appended",
    "claude_md": "appended",
    "inferred": { "port": 3000, "command": "node dist/server.js", "health": "/healthz", "env": "DATABASE_URL", "migrations": "migrations/" },
    "mask": [],
    "notes": [],
    "port_plan": "written"
  },
  "next": [
    { "cmd": "agc help bring", "why": "port it in slices: fill docs/port-plan.md, and get your person’s yes before the first slice" },
    { "cmd": "agc doctor", "why": "check the CLI, login and manifest" },
    { "cmd": "agc up --detach", "why": "start your mirror with masked production data" }
  ]
}
```

Relay `claim_url` to the person; see [Claiming an app](/docs/getting-started/working-with-your-coding-agent.md#claiming-an-app-and-connecting-your-agent). An app made from a console join code has no `claim_url`.

**2. Review `agentcloud.toml`.** For the answer above, agc wrote (lines the runtime ignores left out):

```toml
# Written by `agc init`. Review the mask rules: they decide what a mirror can see.
[app]
name = "camp-bookings"

[service.web]
build   = "."
port    = 3000
command = "node dist/server.js"
dev     = "npm run dev"       # what agc up runs: the whole app on PORT, reloading on save
health  = "/healthz"

[data.db]
env        = "DATABASE_URL"
migrations = "migrations/"
mask = [
]

[mirror]
expire_idle = "3d"
```

Check each inferred value against what the app does. A Python app with no Dockerfile `CMD` and no `npm start` gets no `command`, and its first ship fails with `ship.no_command` until you add one:

```toml
[service.web]
command = "uvicorn app.main:app --host 0.0.0.0 --port $PORT"
```

**3. Move schema changes into `migrations/`.** Agent Cloud runs migrations itself, through `agc migrate` on the mirror and `agc ship` in production, so drop any ORM migrator that runs at start-up. Each migration is a plain SQL file named `<digits>_<slug>.sql` or `<digits>_<slug>/migration.sql`, applied in numeric order in one transaction.

**4. Check the wiring and start the mirror**, your own copy of the app on this machine:

```bash
agc doctor
agc up --detach
```

`agc doctor` warns (`data wiring`) when no source file mentions the variable `[data.db] env` names. `agc up` installs dependencies from the lockfile, starts the `dev` command on `http://127.0.0.1:<port>`, and points that variable at the mirror's own database. Production starts empty, so the mirror applies your migrations, then `seed` if you set one.

**5. Say what must stay true, then check:**

```bash
agc check
```

Add at least one `[[check.smoke]]` flow for the main feature, and an invariant for any rule the data must keep. Agent Cloud doesn't run your own test suite.

**6. Decide about existing data.** Production starts empty. `agc import <dump>` validates a `pg_dump` locally and returns a console link, but its upload-and-confirm page is unavailable at this revision. If the app needs its data, stop here before the first release. Continue to ship only if empty production is acceptable ([Importing existing data](/docs/data/importing-existing-data.md)).

Rehearsals get the app's secrets, so review [rehearsal side effects](/docs/concepts/rehearsals.md) first and handle `AGC_RUN=rehearsal`. Captured platform email does not capture direct provider calls.

**7. Ship:**

```bash
agc ship
```

A claimed app's first release goes live once its rehearsal passes, with no approval. An unclaimed app's ends at a private preview (exit 10, `"outcome": "preview"`): relay `data.relay`, then `agc wait <op>` answers `live` once the person publishes. Set the app's icon first ([Your app's icon](/docs/build/your-apps-icon.md)).

## How it works

`agc init` reads only the repo: the root's `Dockerfile`, `package.json`, `pyproject.toml`, and up to 300 source files, skipping `node_modules`, `.venv`, `dist`, `build`, `tests` and `migrations`.

| Key written | Inferred from | Default |
|---|---|---|
| `[app] name` | `package.json` `name`, else `pyproject.toml` `[project] name` | refused (`init.name_needed`) |
| `[service.web] port` | `EXPOSE` in the Dockerfile, else `PORT=<n>` there | `8080` |
| `[service.web] command` | Dockerfile `CMD`, else `scripts.start` (written as the script's own text) | none |
| `[service.web] dev` | `npm run dev` when `scripts.dev` exists | none |
| `[service.web] health` | a quoted `/healthz`, `/health`, `/api/health` or `/v1/health` in the source | none |
| `[data.db] env` | the first `process.env.*DATABASE_URL*` or `os.environ`/`os.getenv` lookup | `DATABASE_URL` |
| `[data.db] migrations` | a `migrations/` folder | `migrations/` |
| `mask` | suggested rules by column name, or `keep` for at most 50 distinct values; runtime masking policy still applies | empty for a new app |

If the source mentions `schema_migrations`, `notes` says the repo has its own migrator and that agents shouldn't run it.

If an `agentcloud.toml` already exists, `agc init` links the app it names and leaves the file unchanged (apart from adding `[app] org` for an organization's app), and `note` says so. Passing a different `--name` there fails with `init.name_fixed`. Linking an app that's already live writes its live web and worker settings instead of inferring them.

`AGENTS.md` gets Agent Cloud's section appended (your own text above it is kept), `CLAUDE.md` gets an `@AGENTS.md` line, `docs/port-plan.md` gets a plan to fill in (`agc help bring`), and `.env.mirror` goes into `.gitignore`.

## Errors

Every code, its exit and fix: [Error code catalog](/docs/reference/error-code-catalog.md).

Outside a linked folder, `agc ship` exits 1:

```json
{
  "ok": false,
  "product": "agent.cloud",
  "command": "ship",
  "error": {
    "retryable": false,
    "code": "app.not_linked",
    "message": "No agentcloud.toml in this directory or above it.",
    "fix": "Run `agc init` in the app repository.",
    "docs": "agc help onboarding"
  },
  "next": [
    {
      "cmd": "agc init",
      "why": "create the app on agent.cloud and write agentcloud.toml"
    }
  ]
}
```

## Agent notes

- `agc init` also writes `[data.db] engine`, `tool` and `[release] watch`, which the runtime doesn't read.
- Mirrors and production run differently: the mirror runs your `dev` command natively, production runs the built image's `command`. A missing `command` only shows up at ship.
- The `health` guess is a match over the source: confirm the path is a real route.

## Related

- [Quickstart: a new app from an empty folder](/docs/getting-started/quickstart-new-app.md)
- [How your image is built](/docs/build/how-your-image-is-built.md)
- [Migrations](/docs/data/migrations.md)
- [Importing existing data](/docs/data/importing-existing-data.md)
- [`agentcloud.toml` reference](/docs/reference/agentcloud-toml-reference.md)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "getting-started/quickstart-existing-app: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
