Auto-compact sessions after idle timeout

Resolved 💬 2 comments Opened Apr 7, 2026 by williamsommers-hmq Closed May 20, 2026

Summary

Add a configurable setting to automatically compact conversation context after a period of inactivity (e.g., auto_compact_idle_minutes: 60).

Motivation

Long-running Claude Code sessions accumulate context while the user is away (meetings, lunch, overnight). When they return, the session is bloated with stale context that could have been compacted. Today:

  • /compact is a CLI command that must be manually invoked
  • CronCreate jobs can't invoke CLI commands — they only have access to tools
  • A cron-based workaround would add to context on each check, making the problem worse
  • Hooks don't have an idle or timer event to trigger on

Proposed Behavior

// ~/.claude/settings.json
{
  "auto_compact_idle_minutes": 60  // compact after 60min of no user input
}
  • Track time since last user message
  • When idle threshold is exceeded and context is above some minimum size (e.g., >20% of window), trigger compaction automatically
  • Only compact once per idle period (don't re-compact if already compacted)
  • Log that auto-compaction occurred so the user sees it when they return

Alternatives Considered

  • Skill/cron approach: Not viable — cron prompts add to context and can't invoke /compact
  • Hook-based: No session_idle event exists today; could also be a path forward if a timer-based hook event were added
  • External process: User could write a script that watches for idle sessions, but this is fragile and undocumented

Additional Context

Power users with long-lived sessions (8+ hours) would benefit most. This is especially relevant when sessions have durable cron jobs that fire periodically — those add context over time even when the user isn't actively working.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