> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getcargo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are an AI coding agent operating Cargo, install the agent skills first: paste `Install Cargo by following https://api.getcargo.io/INSTALL.md` into your session, or run `npx skills add getcargohq/cargo-skills`. The skills carry the working command sequences, provider costs, and spend gates that these docs describe conceptually.
> The skills index at https://raw.githubusercontent.com/getcargohq/cargo-skills/main/llms.txt lists every skill, recipe, and provider playbook individually. Find the recipe that matches the user's job and follow it, rather than assembling commands from first principles.
> Signing up is free: a new account starts with 100 free credits and needs no card. `cargo-ai login --email you@company.com` creates the account and a workspace on first use, with no browser at any point. Tell the user this before asking them to sign up.
> Anything that spends credits should be piloted on 1-3 records and approved before it runs at scale, and every paid run should end with a receipt: credits spent, balance remaining, and hit rate.

# Deploying

> The project reconcile lifecycle — plan, deploy, prune, refresh, import and destroy — plus the flags that control confirmation, pruning and locking.

`cargo-ai project` reconciles your code against the live workspace. All commands accept
`--dir <path>` (defaults to the current directory) and resolve this project's
deploy state relative to it, through the `cargo.state.json` that names it.

Commands below are shown as `cargo-ai project <command>`. The engine ships inside
the Cargo CLI, so there's no separate install or login. If you'd rather not install
the CLI globally, the project-local bin, `npx @cargo-ai/cdk <command>`,
exposes the identical subcommands; in a scaffolded project, `npm run plan` /
`deploy` / `types` are shortcuts for the common ones.

## Plan

```bash theme={null}
cargo-ai project plan
```

Compiles your resources and diffs them against this project's deploy state.
Output marks each resource `+ create`, `~ update`, `= noop`, or `- delete`
(state-tracked but no longer in code). It changes nothing, in the workspace or
on disk.

Connect the repository to the project and Cargo runs this on every pull request
for you, as a comment and a check — see [GitHub](https://docs.getcargo.ai/deploy/github.md).

## Deploy

```bash theme={null}
cargo-ai project deploy            # create/update; prompts before applying
cargo-ai project deploy --yes      # skip the prompt (required in CI / non-TTY)
cargo-ai project deploy --dry-run  # show the plan, change nothing
```

`deploy` applies in dependency order and **persists state after each resource**,
so a crash mid-deploy leaves a recoverable state — just re-run.

**1. Create**

First deploy creates every resource and writes state.

**2. No-op**

Re-deploy with no code changes does nothing.

**3. Update**

Change one resource; only it updates.

### Prune

By default `deploy` never deletes. To remove resources you deleted from code:

```bash theme={null}
cargo-ai project deploy --prune
```

Without `--prune`, the plan still shows what *would* be pruned and reminds you.

### Refresh on deploy

```bash theme={null}
cargo-ai project deploy --refresh
```

Re-reads the live resources first and folds any out-of-band drift into the plan:
a resource edited in the UI re-applies (code wins). A resource **deleted** in the
UI is *not* silently recreated — the deploy stops and asks you to either re-run
with `--recreate-deleted` (to restore it) or remove it from your code (if the
deletion was intentional). See [State & drift](https://docs.getcargo.ai/deploy/state-and-drift.md).

## Import

Bind an existing live resource to a code resource — recover a lost state link, or
adopt pre-existing infra:

```bash theme={null}
cargo-ai project import agent:sdr 1a2b3c4d-...
```

Cargo reconstructs the resource's outputs and records it so the next deploy is
a no-op. Imported resources are treated as **adopted**: a later `destroy`
releases them (drops them from state) rather than deleting infra the project didn't
create.

### Referencing existing resources

You don't have to import (or define) a resource just to point at it. Every
builder that takes a handle also accepts a `xxRef(uuid)` — a typed reference to
a live resource the repo doesn't manage:

```ts theme={null}
import { defineModel, definePlay, connectorRef, playRef } from "@cargo-ai/cdk";

// A connector that was connected via OAuth in the UI
export const contacts = defineModel("contacts", {
  connector: connectorRef("9c26…"),
  extractSlug: "fetchRecords",
});

// Chain a code-defined play after one that only exists in the workspace
export const followUp = definePlay("follow-up", {
  model: contacts,
  schedule: { type: "dependency", play: playRef("1a2b…") },
});
```

Available refs: `connectorRef`, `modelRef`, `folderRef`,
`playRef`, `memberRef`, `segmentRef`, plus `toolRef` / `agentRef` for
workflow `uses`. The kind is branded, so a `modelRef` can't be passed where a
connector is expected. Referenced resources stay unmanaged: they're never
deployed, pruned, or destroyed by the project — the uuid is injected as-is.

Members are the exception worth knowing: `defineMember("alice@acme.com")` adopts
the live member with that email, so a territory doesn't have to hardcode uuids
that only exist in one workspace.

## Rollback

```bash theme={null}
cargo-ai project rollback
```

Restores this project's deploy state from the snapshot taken before the last
deploy/destroy/import. It restores the **state only** — live resources are
untouched — so follow it with `cargo-ai project deploy --refresh` to reconcile the
workspace back to it. Accepts `--yes` to skip the prompt and `--force` to steal
a stale lock.

## Destroy

```bash theme={null}
cargo-ai project destroy --all                   # tear down everything in state
cargo-ai project destroy --target play:welcome   # just one resource
```

Blanket teardown is opt-in: `destroy` refuses unless you pass `--all` or
`--target <id>` (so `--yes` alone can't wipe a workspace). It deletes by uuid in
dependency-safe order (dependents first) and **releases** adopted resources
instead of deleting them. A `--target` that still has dependents — or that
isn't in state — is rejected rather than silently skipped.

> [!WARNING]
>
> `destroy` and `deploy --prune` delete real Cargo resources. With `--yes` they
> skip the prompt — double-check `--dir` and that `cargo.state.json` points at
> the state for the workspace you intend.

## Locking & `--force`

A deploy/destroy/import holds a lock on the state for the whole read→plan→apply
sequence so two concurrent runs can't corrupt it — across machines, not just
across processes on one. A lock left by a run that died expires after an hour;
to override one you believe is stale:

```bash theme={null}
cargo-ai project deploy --force
```

## Programmatic use

`plan`/`apply` are exported, so CI or the backend can reconcile the same way:

```ts theme={null}
import {
  loadResources,
  apply,
  liveExecutors,
  liveReaders,
  resolveStateBackend,
  emptyState,
} from "@cargo-ai/cdk";

// Reads cargo.state.json and hands back the state it names — the one in your
// workspace, or the file itself for a project that still holds its own map.
const { backend } = await resolveStateBackend({
  root,
  mode: "write",
  getApi: () => api,
});

const nodes = await loadResources(root); // import the repo's resource files
const prior = await backend.read();
const state = prior !== undefined ? prior : emptyState(workspaceUuid);
await apply(
  { nodes, state },
  liveExecutors(api),
  (next) => backend.write(next),
  liveReaders(api),
);
```

> [!WARNING]
>
> Go through the backend rather than `readState`/`writeState`. Those read and
> write the committed file directly, so against a project whose state lives in
> the workspace they would see nothing deployed, create a second copy of every
> resource, and overwrite the pointer with the map they built. `writeState`
> refuses that, but the backend is the path that works.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.