Skip to content

Intelligent autonomous context cleanup system for Claude Code - Automatically manages prompt size through smart cleanup and memory migration

License

MarcoFPO/claude-code-context-cleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

72 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Claude Code - Intelligent Context Cleanup System

Autonomous context management for Claude Code through intelligent cleanup and memory migration

License: MIT Status: Beta Version: 0.2.0

๐ŸŽฏ Overview

An intelligent system that enables Claude Code to autonomously manage its context window by:

  • ๐Ÿ“Š Monitoring prompt fill level continuously
  • ๐Ÿงน Cleaning up irrelevant information automatically
  • ๐Ÿง  Migrating important knowledge to persistent memory
  • ๐Ÿš€ Optimizing performance without user intervention

Problem: As conversations grow, Claude Code's context fills up, leading to slower performance and eventually hitting token limits.

Solution: Claude autonomously detects when cleanup is needed and intelligently removes old, irrelevant information while preserving important knowledge in the MCP Memory Server.


๐ŸŒ Multi-Language Support

Available in 7 languages! See the Documentation Center for:

Language Links
๐Ÿ‡ฌ๐Ÿ‡ง English README | Installation | Contributing
๐Ÿ‡ฉ๐Ÿ‡ช Deutsch README | Installation | Beitragen
๐Ÿ‡ช๐Ÿ‡ธ Espaรฑol README | Instalaciรณn | Contribuir
๐Ÿ‡ซ๐Ÿ‡ท Franรงais README | Installation | Contribuer
๐Ÿ‡จ๐Ÿ‡ณ ไธญๆ–‡ README | ๅฎ‰่ฃ… | ่ดก็Œฎ
๐Ÿ‡ฎ๐Ÿ‡น Italiano README | Installazione | Contribuire
๐Ÿ‡ท๐Ÿ‡บ ะ ัƒััะบะธะน README | ะฃัั‚ะฐะฝะพะฒะบะฐ | ะฃั‡ะฐัั‚ะธะต

โœจ Key Features

๐Ÿค– Autonomous Operation

  • Self-monitoring: Claude checks context usage automatically
  • Proactive cleanup: Acts before reaching limits
  • Auto-approval: Executes cleanup without user intervention when safe
  • Transparent: Always explains what's being done

๐ŸŽฏ Intelligent Cleanup

  • Relevance scoring: ML-based analysis of message importance
  • Reference tracking: Preserves cross-referenced information
  • Tool-specific rules: Different strategies for Read, Bash, Grep, etc.
  • Context-aware: Understands current task and preserves related info

๐Ÿง  Memory Integration

  • Automatic migration: Important old info moved to MCP Memory Server
  • Entity extraction: Converts context to structured knowledge graph
  • Retrieval support: Can query memory when needed
  • Dual scope: Project-local and user-global memory

๐Ÿ›ก๏ธ Safety First

  • Never removes: Last 3 turns, errors, system prompts, recent edits
  • Rollback support: Can undo any cleanup operation
  • Dry-run mode: Preview cleanup before execution
  • User override: Always respects explicit user instructions

๐Ÿš€ Quick Start

Installation

# Install the package
pip install context-cleanup==0.2.0

# Verify installation
python3 -c "from context_cleanup.tools import context_status; print('โœ… Installed')"

Basic Usage

# Check context status
python3 ~/.claude/local/bin/context-status --detailed

# Analyze cleanup candidates
~/.claude/local/bin/analyze-cleanup standard --json

# Perform cleanup (dry-run)
python3 ~/.claude/local/bin/cleanup-context standard --dry-run

# Execute cleanup
python3 ~/.claude/local/bin/cleanup-context standard --approve

For detailed installation instructions, see INSTALLATION.md


๐Ÿ”ง Available Tools

1. context-status

Check current context usage and get recommendations

2. analyze-cleanup

Preview what would be removed (dry-run analysis)

Modes: conservative, standard, aggressive, emergency

