#cargo #cache #remove #manage #clean

app cargo-trim

Binary application to cleanup $CARGO_HOME cache

16 unstable releases (5 breaking)

✓ Uses Rust 2018 edition

0.6.1 May 14, 2020
0.5.3 Feb 14, 2020
0.5.0 Dec 22, 2019
0.4.2 Sep 28, 2019
0.1.1 Mar 17, 2019

#50 in Command line utilities

Download history 30/week @ 2020-03-16 45/week @ 2020-03-23 9/week @ 2020-03-30 45/week @ 2020-04-06 68/week @ 2020-04-13 8/week @ 2020-04-20 7/week @ 2020-04-27 4/week @ 2020-05-04 31/week @ 2020-05-11 12/week @ 2020-05-18 22/week @ 2020-05-25 53/week @ 2020-06-01 5/week @ 2020-06-08 21/week @ 2020-06-15 5/week @ 2020-06-22 19/week @ 2020-06-29

135 downloads per month

MIT and MPL-2.0 licenses

2.5K SLoC


Project status & info:

Travis Build Status License Crates Version
Travis Build Status License: MIT Crate

Rust & OS support:

Stable Beta Nightly Linux OSX Windows
Stable support Beta support Nightly support Linux support OSX support Windows support

Binary application for cleaning $CARGO_HOME/registry & $CARGO_HOME/git folder support orphan and old crates cleaning Default $CARGO_HOME is set as $HOME/.cargo


For installation of cargo-trim:- You can install from crates.io registry

    cargo install cargo-trim


For bleeding edge latest development version:

    cargo install --git https://github.com/iamsauravsharma/cargo-trim

By default cargo-trim print out colored output if you want to use a non colored output you can enable out no-color feature

    cargo install cargo-trim --features no-color


Initially you need to setup cargo-trim for some of commands such as orphan clean to work properly. To setup cargo-trim to properly work for all projects related to rust lang go to directory where all projects lies and run cargo trim init. You can even run this command multiple time to add multiple directory. or simple run command cargo trim -s <directory-path>. All projects inside directory will be used for listing orphan crates. So if there is any projects in other directory then their dependencies will be classified as orphan crates. If not used by any other crates.

Command output

All cargo-trim can be run using cargo trim <command> cargo trim --help will produce out following output which list out all of available command for cargo-trim

cargo-trim 0.6.1
Saurav Sharma <appdroiddeveloper@gmail.com>
Binary application to cleanup $CARGO_HOME cache

    cargo trim [FLAGS] [OPTIONS] [SUBCOMMAND]

    -a, --all                 Clean up all .cargo/registry & .cargo/git follow config file data
    -c, --clear               Clear config file data
    -n, --dry-run             Run command in dry run mode to see what would be removed
    -f, --force               Force clear cache without reading conf file
    -h, --help                Prints help information
    -l, --light               Light cleanup repos by removing git checkout and registry source but stores git db and
                              registry archive for future compilation without internet requirement
    -o, --old-clean           Clean old cache crates
    -z, --old-orphan-clean    Clean crates which is both old and orphan
    -x, --orphan-clean        Clean orphan cache crates i.e all crates which are not present in lock file generated till
                              now use cargo trim -u to guarantee your all project generate lock file
    -q, --query               Return size of different .cargo/cache folders
    -u, --update              Generate and Update Cargo.lock file present inside config directory folder path
    -V, --version             Prints version information

    -e, --exclude <crate>...          Add listed crates to default conf file exclude list [use TRIM_EXCLUDE environment
                                      variable for creating exclude list without editing conf file]
    -g, --gc <git compress>           Git compress to reduce size of .cargo [possible values: all, index, git, git-
                                      checkout, git-db]
    -i, --include <crate>...          Add listed crates to default conf file include list [use TRIM_INCLUDE environment
                                      variable for creating include list without editing conf file]
    -r, --remove <crate>...           Remove provided crates from registry or git
    -d, --directory <directory>...    Set directory of Rust project [use TRIM_DIRECTORY environment variable for
                                      creating directory list without editing conf file]
    -t, --top <number>                Show certain number of top crates which have highest size
    -w, --wipe <folder>               Wipe folder [possible values: git, checkouts, db, registry, cache, index, src]

    clear       Clear current working directory from cargo cache config
    config      Query config file data
    git         Perform operation only to git related cache file
    help        Prints this message or the help of the given subcommand(s)
    init        Initialize current working directory as cargo trim directory
    list        List out crates
    registry    Perform operation only to registry related cache file
    remove      Remove values from config file

Config file location

cargo-trim store its config file to config directory of OS and name config file as cargo_trim_config.json. In file cargo-trim stores out information about directory of rust projects and exclude and include crates list for cargo trim.


~57K SLoC