Skip to main content

deno clean

Remove the Deno cache directory to free up disk space or force re-downloading of dependencies.

Basic usage

deno clean
This command removes the entire Deno cache directory, including:
  • Downloaded remote modules
  • Compiled TypeScript files
  • npm packages
  • Generated source maps

Syntax

deno clean [OPTIONS]

Options

--except <PATHS>
string[]
Clean the cache except for dependencies used by the specified entry points. This allows you to remove unused cached files while keeping dependencies for specific projects.
--dry-run
boolean
default:"false"
Show what would be removed without actually deleting files.

Examples

Clean entire cache

deno clean
This removes all cached files and frees up disk space.

Dry run

deno clean --dry-run
See what would be removed without actually deleting anything:
would remove:
 /Users/username/Library/Caches/deno/deps
 /Users/username/Library/Caches/deno/gen
 /Users/username/Library/Caches/deno/npm

Clean except specific dependencies

deno clean --except main.ts
This removes all cached files except those used by main.ts and its dependencies.
deno clean --except server.ts worker.ts
Preserve dependencies for multiple entry points.

What gets removed

The deno clean command removes:
Downloaded files from https:// and http:// imports.Location: $DENO_DIR/deps/
Transpiled TypeScript files and source maps.Location: $DENO_DIR/gen/
Downloaded npm packages and their metadata.Location: $DENO_DIR/npm/
When using --except, unused packages from node_modules/.deno/ are also removed.

Cache location

The Deno cache directory location varies by operating system:
OSDefault Location
Linux/Unix$HOME/.cache/deno
macOS$HOME/Library/Caches/deno
Windows%LOCALAPPDATA%\deno
You can override this with the DENO_DIR environment variable:
export DENO_DIR=/custom/cache/path
deno clean

Use cases

Free disk space

Remove all cached files to reclaim storage

Fix cache corruption

Clear corrupted cache to force fresh downloads

Test fresh installs

Verify dependency resolution works correctly

Remove old dependencies

Clean up unused dependencies from old projects

Selective cleaning with —except

The --except flag is useful for maintaining a clean cache while preserving dependencies for active projects:
# Clean everything except dependencies for your main project
deno clean --except src/main.ts

# Preserve dependencies for multiple projects
deno clean --except project1/mod.ts project2/mod.ts

# Preview what would be removed
deno clean --except main.ts --dry-run
This command:
  1. Analyzes the module graph for specified entry points
  2. Identifies all required dependencies
  3. Removes cached files not used by those dependencies
  4. Also cleans up unused npm packages and node_modules symlinks

After cleaning

After running deno clean, the next time you run a Deno command:
  • Remote modules will be re-downloaded
  • TypeScript files will be re-compiled
  • npm packages will be re-installed
This may take longer than usual as the cache is repopulated.

Best practices

  • Cleaning the cache does not affect your source code
  • Lock files (deno.lock) are not removed
  • Use --dry-run first to preview changes
  • The --except flag requires analyzing the module graph, which may take time for large projects

See also

  • deno cache - Pre-download and cache dependencies
  • deno info - View cache location and dependency tree

Build docs developers (and LLMs) love