3. cleanup-context

Perform the actual context cleanup

4. memory-migration

Save important information to MCP Memory Server


๐Ÿ“ Repository Structure

claude-code-context-cleanup/
โ”œโ”€โ”€ README.md                    # This file (English)
โ”œโ”€โ”€ INSTALLATION.md              # Installation guide (English)
โ”œโ”€โ”€ CHANGELOG.md                 # Version history
โ”œโ”€โ”€ CONTRIBUTING.md              # Contributing guidelines (English)
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ README.md               # Multi-language documentation center
โ”‚   โ”œโ”€โ”€ en/                     # English documentation
โ”‚   โ”œโ”€โ”€ de/                     # Deutsch documentation
โ”‚   โ”œโ”€โ”€ es/                     # Espaรฑol documentation
โ”‚   โ”œโ”€โ”€ fr/                     # Franรงais documentation
โ”‚   โ”œโ”€โ”€ zh/                     # ไธญๆ–‡ (Chinese) documentation
โ”‚   โ”œโ”€โ”€ it/                     # Italiano documentation
โ”‚   โ””โ”€โ”€ ru/                     # ะ ัƒััะบะธะน (Russian) documentation
โ”œโ”€โ”€ implementation/
โ”‚   โ””โ”€โ”€ context_cleanup/         # Main package
โ”‚       โ”œโ”€โ”€ core/                # Core modules
โ”‚       โ”œโ”€โ”€ analyzers/           # Analysis engines
โ”‚       โ”œโ”€โ”€ tools/               # CLI tools
โ”‚       โ””โ”€โ”€ utils/               # Utilities
โ”œโ”€โ”€ tests/                       # Test suite
โ””โ”€โ”€ LICENSE                      # MIT License

๐Ÿ›ก๏ธ Safety & Guidelines

What Gets Cleaned Up

  • โœ… Old grep/glob searches (no follow-up)
  • โœ… Exploratory file reads (no subsequent edits)
  • โœ… Completed todo items
  • โœ… Old bash command outputs
  • โœ… Redundant information

Never Removed

  • โŒ Last 3 turns (always kept)
  • โŒ Error messages & traces
  • โŒ Recently edited files
  • โŒ Actively referenced messages
  • โŒ System prompts

๐Ÿš€ Roadmap

โœ… v0.2.0 - Current (Beta Phase - Production Ready)

Released: October 18, 2025

  • โœ… Core tools and analyzers (4 tools)
  • โœ… CLI integration with all features
  • โœ… Full test coverage (264 tests, 54% coverage)
  • โœ… 100% type safety and documentation
  • โœ… Multilingual documentation (7 languages)
  • โœ… Production deployment ready

๐Ÿ”œ v0.3.0 (Q4 2025) - Advanced Features & API Integration

Planned Features:

  • Real Claude Code API integration
  • Advanced ML-based relevance scoring
  • Production PostgreSQL database support
  • Real-time context monitoring dashboard
  • Performance optimizations
  • Extended language support

๐Ÿ”œ v0.4.0 (Q1 2026) - Enterprise Features

Planned Features:

  • Advanced configuration management
  • Multi-user project support
  • Custom cleanup policies
  • Audit logging and compliance
  • Team collaboration features

๐Ÿ”œ v1.0.0 (Q2 2026) - General Availability

General Availability Release:

  • Full production deployment
  • Enterprise monitoring and observability
  • Professional support program
  • SLA guarantees
  • Security certifications

๐Ÿ“š Documentation


๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.


๐Ÿ“„ License

MIT License - See LICENSE file for details


๐Ÿ”— Links


Status: ๐ŸŸข Beta Phase - Production Ready Version: 0.2.0 Last Updated: 18. Oktober 2025

โญ Star this repo if you find it interesting!

About

Intelligent autonomous context cleanup system for Claude Code - Automatically manages prompt size through smart cleanup and memory migration

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages