A guide to the CacheKill CLI tool for safely managing development and build caches.
- Overview
- Installation
- Architecture
- Core Concepts
- CLI Reference
- Configuration
- Cache Detection
- Safety Features
- Testing Guide
- Development
- Troubleshooting
- API Reference
CacheKill is a CLI tool designed to safely clean up development and build caches across multiple languages and frameworks. It provides intelligent cache detection, safe deletion with backup functionality, and detailed insights into cache usage.
- Multi-language Support: JavaScript, Python, Rust, Java, Machine Learning
- Smart Detection: Automatic project type detection and relevant cache identification
- Safe Operations: Timestamped backups with restore capability
- Flexible Output: Human-readable tables and machine-readable JSON
- Cross-platform: macOS, Linux, Windows support
- Configurable: TOML configuration file support
- Advanced NPX Analysis: Per-package visibility with detailed breakdown
- Enhanced Edge Purging: Improved API integration for Vercel and Cloudflare
- Integration: Docker and NPX cache management
# Clone the repository
git clone https://github.com/kagehq/cachekill.git
cd cachekill
# Build in release mode
cargo build --release
# The binary will be available at ./target/release/cachekill# Install from crates.io (when published)
cargo install cachekill
# Install from local source
cargo install --path .# Download pre-built binaries (when available)
# Check releases page for your platform- CLI Parsing: Arguments parsed and validated
- Configuration: Load
.cachekillrcand merge with CLI args - Discovery: Detect project type and find cache candidates
- Inspection: Analyze cache sizes, modification times, staleness
- Planning: Determine actions (delete, backup, skip)
- Execution: Perform operations with safety checks
- Output: Format and display results
A CacheEntry represents a discovered cache with metadata:
pub struct CacheEntry {
pub path: PathBuf, // Path to cache
pub kind: CacheKind, // Type of cache
pub size_bytes: u64, // Size in bytes
pub last_used: DateTime<Utc>, // Last modification time
pub stale: bool, // Whether cache is stale
pub planned_action: Option<PlannedAction>, // What to do with it
}- JavaScript:
node_modules/,.next/,.vite/, etc. - Python:
__pycache__/,.pytest_cache/,.venv/, etc. - Rust:
target/,.cargo/ - Java:
.gradle/,build/,~/.m2/repository - Machine Learning:
~/.cache/huggingface,~/.cache/torch - NPX:
~/.npm/_npx - Docker: Images, containers, volumes, build cache
- Generic:
tmp/,temp/,.cache/
- JavaScript: Detected by
package.json - Python: Detected by
requirements.txt,pyproject.toml - Rust: Detected by
Cargo.toml - Java: Detected by
build.gradle,pom.xml - Machine Learning: Detected by ML-specific files
- Mixed: Multiple project types detected
- Unknown: No clear project type
| Option | Short | Description | Default |
|---|---|---|---|
--list |
List cache entries with details | ||
--dry-run |
Show what would be cleaned | ||
--force |
-f |
Proceed without confirmation | |
--yes |
-y |
Alias for --force | |
--json |
Output in JSON format | ||
--lang <LANG> |
Language filter | auto |
|
--paths <PATTERNS> |
Include patterns (glob) | ||
--exclude <PATTERNS> |
Exclude patterns (glob) | ||
--stale-days <DAYS> |
Stale threshold in days | 14 |
|
--safe-delete <BOOL> |
Enable safe delete | true |
|
--backup-dir <PATH> |
Backup directory | .cachekill-backup |
|
--docker |
Include Docker cleanup | ||
--npx |
Include NPX cache cleanup and per-package analysis | ||
--restore-last |
Restore from last backup | ||
--all |
Clean all common caches | ||
--help |
-h |
Show help | |
--version |
-V |
Show version |
auto: Auto-detect project typejs: JavaScript/TypeScript onlypy: Python onlyrust: Rust onlyjava: Java/Kotlin onlyml: Machine Learning only
# Basic usage
./target/release/cachekill
# List all caches
./target/release/cachekill --list
# Dry run with specific language
./target/release/cachekill --lang js --dry-run
# Include Docker and NPX
./target/release/cachekill --docker --npx --dry-run
# Advanced NPX analysis with per-package details
./target/release/cachekill --npx --list
# NPX analysis with JSON output for automation
./target/release/cachekill --npx --list --json
# NPX cache management
./target/release/cachekill --npx --dry-run # Preview what would be cleaned
./target/release/cachekill --npx --force # Nuclear option - clear all NPX caches
./target/release/cachekill --npx --stale-days 7 --force # Surgical - only stale packages
# Custom paths and exclusions
./target/release/cachekill --paths "**/custom-cache" --exclude "**/test" --dry-run
# JSON output for scripting
./target/release/cachekill --list --json | jq .
# Force mode without confirmation
./target/release/cachekill --force
# Restore from backup
./target/release/cachekill --restore-lastCreate a .cachekillrc file in your project root:
# Default language filter
default_lang = "auto"
# Stale threshold in days
stale_days = 14
# Enable safe delete by default
safe_delete = true
# Backup directory (relative to project root)
backup_dir = ".cachekill-backup"
# Additional include patterns
include_paths = [
"**/custom-cache",
"**/build-artifacts"
]
# Exclude patterns
exclude_paths = [
".git",
".cachekill-backup",
"node_modules/.cache",
"**/test-results",
"**/coverage"
]
# Include Docker cleanup by default
include_docker = false
# Include NPX cache cleanup by default
include_npx = false- CLI arguments (highest priority)
- Configuration file (
.cachekillrc) - Default values (lowest priority)
CACHEKILL_CONFIG: Path to configuration fileCACHEKILL_BACKUP_DIR: Default backup directoryCACHEKILL_STALE_DAYS: Default stale threshold
-
Project Type Detection:
- Scan for project files (
package.json,Cargo.toml, etc.) - Determine primary project type
- Handle mixed projects
- Scan for project files (
-
Cache Discovery:
- Use project type to determine relevant cache patterns
- Scan for common cache directories
- Apply include/exclude patterns
-
Cache Analysis:
- Calculate directory sizes
- Determine last modification time
- Check staleness based on threshold
node_modules/.next/,.nuxt/.vite/,.cache/dist/,coverage/.turbo/,.parcel-cache/build/,out/
__pycache__/.pytest_cache/.venv/,venv/.tox/,.mypy_cache/.ruff_cache/,.pip-cache/.coverage/
target/.cargo/target/debug/,target/release/
.gradle/build/~/.m2/repositorytarget/(Maven)
~/.cache/huggingface~/.cache/torch.dvc/cache~/.cache/transformers
tmp/,temp/.cache/build/,dist/
~/.npm/_npx- Platform-specific NPX cache locations
- Images, containers, volumes, build cache
- Managed via
docker system prune
CacheKill provides comprehensive per-package analysis for NPX caches, offering detailed insights into package usage and optimization opportunities.
The --npx --list command provides detailed analysis of NPX cached packages:
# Analyze NPX packages with detailed breakdown
./target/release/cachekill --npx --list
# JSON output for automation
./target/release/cachekill --npx --list --json- Name: Package name extracted from
package.json - Version: Package version (when available)
- Size: Disk usage in human-readable format
- Last Used: Modification timestamp
- Stale Status: Based on configurable threshold (default: 14 days)
📦 NPX Package Cache Analysis
Found 791 cached packages:
Package | Version | Size | Last Used | Stale?
------------------------------ | --------------- | ------------ | --------------- | --------
prisma | unknown | 85.59 MB | 2025-02-03 00:13 | Yes
@nestjs/cli | unknown | 60.86 MB | 2025-08-02 13:43 | Yes
typescript | 5.9.2 | 23.62 MB | 2025-09-12 20:19 | No
- Total packages: Count of cached packages
- Total size: Combined disk usage
- Stale packages: Count of packages exceeding stale threshold
- Size optimization: Identify largest packages for cleanup
NPX caches are stored in platform-specific locations:
- macOS/Linux:
~/.npm/_npx/ - Windows:
%APPDATA%\npm-cache\_npx\
Each package is stored in a hash-named directory containing:
package.json: Package metadatanode_modules/: Package dependenciespackage-lock.json: Lock file (when available)
Packages are marked as stale based on:
- Last modification time: When the package was last accessed
- Configurable threshold: Default 14 days, configurable via
--stale-days - Size consideration: Large packages may have different thresholds
For automation and scripting, use --json flag:
[
{
"name": "prisma",
"version": null,
"size_bytes": 89738240,
"last_used": "2025-02-03T00:13:00Z",
"path": "/Users/user/.npm/_npx/1d6e82a4126006c4",
"stale": true
}
]CacheKill provides powerful NPX cache management capabilities:
# Preview what would be cleaned (recommended first step)
./target/release/cachekill --npx --dry-run# Clear all NPX caches (backup to timestamped directory)
./target/release/cachekill --npx --force# Only clean packages not used in last 7 days
./target/release/cachekill --npx --stale-days 7 --force
# Only clean packages not used in last 30 days
./target/release/cachekill --npx --stale-days 30 --force# Generate comprehensive report for engineering teams
./target/release/cachekill --npx --list --json > team-cache-report.json
# Human-readable summary
./target/release/cachekill --npx --listBased on analysis results:
- Remove stale packages: Clean packages not used recently
- Size optimization: Focus on largest packages first
- Version management: Remove duplicate versions of same package
- Regular cleanup: Schedule periodic NPX cache maintenance
When --safe-delete is enabled (default):
- Backup Creation: Move caches to timestamped backup directory
- Backup Structure:
{backup_dir}/{timestamp}/ - Restore Capability: Use
--restore-lastto restore from backup - Backup Cleanup: Old backups can be automatically cleaned
- Threshold: Configurable via
--stale-days(default: 14) - Calculation: Based on last modification time
- Purpose: Avoid deleting recently used caches
- Override: Use
--forceto ignore staleness
- Symlink Protection: Don't follow symlinks outside project
- Path Validation: Ensure operations stay within project bounds
- Permission Checks: Verify write permissions before operations
# Backup directory structure
.cachekill-backup/
├── 2024-01-15_14-30-25/
│ ├── node_modules/
│ └── target/
├── 2024-01-16_09-15-10/
│ └── .next/
└── metadata.json# Run all tests
cargo test
# Run specific test module
cargo test cache_entry
# Run tests with output
cargo test -- --nocapture# Test basic functionality
./target/release/cachekill --help
./target/release/cachekill --version
./target/release/cachekill --list
# Test dry run
./target/release/cachekill --dry-run
# Test JSON output
./target/release/cachekill --list --json | jq .
# Test language filters
./target/release/cachekill --lang js --dry-run
./target/release/cachekill --lang rust --dry-run# Test large directory scanning
./target/release/cachekill --all --dry-run
# Test memory usage
time ./target/release/cachekill --list
# Test JSON performance
./target/release/cachekill --list --json > /dev/null# Test invalid flags
./target/release/cachekill --invalid-flag
# Test invalid language
./target/release/cachekill --lang invalid --dry-run
# Test invalid paths
./target/release/cachekill --paths "invalid[pattern" --dry-run# Clone and build
git clone https://github.com/kagehq/cachekill.git
cd cachekill
cargo build --release# Build
make build
# or
cargo build --release
# Test
make test
# or
cargo test
# Format
make fmt
# or
cargo fmt
# Lint
make clippy
# or
cargo clippy -- -D warnings
# Run
make run
# or
./target/release/cachekill --help- CLI argument parsing
- Command dispatch
- Error handling
- Exit codes
CacheEntrystructCacheKindenumLanguageFilterenumPlannedActionenum
Configstruct (file-based)CliArgsstruct (CLI arguments)MergedConfigstruct (merged configuration)
ProjectTypeenumDiscoveryResultstruct- Project type detection
- Cache candidate discovery
CacheInspectorstruct- Size calculation
- Staleness detection
- Cache analysis
ActionExecutorstruct- Dry run simulation
- Safe delete operations
- Backup management
- Restore functionality
OutputFormatterstruct- Table formatting
- JSON serialization
- Summary generation
NpxCacheManagerstruct- NPX cache detection
- NPX cache operations
DockerCacheManagerstruct- Docker system analysis
- Docker cleanup operations
- Path utilities
- File system operations
- Time handling
- Backup management
-
New Cache Type:
- Add to
CacheKindenum - Update detection patterns
- Add to project type mapping
- Add to
-
New Project Type:
- Add to
ProjectTypeenum - Update detection logic
- Add cache kind mapping
- Add to
-
New CLI Option:
- Add to
Clistruct - Update
CliArgsstruct - Update
MergedConfigstruct - Update help text
- Add to
# Add unit tests
# Add integration tests
# Update documentation
# Test cross-platform compatibility- Cause: No caches detected in current directory
- Solution:
- Check if you're in the right directory
- Try
--allto include generic caches - Use
--listto see what's detected - Check include/exclude patterns
- Cause: Insufficient permissions for file operations
- Solution:
- Run with appropriate permissions
- Check file ownership
- Use
--forceto skip interactive prompts
- Cause: Docker CLI not found or not running
- Solution:
- Install Docker CLI
- Check if Docker is running
- Use
--dockeronly when needed
- Cause: Invalid
.cachekillrcfile - Solution:
- Check TOML syntax
- Validate configuration values
- Use
--helpto see valid options
# Enable debug output
RUST_LOG=debug ./target/release/cachekill --list
# Verbose output
./target/release/cachekill --list --json | jq .CacheKill doesn't create log files by default. For debugging:
# Redirect output to file
./target/release/cachekill --list > cachekill.log 2>&1
# Use system logging
./target/release/cachekill --list 2>&1 | tee cachekill.log0: Success2: Partial success (some operations failed)3: Nothing to do4: Configuration error5: Fatal error
{
"mode": "list|dry-run|delete|restore",
"entries": [
{
"path": "string",
"kind": "js|py|rust|java|ml|npx|docker|generic",
"size_bytes": "number",
"last_used": "ISO8601 datetime",
"stale": "boolean",
"planned_action": "delete|backup|skip"
}
],
"totals": {
"size_bytes": "number",
"count": "number",
"freed_bytes": "number"
}
}# .cachekillrc
default_lang = "auto|js|py|rust|java|ml"
stale_days = "number"
safe_delete = "boolean"
backup_dir = "string"
include_paths = ["string"]
exclude_paths = ["string"]
include_docker = "boolean"
include_npx = "boolean"CACHEKILL_CONFIG: Path to configuration fileCACHEKILL_BACKUP_DIR: Default backup directoryCACHEKILL_STALE_DAYS: Default stale thresholdRUST_LOG: Log level for debugging
- Memory Usage: ~10-50MB depending on cache size
- Scan Speed: ~100-1000 directories/second
- JSON Output: ~1-10MB for large projects
- Backup Size: Same as original cache size
- Symlinks: Limited support for complex symlink structures
- Permissions: Requires appropriate file system permissions
- Large Files: May be slow with very large cache directories
- Network: No support for remote cache management
- Remote Caches: Support for cloud-based caches
- Cache Analysis: Detailed cache usage analytics
For more information, see the README.md for quick start instructions.