BSD-3-Clause licensed and maintained by Jens Petersen
This version can be pinned in stack with:stack-clean-old-0.5.1@sha256:7380de1c0b765f22881cd2ab399b9d1ab72cf3bfd0c72ab8eb09c771e6ed791a,2077

Module documentation for 0.5.1

There are no documented modules for this package.


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|--global)|(-C|--compilers)|(-T|--tarballs)] [(-s|--subdirs)|(-r|--recursive)] [-d|--delete] [GHCVER]`

In a project directory it acts on .stack-work/install/ by default, otherwise on ${STACK_ROOT}/{snapshots,programs}/ (the default Stack root is ~/.stack/): see the Stack root documentation.


size: prints the total size of .stack-work/ of project(s) or the Stack root. 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 older minor releases of ghc major versions. If GHCVER is given then only minor versions older than it (or than the latest installed minor version) are removed. If no GHCVER is given it applies to each installed ghc major version.

purge-older: removes snapshot builds with older timestamps

delete-work: removes .stack-work directories completely

dry-run mode is used by default and one should use --delete (-d) for actual deletion of files, after checking the dry-run output.

If you should remove any needed snapshot builds, then they will get rebuilt again by stack next time you build any projects needing them, so removals should be done carefully but can recover a lot of diskspace.

Further the commands can use --subdirs or --recursive to run over the projects in subdirs under the current directory or all matching .stack-work dirs from the current directory and below respectively.

If you have different ghc variants/archs installed you can use --platform to restrict to one of then, otherwise they are each listed by default.

Example usage

List a project’s builds:

$ stack-clean-old list
149M  9.2.8  (5 dirs)
163M  9.4.7  (5 dirs)
155M  9.6.2  (5 dirs)

Remove project’s 9.0.2 builds:

$ stack-clean-old remove --delete --project 9.0.2

(–project is optional in a project dir).

Remove stack ghc-9.4 snapshot builds and minor compilers before 9.4.7:

$ stack-clean-old list --global 9.4
1.8G  9.4.6  (61 dirs)
279M  9.4.7  (6 dirs)
$ stack-clean-old keep-minor --global 9.4
ghc-tinfo6-9.4.6 compiler would be removed
61 dirs in ~/.stack/snapshots/x86_64-linux-tinfo6/*/9.4.6 would be removed

(use --delete (-d) for removal)
$ stack-clean-old keep-minor --global 9.4 -d
ghc-tinfo6-9.4.6 compiler removed
61 dirs in ~/.stack/snapshots/x86_64-linux-tinfo6/*/9.4.6 removed

(–global is optional outside a project dir).

If you have different latest minor versions for compilers and snapshots you may prefer to specify the latest minor version to keep to get more certain behaviour.

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 --recursive can be used to remove recursively all .stack-work/ dirs within (or outside) a project directory to save space (seems same as stack clean --full inside a project).

Help output

(Note you can also run this tool via stack clean-old.)

To get help you can run stack-clean-old --help or just: $ stack-clean-old --version


$ stack-clean-old --help

Stack clean up tool

Usage: stack-clean-old [--version] COMMAND

  Cleans away old stack-work builds (and pending: stack snapshots) to recover
  diskspace. Use the --delete option to perform actual removals.

Available options:
  -h,--help                Show this help text
  --version                Show version

Available commands:
  size                     Total size
  list                     List sizes per ghc version
  remove                   Remove for a ghc version
  keep-minor               Remove for previous ghc minor versions
  purge-older              Purge older builds in .stack-work/install
  delete-work              Remove project's .stack-work/ (optionally

Command options

Most of the commands have similar options, e.g.:

$ stack-clean-old remove --help

Usage: stack-clean-old remove [(-d|--delete) [-y|--yes]] 
                              [(-P|--project) | (-S|--snapshots) | 
                                (-C|--compilers) | (-T|--tarballs) | 
                              [(-s|--subdirs) | (-r|--recursive)] GHCVER 
                              [-o|--platform SYSTEM]

  Remove for a ghc version

Available options:
  -d,--delete              Do deletion [default is dryrun]
  -y,--yes                 Assume yes for all prompts
  -P,--project             Act on current project's .stack-work/ [default in
                           project dir]
  -S,--snapshots           Act on ~/.stack/snapshots/
  -C,--compilers           Act on ~/.stack/programs/ installations
  -T,--tarballs            Act on ~/.stack/programs/ tarballs
  -G,--global              Act on both ~/.stack/{programs,snapshots}/ [default
                           outside project dir]
  -s,--subdirs             List subdirectories
  -r,--recursive           List subdirectories
  -o,--platform SYSTEM     Specify which OS platform to work on (eg
                           'x86_64-linux-tinfo6', 'aarch64-linux-nix',
                           'x86_64-osx', 'aarch64-osx', etc)
  -h,--help                Show this help text

(The list and size commands don’t have --delete and --yes.)


Run stack install or cabal install


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

cabal-clean is a similar tool for cleaning old cached cabal build files.


BSD license



Use at your own risk: the author takes no responsibility for any loss or damaged caused by using this tool.

Bug reports, suggestions, and improvements are welcome.


Release history for stack-clean-old

0.5.1 (2023-12-17)

  • listStackSubdirs: sort after filtering
  • Directory: ignore non-directories, like .DS_Store files (#19, thanks to @0rphee for reporting #18)

0.5 (2023-09-13)

  • simpler dry run output and use simple-prompt yesNo
  • add –yes option for –delete
  • keep-minor: fix ghc minor version checks with major version

0.4.8 (2023-08-26)

  • support the STACK_ROOT environment variable which overrides the default Stack root (~/.stack) by @PRESFIL (#12)
  • list all the platform variants by default (#15)

0.4.7 (2023-08-22)

  • add –tarballs for programs/ ghc tarballs too (#9)
  • bug fix to match both ghc-. and ghc-variant-. (#14)
  • rename –os-system to –platform and add more explanation (#15)
  • parse ghc installation versions more carefully
  • ignore hidden files in stack dirs

0.4.6 (2022-02-03)

  • fix –recursive and –subdirs to work again
  • show –recursive dir paths
  • ignore non-ghc dirs in ~/.stack/programs/

0.4.5 (2022-01-14)

  • fix multiple reminders about using –delete

0.4.4 (2022-01-04)

  • handle .stack-work/ consistently for –subdir and –recursive
  • remind user to use ‘–delete’ for removal
  • purge-older: output is now sorted by ghc versions

0.4.3 (2021-11-23)

  • ‘delete-work’ now prints “.stack-work” would be deleted
  • prompts now print what would be deleted
  • ‘–recursive’ now prints dirs with ‘/’ appended

0.4.2 (2021-11-22)

  • add optional –os-system to fix #7
  • list/size snapshots before compilers for –global

0.4.1 (2021-10-05)

  • –help now mentions –delete and a link to README

0.4 (2021-09-26)

  • dryrun is now default: use –delete for actual removal (suggested by @andreasabel #6)
  • new –subdirs and –recursive options
  • various output improvements
  • purge-older now also says “would be removed” when dryrun

0.3.1 (2021-08-01)

  • ‘delete-work’: use find -prune and ignore inaccessible files (@petrem, #4)

0.3 (2021-01-08)

  • drop subsubcommands to simplify UI
  • default to project if there is a .stack-work/ dir, otherwise global ~/.stack
  • rename commands:
    • remove-version -> remove
    • remove-earlier-minor -> keep-minor
    • remove-older -> purge-older
    • remove-work -> delete-work
  • fix handling of partially installed ghc compiler temp dirs (#2)
  • rename –dryrun to –dry-run (#1)
  • drop –dir option
  • delete-work: use –all to run from a non-project dir

0.2.2 (2002-12-31)

  • add ‘project remove-work’ to recursively remove .stack-work from projects

0.2.1 (2020-11-14)

  • remove-earlier-minor can now take a major version
  • major internal refactors with VersionSnapshots type
  • split code into modules

0.2 (2020-10-26)

  • add –dryrun to all remove commands
  • remove-earlier-minor subcommands to purge for previous ghc minor versions
  • allow major ghc X.Y versions (prompts for removal)
  • ‘ghc list’ is now sorted

0.1 (2020-09-22)

  • initial release with project and snapshots subcommands