К основному содержанию
команда CX Codex

cleanup-context — команда для Claude Code: оптимизация памяти проекта

Команда cleanup-context для Claude Code анализирует и сокращает объём файлов документации проекта, удаляя дубли, устаревшие материалы и консолидируя перекрывающийся контент.

MIT ★ 2 744 обновлён 2026-10-08

Установить в Claude Code · Вручную: положить файлы Все способы и платформы ↓
.claude/commands/cleanup-context.md
Открыть на GitHub

Что делает cleanup-context

Команда работает в Claude Code и сканирует память проекта (файлы CLAUDE-*.md, CLAUDE.md, README.md) в четыре этапа: сначала удаляет файлы, отмеченные как «REMOVED» или «DEPRECATED», потом объединяет документацию по одному топику в один файл, затем сокращает многословие в главном CLAUDE.md, и в конце архивирует историческую документацию. На каждом этапе сохраняются все существенные технические детали, примеры конфигурации, советы по отладке и временная шкала.

Оптимизация ищет файлы объёмом более 20 КБ с дублирующейся информацией и группирует их — например, несколько файлов о безопасности сливает в один comprehensive. После каждой фазы команда обновляет ссылки в CLAUDE.md и подсчитывает сэкономленные токены. Результат: память обычно сокращается на 15–25 процентов при полном сохранении нужной информации.

Документация предусмотрена для монтажа в четырёх средах: Claude Code (.claude/commands/), Codex (~/.codex/prompts/), GitHub Copilot (.github/prompts/) и Gemini CLI (.gemini/commands/). Настроена на регулярный прогон — раз в месяц проверять на новые устаревшие файлы, раз в квартал искать возможности объединения, раз в полугодие делать полный аудит.

Какие задачи решает

  • сократить размер памяти проекта без потери технической информации
  • найти и удалить дублирующееся описание одного функционала в разных файлах
  • архивировать разрешённые задачи, чтобы они не занимали место в активной памяти
  • обновить ссылки и индексы после перестановки файлов
  • подсчитать, сколько токенов сэкономилось

Примеры запросов агенту

  • Проанализируй память проекта и определи, какие файлы можно удалить или объединить
  • Найди все файлы CLAUDE-security-*.md, объедини их в один CLAUDE-security-comprehensive.md и удали исходники
  • Сформируй архив для разрешённых задач и обнови CLAUDE.md с ссылкой на архив

Как установить cleanup-context

Вручную: положить файлы

.claude/commands/cleanup-context.md

Вызов — /cleanup-context. Для всех проектов — ~/.claude/commands/

Вопросы о cleanup-context

Как установить cleanup-context в Claude Code?

Скопируй файл из репозитория в .claude/commands/cleanup-context.md. Команда будет доступна в Claude Code сразу после обновления памяти.

Что делает cleanup-context?

Команда сканирует документацию проекта и удаляет устаревшие файлы, объединяет дублирующееся содержание и архивирует исторические материалы. Цель — сократить общий объём памяти на 15–25 процентов.

На сколько именно уменьшится контекстное окно?

Зависит от состояния памяти проекта. Если много старых файлов и дублей, экономия может быть 30–50 КБ; если память уже чистая, 5–10 КБ. Команда рассчитает точный результат после анализа.

Исходный текст

cleanup-context.md · MIT
# Memory Bank Context Optimization

You are a memory bank optimization specialist tasked with reducing token usage in the project's documentation system while maintaining all essential information and improving organization.

## Task Overview

Analyze the project's memory bank files (CLAUDE-*.md, CLAUDE.md, README.md) to identify and eliminate token waste through:

1. **Duplicate content removal**
2. **Obsolete file elimination**
3. **Content consolidation**
4. **Archive strategy implementation**
5. **Essential content optimization**

## Analysis Phase

### 1. Initial Assessment

```bash
# Get comprehensive file size analysis
find . -name "CLAUDE-*.md" -exec wc -c {} \; | sort -nr
wc -c CLAUDE.md README.md
```

**Examine for:**

- Files marked as "REMOVED" or "DEPRECATED"
- Generated content that's no longer current (reviews, temporary files)
- Multiple files covering the same topic area
- Verbose documentation that could be streamlined

### 2. Identify Optimization Opportunities

**High-Impact Targets (prioritize first):**

- Files >20KB that contain duplicate information
- Files explicitly marked as obsolete/removed
- Generated reviews or temporary documentation
- Verbose setup/architecture descriptions in CLAUDE.md

**Medium-Impact Targets:**

