Files
SuperClaude/docs/Reference/claude-code-history-management.md
kazuki nakai 050d5ea2ab refactor: PEP8 compliance - directory rename and code formatting (#425)
* fix(orchestration): add WebFetch auto-trigger for infrastructure configuration

Problem: Infrastructure configuration changes (e.g., Traefik port settings)
were being made based on assumptions without consulting official documentation,
violating the 'Evidence > assumptions' principle in PRINCIPLES.md.

Solution:
- Added Infrastructure Configuration Validation section to MODE_Orchestration.md
- Auto-triggers WebFetch for infrastructure tools (Traefik, nginx, Docker, etc.)
- Enforces MODE_DeepResearch activation for investigation
- BLOCKS assumption-based configuration changes

Testing: Verified WebFetch successfully retrieves Traefik official docs (port 80 default)

This prevents production outages from infrastructure misconfiguration by ensuring
all technical recommendations are backed by official documentation.

* feat: Add PM Agent (Project Manager Agent) for seamless orchestration

Introduces PM Agent as the default orchestration layer that coordinates
all sub-agents and manages workflows automatically.

Key Features:
- Default orchestration: All user interactions handled by PM Agent
- Auto-delegation: Intelligent sub-agent selection based on task analysis
- Docker Gateway integration: Zero-token baseline with dynamic MCP loading
- Self-improvement loop: Automatic documentation of patterns and mistakes
- Optional override: Users can specify sub-agents explicitly if desired

Architecture:
- Agent spec: SuperClaude/Agents/pm-agent.md
- Command: SuperClaude/Commands/pm.md
- Updated docs: README.md (15→16 agents), agents.md (new Orchestration category)

User Experience:
- Default: PM Agent handles everything (seamless, no manual routing)
- Optional: Explicit --agent flag for direct sub-agent access
- Both modes available simultaneously (no user downside)

Implementation Status:
-  Specification complete
-  Documentation complete
-  Prototype implementation needed
-  Docker Gateway integration needed
-  Testing and validation needed

Refs: kazukinakai/docker-mcp-gateway (IRIS MCP Gateway integration)

* feat: Add Agent Orchestration rules for PM Agent default activation

Implements PM Agent as the default orchestration layer in RULES.md.

Key Changes:
- New 'Agent Orchestration' section (CRITICAL priority)
- PM Agent receives ALL user requests by default
- Manual override with @agent-[name] bypasses PM Agent
- Agent Selection Priority clearly defined:
  1. Manual override → Direct routing
  2. Default → PM Agent → Auto-delegation
  3. Delegation based on keywords, file types, complexity, context

User Experience:
- Default: PM Agent handles everything (seamless)
- Override: @agent-[name] for direct specialist access
- Transparent: PM Agent reports delegation decisions

This establishes PM Agent as the orchestration layer while
respecting existing auto-activation patterns and manual overrides.

Next Steps:
- Local testing in agiletec project
- Iteration based on actual behavior
- Documentation updates as needed

* refactor(pm-agent): redesign as self-improvement meta-layer

Problem Resolution:
PM Agent's initial design competed with existing auto-activation for task routing,
creating confusion about orchestration responsibilities and adding unnecessary complexity.

Design Change:
Redefined PM Agent as a meta-layer agent that operates AFTER specialist agents
complete tasks, focusing on:
- Post-implementation documentation and pattern recording
- Immediate mistake analysis with prevention checklists
- Monthly documentation maintenance and noise reduction
- Pattern extraction and knowledge synthesis

Two-Layer Orchestration System:
1. Task Execution Layer: Existing auto-activation handles task routing (unchanged)
2. Self-Improvement Layer: PM Agent meta-layer handles documentation (new)

Files Modified:
- SuperClaude/Agents/pm-agent.md: Complete rewrite with meta-layer design
  - Category: orchestration → meta
  - Triggers: All user interactions → Post-implementation, mistakes, monthly
  - Behavioral Mindset: Continuous learning system
  - Self-Improvement Workflow: BEFORE/DURING/AFTER/MISTAKE RECOVERY/MAINTENANCE

- SuperClaude/Core/RULES.md: Agent Orchestration section updated
  - Split into Task Execution Layer + Self-Improvement Layer
  - Added orchestration flow diagram
  - Clarified PM Agent activates AFTER task completion

- README.md: Updated PM Agent description
  - "orchestrates all interactions" → "ensures continuous learning"

- Docs/User-Guide/agents.md: PM Agent section rewritten
  - Section: Orchestration Agent → Meta-Layer Agent
  - Expertise: Project orchestration → Self-improvement workflow executor
  - Examples: Task coordination → Post-implementation documentation

- PR_DOCUMENTATION.md: Comprehensive PR documentation added
  - Summary, motivation, changes, testing, breaking changes
  - Two-layer orchestration system diagram
  - Verification checklist

Integration Validated:
Tested with agiletec project's self-improvement-workflow.md:
 PM Agent aligns with existing BEFORE/DURING/AFTER/MISTAKE RECOVERY phases
 Complements (not competes with) existing workflow
 agiletec workflow defines WHAT, PM Agent defines WHO executes it

Breaking Changes: None
- Existing auto-activation continues unchanged
- Specialist agents unaffected
- User workflows remain the same
- New capability: Automatic documentation and knowledge maintenance

Value Proposition:
Transforms SuperClaude into a continuously learning system that accumulates
knowledge, prevents recurring mistakes, and maintains fresh documentation
without manual intervention.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: add Claude Code conversation history management research

Research covering .jsonl file structure, performance impact, and retention policies.

Content:
- Claude Code .jsonl file format and message types
- Performance issues from GitHub (memory leaks, conversation compaction)
- Retention policies (consumer vs enterprise)
- Rotation recommendations based on actual data
- File history snapshot tracking mechanics

Source: Moved from agiletec project (research applicable to all Claude Code projects)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: add Development documentation structure

Phase 1: Documentation Structure complete

- Add Docs/Development/ directory for development documentation
- Add ARCHITECTURE.md - System architecture with PM Agent meta-layer
- Add ROADMAP.md - 5-phase development plan with checkboxes
- Add TASKS.md - Daily task tracking with progress indicators
- Add PROJECT_STATUS.md - Current status dashboard and metrics
- Add pm-agent-integration.md - Implementation guide for PM Agent mode

This establishes comprehensive documentation foundation for:
- System architecture understanding
- Development planning and tracking
- Implementation guidance
- Progress visibility

Related: #pm-agent-mode #documentation #phase-1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: PM Agent session lifecycle and PDCA implementation

Phase 2: PM Agent Mode Integration (Design Phase)

Commands/pm.md updates:
- Add "Always-Active Foundation Layer" concept
- Add Session Lifecycle (Session Start/During Work/Session End)
- Add PDCA Cycle (Plan/Do/Check/Act) automation
- Add Serena MCP Memory Integration (list/read/write_memory)
- Document auto-activation triggers

Agents/pm-agent.md updates:
- Add Session Start Protocol (MANDATORY auto-activation)
- Add During Work PDCA Cycle with example workflows
- Add Session End Protocol with state preservation
- Add PDCA Self-Evaluation Pattern
- Add Documentation Strategy (temp → patterns/mistakes)
- Add Memory Operations Reference

Key Features:
- Session start auto-activation for context restoration
- 30-minute checkpoint saves during work
- Self-evaluation with think_about_* operations
- Systematic documentation lifecycle
- Knowledge evolution to CLAUDE.md

Implementation Status:
-  Design complete (Commands/pm.md, Agents/pm-agent.md)
-  Implementation pending (Core components)
-  Serena MCP integration pending

Salvaged from mistaken development in ~/.claude directory

Related: #pm-agent-mode #session-lifecycle #pdca-cycle #phase-2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: disable Serena MCP auto-browser launch

Disable web dashboard and GUI log window auto-launch in Serena MCP server
to prevent intrusive browser popups on startup. Users can still manually
access the dashboard at http://localhost:24282/dashboard/ if needed.

Changes:
- Add CLI flags to Serena run command:
  - --enable-web-dashboard false
  - --enable-gui-log-window false
- Ensures Git-tracked configuration (no reliance on ~/.serena/serena_config.yml)
- Aligns with AIRIS MCP Gateway integration approach

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: rename directories to lowercase for PEP8 compliance

- Rename superclaude/Agents -> superclaude/agents
- Rename superclaude/Commands -> superclaude/commands
- Rename superclaude/Core -> superclaude/core
- Rename superclaude/Examples -> superclaude/examples
- Rename superclaude/MCP -> superclaude/mcp
- Rename superclaude/Modes -> superclaude/modes

This change follows Python PEP8 naming conventions for package directories.

* style: fix PEP8 violations and update package name to lowercase

Changes:
- Format all Python files with black (43 files reformatted)
- Update package name from 'SuperClaude' to 'superclaude' in pyproject.toml
- Fix import statements to use lowercase package name
- Add missing imports (timedelta, __version__)
- Remove old SuperClaude.egg-info directory

PEP8 violations reduced from 2672 to 701 (mostly E501 line length due to black's 88 char vs flake8's 79 char limit).

* docs: add PM Agent development documentation

Add comprehensive PM Agent development documentation:
- PM Agent ideal workflow (7-phase autonomous cycle)
- Project structure understanding (Git vs installed environment)
- Installation flow understanding (CommandsComponent behavior)
- Task management system (current-tasks.md)

Purpose: Eliminate repeated explanations and enable autonomous PDCA cycles

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(pm-agent): add self-correcting execution and warning investigation culture

## Changes

### superclaude/commands/pm.md
- Add "Self-Correcting Execution" section with root cause analysis protocol
- Add "Warning/Error Investigation Culture" section enforcing zero-tolerance for dismissal
- Define error detection protocol: STOP → Investigate → Hypothesis → Different Solution → Execute
- Document anti-patterns (retry without understanding) and correct patterns (research-first)

### docs/Development/hypothesis-pm-autonomous-enhancement-2025-10-14.md
- Add PDCA workflow hypothesis document for PM Agent autonomous enhancement

## Rationale

PM Agent must never retry failed operations without understanding root causes.
All warnings and errors require investigation via context7/WebFetch/documentation
to ensure production-quality code and prevent technical debt accumulation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(installer): add airis-mcp-gateway MCP server option

## Changes

- Add airis-mcp-gateway to MCP server options in installer
- Configuration: GitHub-based installation via uvx
- Repository: https://github.com/oraios/airis-mcp-gateway
- Purpose: Dynamic MCP Gateway for zero-token baseline and on-demand tool loading

## Implementation

Added to setup/components/mcp.py self.mcp_servers dictionary with:
- install_method: github
- install_command: uvx test installation
- run_command: uvx runtime execution
- required: False (optional server)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: kazuki <kazuki@kazukinoMacBook-Air.local>
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-14 08:47:09 +05:30

557 lines
16 KiB
Markdown

# Claude Code Conversation History Management Research
**Research Date**: 2025-10-09
**Purpose**: Understand .jsonl file structure, performance impact, and establish rotation policy
---
## 1. Official Documentation & Purpose
### .jsonl File Structure
**Location**: `~/.claude/projects/{project-directory}/`
**Data Structure** (from analysis of actual files):
```json
{
"type": "summary|file-history-snapshot|user|assistant|system|tool_use|tool_result|message",
"timestamp": "ISO-8601 timestamp",
"cwd": "/absolute/path/to/working/directory",
"sessionId": "uuid",
"gitBranch": "branch-name",
"content": "message content or command",
"messageId": "uuid for message tracking"
}
```
**Key Message Types** (from 2.6MB conversation analysis):
- `message` (228): Container for conversation messages
- `assistant` (228): Claude's responses
- `user` (182): User inputs
- `tool_use` (137): Tool invocations
- `tool_result` (137): Tool execution results
- `text` (74): Text content blocks
- `file-history-snapshot` (39): File state tracking
- `thinking` (31): Claude's reasoning process
- `system` (12): System-level messages
### File History Snapshot Purpose
```json
{
"type": "file-history-snapshot",
"messageId": "uuid",
"snapshot": {
"messageId": "uuid",
"trackedFileBackups": {},
"timestamp": "ISO-8601"
},
"isSnapshotUpdate": false
}
```
**Purpose** (inferred from structure):
- Tracks file states at specific conversation points
- Enables undo/redo functionality for file changes
- Provides rollback capability for edits
- **Note**: No official documentation found on this feature
### Conversation Loading Behavior
**Official Best Practices** ([source](https://www.anthropic.com/engineering/claude-code-best-practices)):
- "All conversations are automatically saved locally with their full message history"
- "When resuming, the entire message history is restored to maintain context"
- "Tool usage and results from previous conversations preserved"
**Resume Commands**:
- `--continue`: Automatically continue most recent conversation
- `/resume`: Show list of recent sessions and choose one
- Session ID specification: Resume specific conversation
---
## 2. Performance Impact
### Known Issues from GitHub
#### Issue #5024: History Accumulation Causing Performance Issues
**Status**: Open (Major Issue)
**URL**: https://github.com/anthropics/claude-code/issues/5024
**Reported Problems**:
- File sizes growing to "hundreds of MB or more"
- Slower application startup times
- System performance degradation
- No automatic cleanup mechanism
- One user reported file size of 968KB+ continuously growing
**Current Workaround**:
- Manual editing of `.claude.json` (risky - can break configurations)
- `claude history clear` (removes ALL history across ALL projects)
#### Issue #7985: Severe Memory Leak
**Status**: Critical
**URL**: https://github.com/anthropics/claude-code/issues/7985
**Reported Problems**:
- Context accumulation causing massive memory usage
- Memory leaks with objects not garbage collected
- One user reported ~570GB of virtual memory usage
- Long-running sessions become unusable
#### Issue #8839: Conversation Compaction Failure
**Status**: Regression (after undo/redo feature)
**URL**: https://github.com/anthropics/claude-code/issues/8839
**Impact**:
- Claude Code can no longer automatically compact long conversations
- "Too long" errors after conversation history navigation feature added
- Conversations become unmanageable without manual intervention
#### Issue #8755: /clear Command Not Working
**Status**: Bug
**URL**: https://github.com/anthropics/claude-code/issues/8755
**Impact**:
- `/clear` command stopped functioning for some users
- "Clear Conversations" menu option non-functional
- Users cannot reset context window as recommended
### Actual Performance Data (Your Environment)
**Current State** (as of 2025-10-09):
- **Total agiletec project**: 33MB (57 conversation files)
- **Largest file**: 2.6MB (462 lines)
- **Average file**: ~580KB
- **Files >1MB**: 3 files
- **Total across all projects**: ~62MB
**Age Distribution**:
- Files older than 30 days: 0
- Files older than 7 days: 4
- Most files: <7 days old
**Comparison to Other Projects**:
```
33M agiletec (57 files) - Most active
14M SSD-2TB project
6.3M tokium
2.6M bunseki
```
---
## 3. Official Retention Policies
### Standard Retention (Consumer)
**Source**: [Anthropic Privacy Center](https://privacy.claude.com/en/articles/10023548-how-long-do-you-store-my-data)
- **Prompts/Responses**: Up to 30 days in back-end logs
- **Deleted chats**: Immediately removed from UI, purged within 30 days
- **API logs**: Reducing to 7 days starting September 15, 2025 (from 30 days)
### Enterprise Controls
**Source**: [Custom Data Retention Controls](https://privacy.anthropic.com/en/articles/10440198-custom-data-retention-controls-for-claude-enterprise)
- **Minimum retention**: 30 days
- **Retention start**: Last observed activity (last message or project update)
- **Custom periods**: Available for organizations
### Local Storage (No Official Policy)
**Finding**: No official documentation found regarding:
- Recommended local .jsonl file retention periods
- Automatic cleanup of old conversations
- Performance thresholds for file sizes
- Safe deletion procedures
**Current Tools**:
- `claude history clear`: Removes ALL history (all projects, destructive)
- No selective cleanup tools available
- No archive functionality
---
## 4. Best Practices (Official & Community)
### Official Recommendations
#### Context Management
**Source**: [Claude Code Best Practices](https://www.anthropic.com/engineering/claude-code-best-practices)
**Key Guidelines**:
1. **Use `/clear` frequently**: "Reset context window between tasks"
2. **Scope conversations**: "One project or feature per conversation"
3. **Clear before switching**: "/clear before fixing bugs to prevent context pollution"
4. **Don't rely on long context**: "Claude's context window can fill with irrelevant conversation"
**Quote**: "During long sessions, Claude's context window can fill with irrelevant conversation, file contents, and commands which can reduce performance, so use the /clear command frequently between tasks to reset the context window."
#### CLAUDE.md Strategy
- **Persistent context**: Use CLAUDE.md files for stable instructions
- **Auto-loaded**: "Claude automatically pulls into context when starting"
- **Hierarchy**: Global (`~/.claude/CLAUDE.md`) → Workspace → Project
- **Refinement**: "Take time to experiment and determine what produces best results"
#### When to Restart vs /clear
**Source**: [Community Best Practices](https://claudelog.com/faqs/does-claude-code-store-my-data/)
**Use `/clear` when**:
- Starting new task/feature
- Switching between features
- Context becomes polluted
- Before bug fixing
**Restart session when**:
- Switching projects
- Updating CLAUDE.md files
- Experiencing session issues
- Memory usage high
### Community Strategies
#### Conversation Organization
**Pattern**: "Scope a chat to one project or feature"
- Start conversation for specific goal
- Use `/clear` when goal complete
- Don't mix unrelated tasks in same conversation
#### Context Optimization
**Pattern**: "Avoid extensive, unrefined context"
- Iterate on CLAUDE.md effectiveness
- Remove ineffective instructions
- Test and refine periodically
#### Incognito Mode for Sensitive Work
**Pattern**: "Ghost icon for temporary conversations"
- Not saved to chat history
- No contribution to context memory
- Useful for experimental or sensitive work
---
## 5. Recommended Rotation Policy
### Immediate Actions (No Risk)
#### 1. Delete Very Old Conversations (>30 days)
```bash
# Backup first
mkdir -p ~/.claude/projects-archive/$(date +%Y-%m)
# Find and archive
find ~/.claude/projects/ -name "*.jsonl" -mtime +30 -type f \
-exec mv {} ~/.claude/projects-archive/$(date +%Y-%m)/ \;
```
**Rationale**:
- Aligns with Anthropic's 30-day back-end retention
- Minimal functionality loss (context rarely useful after 30 days)
- Significant space savings
#### 2. Archive Project-Specific Old Conversations (>14 days)
```bash
# Per-project archive
mkdir -p ~/.claude/projects-archive/agiletec/$(date +%Y-%m)
find ~/.claude/projects/-Users-kazuki-github-agiletec -name "*.jsonl" -mtime +14 -type f \
-exec mv {} ~/.claude/projects-archive/agiletec/$(date +%Y-%m)/ \;
```
**Rationale**:
- 14 days provides buffer for resumed work
- Most development tasks complete within 2 weeks
- Easy to restore if needed
### Periodic Maintenance (Weekly)
#### 3. Identify Large Files for Manual Review
```bash
# Find files >1MB
find ~/.claude/projects/ -name "*.jsonl" -type f -size +1M -exec ls -lh {} \;
# Review and archive if not actively used
```
**Criteria for Archival**:
- File >1MB and not modified in 7 days
- Completed feature/project conversations
- Debugging sessions that are resolved
### Aggressive Cleanup (Monthly)
#### 4. Archive All Inactive Conversations (>7 days)
```bash
# Monthly archive
mkdir -p ~/.claude/projects-archive/$(date +%Y-%m)
find ~/.claude/projects/ -name "*.jsonl" -mtime +7 -type f \
-exec mv {} ~/.claude/projects-archive/$(date +%Y-%m)/ \;
```
**When to Use**:
- Project directory >50MB
- Startup performance degraded
- Running low on disk space
### Emergency Cleanup (Performance Issues)
#### 5. Nuclear Option - Keep Only Recent Week
```bash
# BACKUP EVERYTHING FIRST
tar -czf ~/claude-history-backup-$(date +%Y%m%d).tar.gz ~/.claude/projects/
# Keep only last 7 days
find ~/.claude/projects/ -name "*.jsonl" -mtime +7 -type f -delete
```
**When to Use**:
- Claude Code startup >10 seconds
- Memory usage abnormally high
- Experiencing Issue #7985 symptoms
---
## 6. Proposed Automated Solution
### Shell Script: `claude-history-rotate.sh`
```bash
#!/usr/bin/env bash
# Claude Code Conversation History Rotation
# Usage: ./claude-history-rotate.sh [--dry-run] [--days N]
set -euo pipefail
DAYS=${DAYS:-30}
DRY_RUN=false
ARCHIVE_BASE=~/.claude/projects-archive
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run) DRY_RUN=true; shift ;;
--days) DAYS="$2"; shift 2 ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# Create archive directory
ARCHIVE_DIR="$ARCHIVE_BASE/$(date +%Y-%m)"
mkdir -p "$ARCHIVE_DIR"
# Find old conversations
OLD_FILES=$(find ~/.claude/projects/ -name "*.jsonl" -mtime "+$DAYS" -type f)
if [[ -z "$OLD_FILES" ]]; then
echo "No files older than $DAYS days found."
exit 0
fi
# Count and size
FILE_COUNT=$(echo "$OLD_FILES" | wc -l | tr -d ' ')
TOTAL_SIZE=$(echo "$OLD_FILES" | xargs du -ch | tail -1 | awk '{print $1}')
echo "Found $FILE_COUNT files older than $DAYS days ($TOTAL_SIZE total)"
if [[ "$DRY_RUN" == "true" ]]; then
echo "DRY RUN - Would archive:"
echo "$OLD_FILES"
exit 0
fi
# Archive files
echo "$OLD_FILES" | while read -r file; do
mv "$file" "$ARCHIVE_DIR/"
echo "Archived: $(basename "$file")"
done
echo "✓ Archived $FILE_COUNT files to $ARCHIVE_DIR"
```
### Cron Job Setup (Optional)
```bash
# Add to crontab (monthly cleanup)
# 0 3 1 * * /Users/kazuki/.local/bin/claude-history-rotate.sh --days 30
# Or use launchd on macOS
cat > ~/Library/LaunchAgents/com.user.claude-history-rotate.plist <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.claude-history-rotate</string>
<key>ProgramArguments</key>
<array>
<string>/Users/kazuki/.local/bin/claude-history-rotate.sh</string>
<string>--days</string>
<string>30</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Day</key>
<integer>1</integer>
<key>Hour</key>
<integer>3</integer>
</dict>
</dict>
</plist>
EOF
launchctl load ~/Library/LaunchAgents/com.user.claude-history-rotate.plist
```
---
## 7. Monitoring & Alerts
### Disk Usage Check Script
```bash
#!/usr/bin/env bash
# claude-history-check.sh
THRESHOLD_MB=100
PROJECTS_DIR=~/.claude/projects
TOTAL_SIZE_MB=$(du -sm "$PROJECTS_DIR" | awk '{print $1}')
echo "Claude Code conversation history: ${TOTAL_SIZE_MB}MB"
if [[ $TOTAL_SIZE_MB -gt $THRESHOLD_MB ]]; then
echo "⚠️ WARNING: History size exceeds ${THRESHOLD_MB}MB threshold"
echo "Consider running: claude-history-rotate.sh --days 30"
# Find largest projects
echo ""
echo "Largest projects:"
du -sm "$PROJECTS_DIR"/*/ | sort -rn | head -5
fi
```
### Performance Indicators to Watch
1. **Startup time**: >5 seconds = investigate
2. **File sizes**: >2MB per conversation = review
3. **Total size**: >100MB across all projects = cleanup
4. **Memory usage**: >2GB during session = Issue #7985
5. **Conversation length**: >500 message pairs = use `/clear`
---
## 8. Key Takeaways & Recommendations
### Critical Findings
**Safe to Delete**:
- Conversations >30 days old (aligns with Anthropic retention)
- Completed feature/project conversations
- Large files (>1MB) not accessed in 14+ days
⚠️ **Caution Required**:
- Active project conversations (<7 days)
- Files referenced in recent work
- Conversations with unfinished tasks
**Known Issues**:
- No official cleanup tools (Issue #5024)
- Memory leaks in long sessions (Issue #7985)
- `/clear` command bugs (Issue #8755)
- Conversation compaction broken (Issue #8839)
### Recommended Policy for Your Environment
**Daily Practice**:
- Use `/clear` between major tasks
- Scope conversations to single features
- Restart session if >2 hours continuous work
**Weekly Review** (Sunday):
```bash
# Check current state
du -sh ~/.claude/projects/*/
# Archive old conversations (>14 days)
claude-history-rotate.sh --days 14 --dry-run # Preview
claude-history-rotate.sh --days 14 # Execute
```
**Monthly Cleanup** (1st of month):
```bash
# Aggressive cleanup (>30 days)
claude-history-rotate.sh --days 30
# Review large files
find ~/.claude/projects/ -name "*.jsonl" -size +1M -mtime +7
```
**Performance Threshold Actions**:
- Total size >50MB: Archive 30-day-old conversations
- Total size >100MB: Archive 14-day-old conversations
- Total size >200MB: Emergency cleanup (7-day retention)
- Startup >10s: Investigate memory leaks, consider Issue #7985
### Future-Proofing
**Watch for Official Solutions**:
- `claude history prune` command (requested in #5024)
- Automatic history rotation feature
- Configurable retention settings
- Separate configuration from history storage
**Community Tools**:
- [cclogviewer](https://github.com/hesreallyhim/awesome-claude-code): View .jsonl files
- Consider contributing to #5024 discussion
- Monitor anthropics/claude-code releases
---
## 9. References
### Official Documentation
- [Claude Code Best Practices](https://www.anthropic.com/engineering/claude-code-best-practices)
- [How Long Do You Store My Data?](https://privacy.claude.com/en/articles/10023548-how-long-do-you-store-my-data)
- [Custom Data Retention Controls](https://privacy.anthropic.com/en/articles/10440198-custom-data-retention-controls-for-claude-enterprise)
### GitHub Issues
- [#5024: History accumulation causes performance issues](https://github.com/anthropics/claude-code/issues/5024)
- [#7985: Severe memory leak](https://github.com/anthropics/claude-code/issues/7985)
- [#8839: Conversation compaction failure](https://github.com/anthropics/claude-code/issues/8839)
- [#8755: /clear command not working](https://github.com/anthropics/claude-code/issues/8755)
### Community Resources
- [Awesome Claude Code](https://github.com/hesreallyhim/awesome-claude-code)
- [Claude Code Context Guide](https://www.arsturn.com/blog/beyond-prompting-a-guide-to-managing-context-in-claude-code)
- [ClaudeLog Documentation](https://claudelog.com/)
---
## Appendix: Current Environment Statistics
**Generated**: 2025-10-09 04:24 JST
### Project Size Breakdown
```
33M -Users-kazuki-github-agiletec (57 files)
14M -Volumes-SSD-2TB (project count: N/A)
6.3M -Users-kazuki-github-tokium
2.6M -Users-kazuki-github-bunseki
1.9M -Users-kazuki
1.9M -Users-kazuki-github-superclaude
---
Total: ~62MB across all projects
```
### agiletec Project Details
- **Total conversations**: 57
- **Largest file**: 2.6MB (d4852655-b760-4311-8f67-26f593f2403f.jsonl)
- **Files >1MB**: 3 files
- **Avg file size**: ~580KB
- **Files >7 days**: 4 files
- **Files >30 days**: 0 files
### Immediate Recommendation
**Status**: ✅ Healthy (no immediate action required)
**Reasoning**:
- Total size (33MB) well below concern threshold (100MB)
- No files >30 days old
- Only 4 files >7 days old
- Largest file (2.6MB) within acceptable range
**Next Review**: 2025-10-16 (weekly check)