stack-clean-old: Clean away old stack build artefacts

[ bsd3, distribution, program ] [ Propose Tags ]

A tool for removing old .stack-work/install builds and .stack/snapshots & programs for older ghc versions to recover diskspace.

[Skip to Readme]


Maintainer's Corner

For package maintainers and hackage trustees


Versions [RSS] 0.1, 0.2, 0.2.1, 0.2.2, 0.3, 0.3.1, 0.4, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6
Change log
Dependencies base (>=4.8 && <5), directory (>=1.2.5), extra (>=1.4.3), filemanip, filepath, simple-cmd (>=0.1.4), simple-cmd-args (>=0.1.2) [details]
License BSD-3-Clause
Copyright 2020-2021 Jens Petersen <>
Author Jens Petersen <>
Maintainer Jens Petersen <>
Category Distribution
Home page
Bug tracker
Source repo head: git clone
Uploaded by JensPetersen at 2021-08-01T07:25:54Z
Distributions LTSHaskell:0.4.6, NixOS:0.4.6, Stackage:0.4.6
Executables stack-clean-old
Downloads 1256 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
Last success reported on 2021-08-01 [all 1 reports]

Readme for stack-clean-old-0.3.1

[back to package description]


A small tool to clean away older Haskell stack snapshot builds and ghc versions to recover diskspace.


stack-clean-old [size|list|remove|keep-minor|purge-older|delete-work] [(-p|--project) | (-g|--ghc)] [GHCVER]


  • --project (default in a stack project dir): act on .stack-work/install/
  • --global (default outside a project dir): act on ~/.stack/snapshots/ and ~/.stack/programs/

and the subcommands:

size: prints the total size of the above directories (size does not take a GHCVER argument).

list: shows the total size and number of snapshots per ghc version (the GHCVER argument is optional).

remove: removes for the specified ghc version (the GHCVER argument is required).

keep-minor: removes the builds/installs for previous minor ghc versions. If GHCVER is given then only minor versions older than it are removed.

purge-older and delete-work: see sections below

If you remove any needed snapshot builds for a version of ghc, then you would have to rebuild them again for any projects still using them, so removal should be used cautiously, but it can recover a lot of diskspace.

NBB: All the command support --dry-run (-n), so please use it to check the effect of running them safely beforehand.

Example usage

To remove project builds for ghc-8.2.2:

$ stack-clean-old list
154M  8.2.2  (5 dirs)
154M  8.4.4  (5 dirs)
163M  8.6.5  (5 dirs)
$ stack-clean-old remove -p 8.2.2

Remove stack ghc-8.4 snapshot builds and compilers before 8.4.4:

$ stack-clean-old list -g 8.4
421M  8.4.1  (7 dirs)
368M  8.4.2  (6 dirs)
489M  8.4.3  (8 dirs)
799M  8.4.4  (24 dirs)
$ stack-clean-old keep-minor -g 8.4.4
ghc-tinfo6-8.4.3 removed
7 dirs removed for 8.4.1
6 dirs removed for 8.4.2
8 dirs removed for 8.4.3

Incidently I build my projects across as many major Stackage LTS versions as possible (using my stack-all tool), and collectively this piles up to a lot of diskspace: so I wrote this tool to help manage that.

Purging older stack project builds

stack-clean-old purge-older

This command removes older stack builds from .stack-work/install/. By default it keeps 5 newest builds per ghc version.

The preservation/deletion is calculated and done per ghc version.

NB: If you regularly build your project for several branches/tags against the same LTS or ghc version then it is safer to avoid using purge-older.

Deleting all .stack-work/ subdirectories

stack-clean-old delete-work can be used to recursively remove all .stack-work/ dirs from a project to save space (seems same as stack clean --full).

stack-clean-old delete-work --all works from outside stack projects: please test with --dry-run first.


Run stack install or cabal install

This tool complements stack-all which builds projects over LTS major versions and hence generates lot of stack builds.


BSD license


Warning disclaimer

Use at your own risk: the author takes no responsibility for any loss or damaged caused by using this tool, as also mentioned in LICENSE.

Bug reports, suggestions, and improvements are welcome.