How cleanup works
Commands use stim. If it is not installed globally, replace stim with
npx stim.
Stim's background process, stimd, stops what is idle and deletes what can be
rebuilt: build outputs, caches, the simulators and emulators it created, and
worktrees whose work is merged. Your source, unpushed commits and anything in
use stay. It is on by default and off in CI. Preview what it would do now:
- Global
- npx
stim gc --dry-run
npx stim gc --dry-run
The preview answers from the report stimd keeps fresh, the same one Stim
Desktop shows, and says how old it is. Add --refresh to measure again now,
for example right after adding or removing worktrees.
Phases
A workspace moves through these as it sits unused:
| Phase | Starts | Setting (default) |
|---|---|---|
| Idle | 60 minutes without activity | idle.minutes (60) |
| Dormant | 1 day without activity | idle.dormantDays (1) |
| Finished | 2 hours after it last changed or finished, for a linked worktree that is merged or whose pull request has ended | gc.worktreeGraceMinutes (120) |
Activity is a Stim command, a build, a Metro request, an agent-device command or input to a device; for dormant, also a file or git write or a process in the checkout. App logs do not count. A clean linked worktree with no commits of its own counts as finished.
The machine has one level, set every minute from memory and the free disk of every volume Stim writes to:
| Level | When |
|---|---|
| high | free disk under disk.minFreeGb (40 GB), a macOS memory warning for 10 minutes, or under 10% of RAM available |
| critical | free disk under disk.criticalFreeGb (20 GB), or critical memory on macOS |
| refuse | free disk under disk.hardFloorGb (5 GB) after cleanup ran |
Above normal, cleanup works down a ladder, cheapest to rebuild first, on the
short volume only, and stops once the level is normal. High cleanup also runs
above 40 GB when a volume fills fast, and before a native build that may not
fit. Memory pressure alone shuts down booted parked simulators, runs the idle
stage and stops daemons. At
refuse, start, ios and android fail with
STIM_LOW_DISK: free space or run stim gc, then retry.
Deletion rules
Caps are checked hourly, finished worktrees every 15 minutes, and unused things daily. High and critical add to the rows above them.
| Phase | Stops | Deletes |
|---|---|---|
| Idle | the dev server and workspace services, data kept; owned simulators and emulators shut down. With a device on another Mac, after maintenance.idleStopHours (6) instead | nothing; under disk pressure, its build outputs on the short volume, an Exact or tagged Cargo target/ included, and the app's Metro cache |
| Dormant | build outputs, any root Cargo target/ included; owned simulators and emulators; a linked worktree's node_modules and Pods holding 256 MB of their own. Logs are archived | |
| Main checkout, 7 days | its node_modules and Pods (idle.sourceDormantDays) | |
| Finished | its dev server, devices and services | the worktree, and its branch when Stim created it and it has no unique commits, after archiving uncommitted changes for up to 30 days. One kept for its changes loses its owned devices |
| Any time | idle Gradle and Kotlin daemons; a restart of an unused Watchman over 2 GiB (1 GiB under memory pressure); a parked simulator left booted for 15 minutes; an idle workspace's booted device, when a run needs a slot | over a cap: build outputs (20 GB), the build (10) and Metro (5) caches, stale Cargo target/ profiles, then other profiles' incremental data, of an idle target (25), parked devices (3 per platform). Unused for maintenance.olderThanDays (3): build outputs, cache entries, parked devices. Also unpinned Gradle versions (all at critical), TMPDIR leftovers, Jest's cache, unused iOS simulator runtimes (never one simctl does not mark deletable, one used in the last 7 days, one of the active Xcode's major version, the only one, the newest when none is used, or one ios.runtime pins), what removed projects left behind, logs at 8 MiB (one over 16 MiB is cut to its newest 8 MiB), recordings past the newest 15 minutes per device or 1 GiB per home, oldest first, and archives past archive.* |
| High | workspaces idle 2 minutes, under memory pressure; booted parked simulators | parked devices, oldest first; shared caches to half their caps; stale Cargo profiles and incremental data; build outputs of stopped workspaces; owned devices of workspaces idle 10 minutes |
| Critical | running workspaces idle at most 15 minutes | every parked device; shared caches and the fingerprint index, except entries in use; owned devices of workspaces idle 2 minutes; recordings, archived logs and archived agent actions. If still short: the npm, Yarn, pnpm, CocoaPods, Gradle and SwiftPM caches and Xcode's compilation cache, each while its tool is idle |
| A Mac hosting others | a hosted session without its client for 6 hours; idle Gradle daemons at low memory | a stopped session's home after an hour; parked hosted devices; a build client's repository area unused for server.workerAreaMaxAgeDays (7), or sooner when its disk runs low |
Only reported, by stim gc --dry-run: Android NDKs, unused system images,
Exact's cache and Xcode device support.
Never touched:
- Tracked files, untracked files git does not ignore, and unpushed commits.
- Anything building, driven by an agent, leased, shared or hosted, except that a workspace with a device on another Mac still stops when idle and still loses build outputs.
- A workspace pinned with
maintenance.keep. - A worktree locked with
git worktree lock, its dependencies and its build outputs. - Simulators and emulators you created, physical devices,
ios/build, and Xcode DerivedData outside Stim, except its compilation cache at critical. - Checkouts no
stimcommand ran in, unless discovery reaches them.
Exceptions:
- A finished worktree goes with its uncommitted changes, once archived, and
with all of its git-ignored files, such as a
.envcreated there. Ignored files in a worktree are disposable state; keep what matters in the main checkout or outside the repository. - Removing a finished worktree tears down its workspace services, which deletes their data.
- You reinstall the main checkout's dependencies yourself.
- A pinned workspace still has its logs trimmed, its recordings expire, its hosted device stopped and its booted device shut down for a waiting run.
- A locked worktree still goes idle and dormant; only the worktree, its dependencies and its build outputs stay.
daemon.mode offstill stops an idle dev server thatstimdruns, and its devices. In every mode logs rotate, recordings expire, and stim-server on a Mac hosting others deletes stopped sessions' homes; it stops abandoned sessions only inon.
Settings you might change
| To | Set |
|---|---|
| See what it would do, deleting nothing | daemon.mode report |
| Turn automatic cleanup off | daemon.mode off |
| Pin one workspace, from inside it | maintenance.keep true --scope workspace |
| Stop removing finished worktrees | maintenance.removeFinishedWorktrees false |
| Keep a finished worktree that has changes | archive.enabled false |
| Wait longer before idle (60 minutes) | idle.minutes 120 |
| Wait longer before dormant (1 day) | idle.dormantDays 3 |
| Never touch the main checkout's dependencies | idle.sourceDormantDays 0 |
| Clean earlier or later (40, 20 and 5 GB) | disk.minFreeGb, disk.criticalFreeGb, disk.hardFloorGb |
| Raise or lower a cap | caches.buildCacheMaxGb, caches.ccacheMaxGb, maintenance.workspaceOutputsMaxGb, maintenance.cargoTargetMaxGb |
Each is stim settings set <setting> <value> --scope machine, except
maintenance.keep:
- Global
- npx
stim settings set daemon.mode report --scope machine
npx stim settings set daemon.mode report --scope machine
git worktree lock keeps one worktree from removal.
maintenance.removeIdleWorktrees (off) also removes clean, pushed, unmerged
worktrees unused for 3 days. idle.minutes 0 turns the idle and dormant stages off. The rest is in
All settings.
Which checkouts it maintains
- Registered: a checkout where a project command ran, such as
worktree warm,start,iosorandroid. - Named folders: the recognised projects directly inside each
maintenance.managedFoldersfolder, and their linked worktrees inside it, under the same rules. A plain Node checkout there only has its finished linked worktrees removed. Stim 2.0.0 called this settingmaintenance.discoverRoots; a config that still uses that name keeps working. Changing the setting stores it under the new name, which an older Stim sharing the same Stim home does not read, so update every copy in that home. - Automatic discovery (
maintenance.autoDiscover, off): also the folders next to registered checkouts and the linked worktrees of every known repository. Thenode_modulesand Pods of every checkout only automatic discovery found stay while the checkout does, unlessmaintenance.cleanAutoDiscoveredDependenciesis also on.
A weekly scan of the home folder only reports, whatever maintenance.autoDiscover
says: being found by it, or sitting in another tool's folder such as
~/.codex/worktrees, never brings a checkout under the rules above. stim doctor lists the checkouts no rule
above reaches, with the command that adds their folder to
maintenance.managedFolders.
A discovered worktree is removed by the rules of a registered one, finished and
clean, and only when nothing runs from it and no agent session is in it.
That includes one another tool keeps inside the repository, such as
.claude/worktrees. Its git-ignored files go with it, as for any finished
worktree. Nothing is archived, and no git fetch
runs.
To exclude a checkout, run
stim settings set maintenance.keep true --scope committed in it, or drop its
folder from the list.
- Global
- npx
stim settings set maintenance.managedFolders '["~/Developer"]' --scope machine
stim gc --dry-run
npx stim settings set maintenance.managedFolders '["~/Developer"]' --scope machine
npx stim gc --dry-run
What commands delete
This page leaves out what a command does to its own target:
| Command or action | Where |
|---|---|
stim stop | Commands, web |
stim worktree remove | Remove a worktree |
stim gc and its flags | Commands |
| Reusing a parked device | What Stim deletes |
| A device hosted on another Mac | Hosted parking and restart |
stim-ci run | What a run deletes |
See what it did
stim logs --source gc lists what stim gc and the maintenance passes
removed; the pressure ladder logs to daemon.ndjson in the Stim home.
stim status shows
the level and each workspace's stage.
Explain cleanup on this machine
Read stim guide cleanup, then run stim gc --dry-run and stim worktree list --all. Explain what Stim would delete or stop on this machine and why. Do not run stim gc without asking me.