Skip to content

chore: add cache cleanup utility script for Kiro workspace storage#5755

Open
morozow wants to merge 2 commits intokirodotdev:mainfrom
worktif:feature/workspace-cache-cleanup-script
Open

chore: add cache cleanup utility script for Kiro workspace storage#5755
morozow wants to merge 2 commits intokirodotdev:mainfrom
worktif:feature/workspace-cache-cleanup-script

Conversation

@morozow
Copy link

@morozow morozow commented Feb 14, 2026

  • Add clean-kiro-cache.sh script to manage Kiro file cache and workspace data
  • Support selective deletion of chat files older than specified days
  • Support removal of entire workspaces older than specified days
  • Include comprehensive help documentation with usage examples
  • Implement safety features with confirmation prompts and size calculations
  • Add progress tracking during deletion operations
  • Support targeting specific user accounts via --user flag

Issue #, if available:

Description of changes:

Add maintenance script for cleaning Kiro workspace cache

Summary

Adds scripts/bin/clean-kiro-cache.sh - a maintenance utility for managing Kiro workspace storage and reclaiming disk space.

Problem

Kiro accumulates significant disk space over time:

  • File version snapshots for diff/restore operations
  • Chat conversation history (.chat files)
  • Workspace metadata and cache

Users currently have no built-in way to clean old data, leading to:

  • 30-40+ GB storage consumption in typical usage
  • No visibility into what's consuming space
  • Manual deletion risks breaking active sessions

Solution

Introduces a safe, user-friendly maintenance script with:

Features

1. clean-kiro-cache.sh - Storage Cleanup

Main utility for managing Kiro workspace storage with:

Features

  • Selective deletion: Target cache, chat history, or entire workspaces independently
  • Age-based filtering: Delete only data older than specified days
  • Multi-user support: Clean any user's Kiro data via --user flag
  • Safety first:
    • Dry-run analysis before deletion
    • Explicit confirmation prompts
    • Progress reporting during operations
    • Preserves critical data (index, config, active sessions)
  • Enterprise-grade documentation: Comprehensive --help with examples and safety guarantees

2. clean-kiro-ide-sessions.sh - IDE Session Cleanup

Companion utility that removes stale IDE session storage after chat cleanup:

  • Prevents IDE slowdowns: Removes session references to deleted chat files
  • Age-based cleanup: Matches retention period from main cleanup script
  • LevelDB-aware: Properly handles IDE's session storage format
  • Restart reminder: Prompts user to restart IDE after cleanup

Usage Examples

# Analyze current storage (no deletion)
./scripts/bin/clean-kiro-cache.sh

# Delete chat history older than 60 days
./scripts/bin/clean-kiro-cache.sh --chat-files-older-than 60

# Delete entire workspaces older than 90 days
./scripts/bin/clean-kiro-cache.sh --workspaces-older-than 90

# Clean another user's data
./scripts/bin/clean-kiro-cache.sh --user username --chat-files-older-than 30

Recommended Workflow for Optimal IDE Performance

After cleaning cache and old chat files, it's recommended to also clean IDE session storage and restart Kiro IDE to prevent performance degradation:

# 1. Clean cache and old chat files
./scripts/bin/clean-kiro-cache.sh --chat-files-older-than 60

# 2. Clean IDE session storage (prevents stale references)
./scripts/bin/clean-kiro-ide-sessions.sh --sessions-older-than 60

# 3. Restart Kiro IDE to apply changes

This ensures consistency between chat storage and IDE session state, eliminating slowdowns caused by orphaned session references.

Implementation Details

Location:

  • scripts/bin/clean-kiro-cache.sh - Main cache and chat cleanup utility
  • scripts/bin/clean-kiro-ide-sessions.sh - IDE session storage cleanup utility

What gets deleted:

  • File version cache (subdirectories with hash names)
  • .chat files older than specified threshold
  • Workspace directories older than specified threshold

What is preserved:

  • index/ directory (code search index)
  • Configuration files (config.json, profile.json)
  • Migration metadata (.migrations/)
  • Active workspace data (unless explicitly matched by age filter)

Safety mechanisms:

  1. Validates directory existence before proceeding
  2. Calculates and displays size impact before deletion
  3. Requires explicit y/N confirmation
  4. Shows real-time progress during deletion
  5. Reports final size after completion

Testing

Tested on macOS with:

  • ✓ Current user cleanup (default behavior)
  • ✓ Multi-user cleanup (--user flag)
  • ✓ Chat file deletion (--chat-files-older-than)
  • ✓ Workspace deletion (--workspaces-older-than)
  • ✓ Combined operations (multiple flags)
  • ✓ Help documentation (--help)
  • ✓ Error handling (invalid directory, cancelled operations)

Test results: Successfully reclaimed 7+ GB from file cache and 15+ GB from old chat history without affecting active sessions.

Documentation

Comprehensive --help output includes:

  • Synopsis and description
  • Detailed option explanations
  • Real-world usage examples
  • Clear explanation of deletion impact
  • Safety guarantees
  • Exit status codes

Breaking Changes

None. This is a new utility script with no impact on existing functionality.

Future Enhancements

Potential improvements for future PRs:

  • Automatic scheduling via cron/launchd
  • Configuration file for default retention policies
  • Integration with kiro-cli as a subcommand (kiro clean)
  • Metrics reporting (storage saved, files deleted)
  • Backup/restore functionality before deletion

Checklist

  • Script is executable (chmod +x)
  • Follows shell scripting best practices (shellcheck clean)
  • Comprehensive error handling
  • User confirmation before destructive operations
  • Enterprise-grade documentation
  • Tested on macOS
  • No dependencies beyond standard Unix utilities (du, find, rm)

Impact: Low risk, high value. Provides essential maintenance capability without modifying core Kiro functionality.

Recommendation: Merge and document in user-facing documentation (README, troubleshooting guide).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Add clean-kiro-cache.sh bash script for managing Kiro workspace storage
- Support selective deletion of file version cache, chat history, and old workspaces
- Include configurable age-based filtering via --chat-files-older-than and --workspaces-older-than flags
- Implement dry-run analysis mode showing cache size and file counts before deletion
- Add comprehensive help documentation with usage examples and safety information
- Require explicit user confirmation before any deletion operations
- Display progress indicators during bulk deletion operations
- Add clean-kiro-ide-sessions.sh script to remove stale session storage and workspace metadata
- Support --user flag to target specific user accounts
- Support --sessions-older-than flag to delete files by modification date threshold
- Include comprehensive help documentation with usage examples and safety information
- Calculate and display cleanup size before deletion with user confirmation prompt
- Prevent IDE performance degradation caused by stale session data referencing deleted chat files
- Coordinate with clean-kiro-cache.sh for consistent cache and session cleanup workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant