Clean up workspace caches

Workspace runs can leave managed cache entries behind. Preview the selection, narrow it when needed, and remove it after checking the paths.

3 sections13 steps

1. Preview the scope

Separate caches from run records

Cleanup removes managed workspace cache artifacts such as retained workspaces and cache state. Canonical records under .crewplane/execution-stages/ and .crewplane/execution-results/ remain.

Preview what goes. See what stays.

Try cleanup on these example entries. This preview does not access or remove your files.

crewplane cleanup workspaces --dry-run
Example cache entries Current repository
  • Completed run · 14 days oldVerified managed workspace
    Eligible after checks
  • Completed run · 2 days oldVerified managed workspace
    Eligible after checks
  • Running workspaceA run is still active
    Keep
  • Unverifiable workspaceSaved state cannot be confirmed
    Keep
Run records stay.crewplane/execution-stages/.crewplane/execution-results/
Unchanged

Preview the eligible completed workspaces, then confirm removal. Running or unverifiable entries stay.

Print the paths first

Run the dry run in the project whose caches you want to inspect. With no status flags, it selects workspaces from completed runs in the current Git repository, leaving running workspaces and workspaces whose state cannot be confirmed.

Terminal
crewplane cleanup workspaces --dry-run
Preview command; it does not remove the listed paths.

Remove the reviewed selection

After checking the dry-run output, use --yes to remove matching cache entries. Cleanup is non-destructive without --yes; if both --dry-run and --yes are present, the dry run takes precedence.

Terminal
crewplane cleanup workspaces --yes
Destructive command; run only after reviewing the preview.

Expand the scope deliberately

--all-projects selects every repository bucket under the configured workspace cache root. Preview this scope first: Crewplane cannot tell whether another project’s cached workspace is still in use. Adding --all-projects --yes confirms acceptance of that risk.

Terminal
crewplane cleanup workspaces --all-projects --dry-runcrewplane cleanup workspaces --all-projects --yes
Preview, then optionally remove caches across projects.

2. Choose entries

Narrow the selection

Choose a config file, a full run key, an age, or status filters. --successful, --failed, and --cancelled select the corresponding run statuses; --orphans selects cache folders with no saved workspace record.

Replace YOUR_FULL_RUN_KEY with the full run key from the stage directory before running the command.

Terminal
crewplane cleanup workspaces \  --config .crewplane/config.yml \  --dry-run \  --run 'YOUR_FULL_RUN_KEY' \  --older-than 7d \  --successful \  --failed \  --cancelled \  --orphans
Replace YOUR_FULL_RUN_KEY with the complete run key before running.

Select one run

Use the full run key from its stage directory. Review the first command’s output before using the second.

Replace YOUR_FULL_RUN_KEY with the full run key from the stage directory before running either command.

Terminal
crewplane cleanup workspaces --run 'YOUR_FULL_RUN_KEY' --dry-runcrewplane cleanup workspaces --run 'YOUR_FULL_RUN_KEY' --yes
Preview and then remove matching entries for one run. Replace YOUR_FULL_RUN_KEY with the complete run key before running.

Select by age

--older-than accepts integer seconds or durations with suffixes, such as 30s, 30m, 12h, and 7d. Preview before deleting.

Terminal
crewplane cleanup workspaces --older-than 7d --dry-runcrewplane cleanup workspaces --older-than 7d --yes
Preview and then remove matching older entries.

Understand orphan checks

A broken or conflicting record is not a missing record. Crewplane removes an orphan only if it can confirm the related run has ended and no provider process remains active. Otherwise it keeps the folder and explains why.

Understand workspace checks

A workspace can be reused and have multiple saved records. Before deletion, Crewplane checks that all records agree, the folder belongs to the expected repository, Git recognizes the worktree, and removal will not change a branch. If any check cannot be confirmed, it leaves the workspace in place.

3. Understand what remains

Keep the cache root separate

Cleanup rejects cache roots that are relative, symlinks, or overlap the project, .crewplane/, run artifact directories, or Git metadata paths.

Recognize managed entries

Cleanup scans the workspace-runs, workspaces, snapshots, and review-workspaces cache families. Destructive cleanup can also remove internal Git references created for the run.

Cache families and records

Cleanup targets managed caches and verified run-owned refs; canonical run artifacts remain.

Cache root workspace-runs, workspaces, snapshots, review-workspaces
Git references Run-owned refs removed only when verified
.crewplane/ Canonical lineage, outputs, findings, manifests and results stay

Check Git reference ownership

Crewplane removes an internal reference only if it can confirm ownership and that it still points to the exact recorded commit. Changed or unverifiable references remain. Related workspace-result references are removed together to avoid a partial result.

Handle run records separately

Workspace cleanup leaves canonical workspace lineage, provider outputs, findings, run manifests, and result artifacts under .crewplane/. Crewplane has no run-record prune command; delete or archive the stage and result directories for a run according to your project policy.

Run-record paths
.crewplane/execution-stages/<run-key>/.crewplane/execution-results/<run-key>/
Run-record locations; these are paths, not commands.