| 1 | --- |
| 2 | title: drift |
| 3 | description: Detect infrastructure drift by re-observing the cloud, and optionally repair it back to the last deployed state. |
| 4 | --- |
| 5 | |
| 6 | ```sh |
| 7 | alchemy drift [options] |
| 8 | ``` |
| 9 | |
| 10 | Re-observe every deployed resource and compare the live cloud state |
| 11 | against what alchemy last persisted. The result renders exactly like a |
| 12 | deploy plan: unchanged resources are no-ops, out-of-band edits show as |
| 13 | **drifted**, and resources deleted behind alchemy's back show as |
| 14 | **missing**. |
| 15 | |
| 16 | By default, `drift` only reports changes. Pass `--repair` to restore drifted |
| 17 | and missing resources to the last deployed state. Alchemy shows the plan and |
| 18 | asks for approval unless you pass `--yes`. It reads the cloud state again |
| 19 | before applying the repair. |
| 20 | |
| 21 | ## Flags |
| 22 | |
| 23 | | Option | Description | |
| 24 | | ------------------- | ------------------------------------------------------------------ | |
| 25 | | `--repair` | Repair detected drift after showing and confirming the plan | |
| 26 | | `--stage <name>` | Stage to check (defaults to `$ALCHEMY_STAGE` or `live_$USER`) | |
| 27 | | `--yes` | Skip the repair confirmation prompt | |
| 28 | | `--profile <name>` | Auth profile to use (defaults to `$ALCHEMY_PROFILE` or `default`) | |
| 29 | | `--env-file <path>` | Load environment variables from a file | |
| 30 | | `--config, -c <file>` | Stack file to check (defaults to `alchemy.run.ts`) | |
| 31 | |
| 32 | ## Examples |
| 33 | |
| 34 | ```sh |
| 35 | # Report drift for the default stage |
| 36 | alchemy drift |
| 37 | |
| 38 | # Check production |
| 39 | alchemy drift --stage prod |
| 40 | |
| 41 | # Repair drift without an interactive prompt (e.g. a scheduled job) |
| 42 | alchemy drift --stage prod --repair --yes |
| 43 | ``` |
| 44 | |
| 45 | ## Where next |
| 46 | |
| 47 | - [plan](/cli/plan) previews desired-state changes instead of drift |
| 48 | - [Resource Lifecycle](/infrastructure-as-code/resource-lifecycle) explains how reconcile updates observed state |
| 49 | - [Inspecting State](/cli/inspecting-state) explains how to inspect Alchemy's deployment record |