Review what context was summarized away during compaction to understand information loss
Analyzes compaction events to identify what context was summarized away and potential information loss.
/plugin marketplace add melodic-software/claude-code-plugins/plugin install claude-code-observability@melodic-software[session-id] [--current] [--compare]After a compaction event (/compact or automatic), review what context was summarized away to understand potential information loss.
| Argument | Description |
|---|---|
session-id | Specific session ID to review |
--current | Review current session's last compaction |
--compare | Compare pre/post compaction context |
--list | List all compaction events in session |
| (no args) | Review most recent compaction in current session |
Compaction is Claude Code's context management feature that summarizes older conversation turns when the context window fills up:
| Aspect | Description |
|---|---|
| Trigger | Context window approaching limit (~85%+) |
| Process | Older turns summarized into compact form |
| Result | Reduced context, preserved key information |
| Record | {"type":"summary","summary":"..."} in transcript |
| Category | Risk | Examples |
|---|---|---|
| Specific file paths | Medium | Exact paths may be summarized to "several files" |
| Error details | Medium | Stack traces, error codes compressed |
| Code snippets | High | Inline code examples may be omitted |
| Decision rationale | Medium | Why choices were made |
| User preferences | Low | Usually preserved in summary |
| Technical constraints | Medium | Specific requirements may be generalized |
import json
from pathlib import Path
claude_dir = Path.home() / ".claude"
projects_dir = claude_dir / "projects"
def find_compaction_events(session_path):
"""Find all compaction summaries in a session."""
events = []
with open(session_path) as f:
for line_num, line in enumerate(f, 1):
try:
record = json.loads(line)
if record.get("type") == "summary":
events.append({
"line": line_num,
"summary": record.get("summary", ""),
"timestamp": record.get("timestamp") # If present
})
except json.JSONDecodeError:
continue
return events
def get_pre_compaction_content(session_path, compaction_line):
"""Get content that was summarized in compaction."""
content = []
with open(session_path) as f:
lines = f.readlines()
# Find previous compaction or start of session
start_line = 0
for i in range(compaction_line - 2, -1, -1):
try:
record = json.loads(lines[i])
if record.get("type") == "summary":
start_line = i + 1
break
except:
continue
# Collect content between previous compaction and this one
for i in range(start_line, compaction_line - 1):
try:
record = json.loads(lines[i])
content.append(record)
except:
continue
return content
def analyze_loss(pre_content, summary):
"""Analyze what was potentially lost in compaction."""
analysis = {
"files_mentioned": set(),
"code_snippets": 0,
"error_messages": 0,
"decisions": [],
"preserved_in_summary": []
}
for record in pre_content:
content = ""
if record.get("type") == "user":
content = record.get("message", {}).get("content", "")
elif record.get("type") == "assistant":
content = record.get("message", {}).get("content", "")
# Extract file paths
import re
paths = re.findall(r'[/\\][\w/\\.-]+\.\w+', content)
analysis["files_mentioned"].update(paths)
# Count code blocks
analysis["code_snippets"] += content.count("```")
# Count error patterns
if any(word in content.lower() for word in ["error", "exception", "failed"]):
analysis["error_messages"] += 1
# Check what's preserved in summary
for item in analysis["files_mentioned"]:
if item in summary:
analysis["preserved_in_summary"].append(item)
analysis["files_mentioned"] = list(analysis["files_mentioned"])
return analysis
# Compaction Review
**Session:** abc123-def456
**Compaction Event:** #1 (line 523)
**Time:** 2025-12-30 15:30 (estimated)
## Compaction Summary
> The conversation covered implementing user authentication with JWT
> tokens, setting up the auth middleware, and fixing a validation
> bug in the login form. Key files modified include auth.ts and
> login.tsx. The user requested rate limiting which was implemented
> using a sliding window algorithm.
## What Was Summarized
**Pre-compaction context:**
- User turns: 12
- Assistant turns: 12
- Approximate tokens: ~45,000
**Content analysis:**
| Category | Count | Preserved |
|----------|-------|-----------|
| Files mentioned | 8 | 3 (38%) |
| Code snippets | 15 | Summary only |
| Error messages | 2 | Partial |
| Technical decisions | 4 | 2 |
## Potentially Lost Details
### Files Not in Summary
These files were discussed but not mentioned in the compaction summary:
- `src/utils/validation.ts` - Validation helpers
- `src/types/auth.ts` - Type definitions
- `tests/auth.test.ts` - Test file
- `package.json` - Dependency changes
### Code Snippets Summarized
15 code blocks were reduced to prose description. If you need the exact code, you may need to:
1. Re-implement based on summary
2. Search session transcript for specific patterns
3. Check file-history for actual changes made
### Error Details Lost
2 error messages were discussed:
1. "JWT token validation failed" - Details compressed
2. "ECONNREFUSED" - Database connection issue
The summary mentions "fixing a validation bug" but doesn't preserve the exact error.
## Recovery Options
If you need details that were compacted:
1. **Search transcript:** `/user-config:transcript-search "validation"`
2. **Check file history:** `/user-config:file-versions src/auth/auth.ts`
3. **Review session:** `claude --resume abc123-def456`
## Compaction Settings
**Current setting:** Automatic (Claude Code default)
To manually control compaction:
- `/compact` - Trigger manual compaction
- Context monitor: `/check-context` - See current usage
## Prevention Tips
For important sessions with details you want to preserve:
1. **Save key details to CLAUDE.md** before compaction
2. **Export important code** to files early
3. **Use `/clear` between tasks** to start fresh
4. **Document decisions** in comments or ADRs
/compact - Manual compaction (built-in)/check-context - Monitor context usage/user-config:transcript-search - Search for lost details/user-config:retrospective - Full session analysisThis command uses the user-config-management skill for: