Skip to content

feat: session auto-rotation with optional summary generation#43

Open
artemasmith wants to merge 2 commits intomoazbuilds:masterfrom
artemasmith:feature/session-auto-rotation
Open

feat: session auto-rotation with optional summary generation#43
artemasmith wants to merge 2 commits intomoazbuilds:masterfrom
artemasmith:feature/session-auto-rotation

Conversation

@artemasmith
Copy link
Copy Markdown
Contributor

Problem

Long-running ClaudeClaw sessions degrade as context fills up — Claude starts contradicting itself and producing lower quality responses. The built-in compression only kicks in near the context limit, not preventing gradual degradation.

Solution

Automatic session rotation based on configurable thresholds:

  • Message count — rotates after N messages (default: 50)
  • Session age — rotates after N hours (default: 24)

When summaryPath is configured, the expiring session generates a markdown summary before rotating. The latest summary is loaded into the bootstrap prompt of the new session, preserving context continuity.

Changes

  • src/sessions.ts — added messageCount to GlobalSession, incremented on each getSession()
  • src/config.ts — added SessionConfig interface and parsing
  • src/rotation.ts — new file: needsRotation(), rotateSession(), loadLatestSummary()
  • src/runner.ts — rotation check before execClaude(), summary loading in bootstrap()
  • prompts/SUMMARY.md — prompt template for summary generation

Configuration

New session section in settings.json:

{
  "session": {
    "autoRotate": true,
    "maxMessages": 50,
    "maxAgeHours": 24,
    "summaryPath": "/path/to/summaries"
  }
}

All fields are optional with sensible defaults. When summaryPath is empty (default), rotation happens without summary generation.

Backward Compatibility

  • messageCount defaults to 0 for existing sessions via || 0 fallback
  • Feature is opt-in: autoRotate defaults to true but does nothing without the config section
  • No changes to existing behavior when session config is absent

Sessions degrade over time as context fills up. This adds automatic
rotation based on message count (default 50) and session age (default 24h).

When summaryPath is configured, generates a markdown summary of the
expiring session via `claude --resume` before rotating, and loads the
latest summary into the bootstrap prompt of the new session.

New config section in settings.json:
  session.autoRotate (bool, default true)
  session.maxMessages (number, default 50)
  session.maxAgeHours (number, default 24)
  session.summaryPath (string, default "" = no summaries)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fenrur added a commit to Fenrur/claudeclaw that referenced this pull request Mar 17, 2026
…builds#43)

- Auto-rotate sessions based on message count and age
- Generate session summaries before rotation
- SessionConfig with autoRotate, maxMessages, maxAgeHours, summaryPath
- peekSession for pre-rotation inspection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@miraculix95
Copy link
Copy Markdown

sounds awesome ... like a great idea ... how does the dev_process work, you create changes on a branch and then moaz is reviewing them for the next release if time allows?

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.

2 participants