Skip to main content
The moon clean command will clean the current workspace by deleting stale cache. For the most part, the action pipeline will clean automatically, but this command can be used to reset the workspace entirely.
$ moon clean
Output:
✓ Deleted 42 files older than 7 days and saved 156384 bytes

Options

--lifetime <duration>

The maximum lifetime of cached artifacts before being marked as stale. Defaults to 7 days. The duration format supports:
  • Seconds: 30s, 60 seconds
  • Minutes: 15m, 30 minutes
  • Hours: 2h, 12 hours
  • Days: 7d, 30 days
  • Weeks: 2w, 4 weeks
  • Months: 1mo, 3 months
# Delete cache older than 24 hours
$ moon clean --lifetime '24 hours'

# Delete cache older than 30 days
$ moon clean --lifetime '30 days'

# Delete cache older than 2 weeks
$ moon clean --lifetime '2 weeks'

--all

Clean all cached items and reset state, regardless of age. This is equivalent to --reset.
$ moon clean --all
Output:
✓ Deleted 156 files and saved 2483968 bytes
This will delete:
  • All cached task outputs
  • All hash manifests
  • All temporary files
  • State files (.moon/cache/states)

What Gets Cleaned

The clean command removes:

Cached Outputs

Task outputs stored in .moon/cache/outputs/ including:
  • Build artifacts
  • Test results
  • Generated files

Hash Manifests

Hash manifests in .moon/cache/hashes/ that track input changes:
  • Task input hashes
  • Dependency hashes

State Files

Workspace state files in .moon/cache/states/ including:
  • Action graph states
  • Run history
  • Hydration states

Cache Behavior

Moon’s cache is content-addressable and automatically invalidates when:
  • Source files change
  • Dependencies are updated
  • Configuration changes
  • Environment variables change
The clean command is useful for:
  • Freeing disk space
  • Debugging cache issues
  • Starting fresh after major changes
  • CI/CD cleanup tasks

Examples

Clean old cache

# Use default 7 day lifetime
$ moon clean

Clean cache older than custom duration

# Clean cache older than 1 day
$ moon clean --lifetime '1 day'

# Clean cache older than 4 hours
$ moon clean --lifetime '4h'

Reset all cache

# Delete everything
$ moon clean --all

# Or use the alias
$ moon clean --reset

Automation

You can automate cache cleaning in CI/CD:
# GitHub Actions example
- name: Clean old cache
  run: moon clean --lifetime '1 day'

# Or use a cron job
- name: Weekly cleanup
  run: moon clean --lifetime '7 days'
  schedule:
    - cron: '0 0 * * 0'

Performance

The clean command:
  • Runs quickly (typically < 1 second)
  • Only scans cache directories
  • Uses file timestamps for age determination
  • Reports bytes saved after completion

See Also

  • moon ci - Optimized CI workflow that includes cache management
  • Caching - Learn more about moon’s caching system

Build docs developers (and LLMs) love