Skip to content

feat: Add compaction detection and context efficiency analysis (closes #69)#74

Merged
evansenter merged 2 commits into
mainfrom
feat/issue-69-context-efficiency
Jan 10, 2026
Merged

feat: Add compaction detection and context efficiency analysis (closes #69)#74
evansenter merged 2 commits into
mainfrom
feat/issue-69-context-efficiency

Conversation

@evansenter

Copy link
Copy Markdown
Owner

Summary

  • Add result_size_bytes column to track message sizes for context burn rate analysis
  • Detect compaction events during ingestion (when summaries contain "continued from a previous conversation")
  • Add 4 new MCP tools and CLI commands for context efficiency analysis:
    • get_compaction_events - List context reset events
    • get_pre_compaction_events - Show events before a compaction
    • get_large_tool_results - Find bloated tool results consuming context
    • get_session_efficiency - Analyze burn rate and efficiency metrics

Test plan

  • All 352 tests pass
  • New tests for get_pre_compaction_events (3 tests)
  • New tests for calculate_result_size and detect_compaction helpers (14 tests)
  • Migration v9 properly adds column with idempotency check

🤖 Generated with Claude Code

…#69)

Add result_size_bytes column to track message sizes for context burn rate analysis.
Detect compaction events during ingestion when summaries contain "continued from
a previous conversation" marker. Provide 4 new endpoints for analyzing context
efficiency: get_compaction_events, get_pre_compaction_events, get_large_tool_results,
and get_session_efficiency.

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

claude Bot commented Jan 10, 2026

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds compaction detection and context efficiency analysis capabilities: a new result_size_bytes column for tracking message sizes, detection of compaction events during ingestion, and 4 new MCP tools/CLI commands for analyzing context efficiency patterns.

Issues Found

Critical

None

Important

None

Suggestions

  • cli.py - Missing CLI formatter for get_pre_compaction_events. The command exists (line 1109) but unlike _format_compactions, _format_large_results, and _format_efficiency, there's no @_register_formatter for pre-compaction events. It falls back to JSON which is inconsistent with the other new commands that have human-readable formatters.

  • queries.py:2241 - Issue feat: Compaction detection and context efficiency analysis #69 specified read_to_edit_ratio and files_read_multiple_times metrics for get_session_efficiency(), but these are not implemented. The current implementation has useful signals but doesn't match the full issue spec. Consider whether these should be deferred to a follow-up or added here.

Verdict

REQUEST_CHANGES - Minor suggestions for consistency and issue spec alignment.


Automated review by Claude Code

- Add CLI formatter for get_pre_compaction_events for consistency
- Add read_to_edit_ratio metric to get_session_efficiency
- Add files_read_multiple_times metric to get_session_efficiency
- Update guide.md documentation with new metrics

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

Copy link
Copy Markdown
Owner Author

Feedback Addressed

Implemented

  • [Suggestion] Missing CLI formatter for get_pre_compaction_events - Added _format_pre_compaction formatter for human-readable output
  • [Suggestion] Missing metrics from Issue feat: Compaction detection and context efficiency analysis #69 spec - Added read_to_edit_ratio and files_read_multiple_times to get_session_efficiency() output

@claude

claude Bot commented Jan 10, 2026

Copy link
Copy Markdown

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

This PR adds compaction detection and context efficiency analysis capabilities: a new result_size_bytes column for tracking message sizes, detection of compaction events during ingestion (via entry_type='compaction'), and 4 new MCP tools/CLI commands for analyzing context efficiency patterns. The implementation addresses all requirements from Issue #69.

Issues Found

Critical

None

Important

None

Suggestions

None

Previous Feedback Status

The previous review identified two suggestions:

  • Missing CLI formatter for get_pre_compaction_events - ✅ Implemented (_format_pre_compaction at cli.py:638-660)
  • Missing read_to_edit_ratio and files_read_multiple_times metrics - ✅ Implemented in get_session_efficiency() at queries.py:2339-2340

Notes

  • Test coverage is comprehensive: 352 tests pass, with specific tests for the new query functions, helper functions (calculate_result_size, detect_compaction), and storage operations
  • get_pre_compaction_events is intentionally excluded from benchmark (cli.py:1348-1350) since it requires specific session_id and timestamp parameters - this is consistent with the existing pattern for parameter-dependent tools
  • Migration v9 properly adds the column with idempotency check

Verdict

APPROVE - Code looks good, no issues found. All previous feedback has been addressed.


Automated review by Claude Code

@evansenter evansenter merged commit 13b6396 into main Jan 10, 2026
3 checks passed
@evansenter evansenter deleted the feat/issue-69-context-efficiency branch January 10, 2026 12:00
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