- Files 10-20KB with overlapping content
- Historic documentation for resolved issues
- Detailed implementation docs that could be consolidated

**Low-Impact Targets:**

- Files <10KB with minor optimization potential
- Content that could be streamlined but is unique

## Optimization Strategy

### Phase 1: Remove Obsolete Content (Highest Impact)

**Target:** Files marked as removed, deprecated, or clearly obsolete

**Actions:**

1. Delete files marked as "REMOVED" or "DEPRECATED"
2. Remove generated reviews/reports that are outdated
3. Clean up empty or minimal temporary files
4. Update CLAUDE.md references to removed files

**Expected Savings:** 30-50KB typically

### Phase 2: Consolidate Overlapping Documentation (High Impact)

**Target:** Multiple files covering the same functional area

**Common Consolidation Opportunities:**

- **Security files:** Combine security-fixes, security-optimization, security-hardening into one comprehensive file
- **Performance files:** Merge performance-optimization and test-suite documentation
- **Architecture files:** Consolidate detailed architecture descriptions
- **Testing files:** Combine multiple test documentation files

**Actions:**

1. Create consolidated files with comprehensive coverage
2. Ensure all essential information is preserved
3. Remove the separate files
4. Update all references in CLAUDE.md

**Expected Savings:** 20-40KB typically

### Phase 3: Streamline CLAUDE.md (Medium Impact)

**Target:** Remove verbose content that duplicates memory bank files

**Actions:**

1. Replace detailed descriptions with concise summaries
2. Remove redundant architecture explanations
3. Focus on essential guidance and references
4. Eliminate duplicate setup instructions

**Expected Savings:** 5-10KB typically

### Phase 4: Archive Strategy (Medium Impact)

**Target:** Historic documentation that's resolved but worth preserving

**Actions:**

1. Create `archive/` directory
2. Move resolved issue documentation to archive
3. Add archive README.md with index
4. Update CLAUDE.md with archive reference
5. Preserve discoverability while reducing active memory

**Expected Savings:** 10-20KB typically

## Consolidation Guidelines

### Creating Comprehensive Files

**Security Consolidation Pattern:**

```markdown
# CLAUDE-security-comprehensive.md

**Status**: ✅ COMPLETE - All Security Implementations  
**Coverage**: [List of consolidated topics]

## Executive Summary
[High-level overview of all security work]

## [Topic 1] - [Original File 1 Content]
[Essential information from first file]

## [Topic 2] - [Original File 2 Content] 
[Essential information from second file]

## [Topic 3] - [Original File 3 Content]
[Essential information from third file]

## Consolidated [Cross-cutting Concerns]
[Information that appeared in multiple files]
```

**Quality Standards:**

- Maintain all essential technical information
- Preserve implementation details and examples
- Keep configuration examples and code snippets
- Include all important troubleshooting information
- Maintain proper status tracking and dates

### File Naming Convention

- Use `-comprehensive` suffix for consolidated files
- Use descriptive names that indicate complete coverage
- Update CLAUDE.md with single reference per topic area

## Implementation Process

### 1. Plan and Validate

```bash
# Create todo list for tracking
TodoWrite with optimization phases and specific files
```

### 2. Execute by Priority

- Start with highest-impact targets (obsolete files)
- Move to consolidation opportunities
- Optimize main documentation
- Implement archival strategy

### 3. Update References

- Update CLAUDE.md memory bank file list
- Remove references to deleted files
- Add references to new consolidated files
- Update archive references

### 4. Validate Results

```bash
# Calculate savings achieved
find . -name "CLAUDE-*.md" -not -path "*/archive/*" -exec wc -c {} \; | awk '{sum+=$1} END {print sum}'
```

## Expected Outcomes

### Typical Optimization Results

- **15-25% total token reduction** in memory bank
- **Improved organization** with focused, comprehensive files
- **Maintained information quality** with no essential loss
- **Better maintainability** through reduced duplication
- **Preserved history** via organized archival

### Success Metrics

- Total KB/token savings achieved
- Number of files consolidated
- Percentage reduction in memory bank size
- Maintenance of all essential information

## Quality Assurance

### Information Preservation Checklist

- [ ] All technical implementation details preserved
- [ ] Configuration examples and code snippets maintained
- [ ] Troubleshooting information retained
- [ ] Status tracking and timeline information kept
- [ ] Cross-references and dependencies documented

### Organization Improvement Checklist

- [ ] Related information grouped logically
- [ ] Clear file naming and purpose
- [ ] Updated CLAUDE.md references
- [ ] Archive strategy implemented
- [ ] Discoverability maintained

