Skip to content
Reference

Maintenance

Keep .stack.toml in sync with the project's manifests and config files using stack doctor --reconcile and stack remove --all-orphans.

The drift problem

Over time, .stack.toml and the project can fall out of sync. Someone drops the Supabase SDK from package.json but forgets to run stack remove. Or a service is in the config but nothing in the project points to it. stack doctor --reconcile reports this drift and stack remove --all-orphans cleans up the local side.

What counts as "used"

Both commands run the same source scan from the current directory. It reads files at the project root, not import statements under src/:

  • Dependencies in package.json, requirements.txt, pyproject.toml, go.mod and Cargo.toml.
  • Provider config files such as vercel.json, fly.toml, supabase/config.toml, wrangler.toml, firebase.json, render.yaml and .github/workflows/*.yml.
  • Variable names in .env.example, .env.sample or .env.template.

A service is an orphan when it is in .stack.toml and the scan does not find it. It is untracked when the scan finds it and .stack.toml does not list it.

stack doctor --reconcile

Compares the scan with .stack.toml. It is read-only and needs no credentials or Phantom.

stack doctor --reconcile
  ● 2 services configured · 2 detected in source

  ⚠ 1 orphan: posthog (no longer imported — run `stack remove posthog`)
  ○ 1 untracked: clerk (found in package.json — run `stack add clerk`)

With no drift it prints No drift — configured services match source. and exits 0. With drift it exits 2. Adding --fix or --all runs the normal health checks after the drift report.

stack doctor --reconcile --json prints the configured, detected, orphans and untracked lists inside the shared doctor envelope, with native_status set to in-sync or drift and one warn check per difference. It skips the health checks and exits 0 even on drift, so tooling must read status or the lists.

stack remove --all-orphans

Runs the scan again (it does not reuse a saved doctor --reconcile result), lists the orphans with their secret counts, then removes them from .stack.toml, removes their MCP entries and attempts to remove their Phantom secrets. It keeps upstream resources. In a terminal it asks for confirmation first. Without a TTY (CI, agent shells) it does not ask and removes the orphans at once.

# Preview first
stack doctor --reconcile

# Then remove orphans
stack remove --all-orphans
stack remove --all-orphans does not delete upstream projects. Inspect the orphan list before removing local configuration, especially from an agent shell, where there is no confirmation prompt. Phantom secret removal requires its terminal confirmation; headless cleanup or refused confirmation can leave secrets stored. Inspect any reported leftovers. --keepRemote is a compatibility flag, not a switch for remote deletion.

Using both in CI

To fail a job on drift, run stack doctor --reconcile without --json and let exit code 2 fail the step. To collect a report instead, save stack doctor --reconcile --json and inspect its fields. See CI integration → source-drift report and stack scan in CI.