## Post-Optimization Maintenance

### Regular Optimization Schedule

- **Monthly**: Check for new obsolete files
- **Quarterly**: Review for new consolidation opportunities
- **Semi-annually**: Comprehensive optimization review
- **As-needed**: After major implementation phases

### Warning Signs for Re-optimization

- Memory bank files exceeding previous optimized size
- Multiple new files covering same topic areas
- Files marked as removed/deprecated but still present
- User feedback about context window limitations

## Documentation Standards

### Consolidated File Format

```markdown
# CLAUDE-[topic]-comprehensive.md

**Last Updated**: [Date]
**Status**: ✅ [Status Description]
**Coverage**: [What this file consolidates]

## Executive Summary
[Overview of complete topic coverage]

## [Major Section 1]
[Comprehensive coverage of subtopic]

## [Major Section 2] 
[Comprehensive coverage of subtopic]

## [Cross-cutting Concerns]
[Information spanning multiple original files]
```

### Archive File Format

```markdown
# archive/README.md

## Archived Files
### [Category]
- **filename.md** - [Description] (resolved/historic)

## Usage
Reference when investigating similar issues or understanding implementation history.
```

This systematic approach ensures consistent, effective memory bank optimization while preserving all essential information and improving overall organization.

© centminmod · MIT · centminmod/my-claude-code-setup

Похожие слэш-команды

Все слэш-команды по теме «Настройка агента: память, контекст, субагенты» →
context-manager VoltAgent Community Субагент context-manager организует общий контекст мультиагентного проекта в файлах: раскладывает состояние, решения и историю задач по понятной структуре. CX Codex 10 638установок initref davila7 Команда initref собирает справочные документы о внутреннем устройстве проекта в каталог /ref и прописывает ссылки на них в CLAUDE.md. CX Codex +1 186установок context-window-management sickn33 Скилл context-window-management для Claude Code считает, сокращает и распределяет контекст LLM. Управляет историей многошаговых диалогов, когда она мешает запросу. CX Codex +1 1 600установок filesystem-context guanyang Скилл filesystem-context учит агента складывать контекст в файлы: черновики, выгрузки вывода инструментов, планы и передачу между субагентами. CX Codex +1 608установок context-master JosiahSiegel Скилл context-master для планирования сложных задач и многофайловых проектов. Заставляет агента сначала составить план, а потом писать файлы. CX Codex +1 401установок Context Preserver daffy0208 Скилл Context Preserver сохраняет состояние работы в .adhd/context.json и возвращает его после перерыва: файл, строка, что делали и что дальше. CX Codex +1 139установок

Из того же набора35

Весь набор →
batch-operations-prompt Команда batch-operations-prompt превращает сырые запросы на рефакторинг в структурированные планы с параллельными и последовательными шагами. Помогает Claude Code выполнять массовые правки через TodoWrite без конфликтов. CX Codex +1 ★ 2 744звёзд репо memory-bank-synchronizer memory-bank-synchronizer — субагент Claude Code, который сверяет memory bank с текущим кодом и обновляет документацию при расхождениях. CX Codex ★ 2 744звёзд репо ux-design-expert Субагент ux-design-expert для Claude Code разбирает пользовательские сценарии, собирает дизайн-систему на Tailwind и настраивает графики Highcharts. Разбирает путаницу пользователей в готовом интерфейсе. CX Codex ★ 2 744звёзд репо code-searcher Субагент code-searcher ищет функции, классы и уязвимости в кодовой базе и возвращает ссылки на строки файл:номер. CX Codex ★ 2 744звёзд репо audit-session-metrics Читает JSON-экспорт session-metrics и выдаёт отчёт о нерациональном расходе токенов. Запускается командой /audit-session-metrics quick или detailed над готовым файлом экспорта. CX Codex +1 ★ 2 744звёзд репо task-breakdown Скилл task-breakdown группирует запросы из сессии Claude Code в осмысленные задачи и оценивает их пользу по метрикам. CX Codex +1 ★ 2 744звёзд репо apply-thinking-to Команда apply-thinking-to для Claude Code преобразует файл промпта по схемам расширенного мышления Anthropic. Помогает анализировать задачи, проверять выводы и разбирать компромиссы. CX Codex +1 ★ 2 744звёзд репо create-release-note Команда create-release-note для автоматического создания двух версий документации релиза: покупательской и технической. Анализирует коммиты за последнее время и структурирует изменения по темам. CX Codex +1 ★ 2 744звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой