[FEATURE] Auto-compact on idle timeout
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Feature Request: Auto-compact on idle timeout
Summary
Add a configurable idle timeout that automatically runs /compact on a Claude Code session when no user input or tool activity has occurred for a specified number of minutes.
Motivation
Long-running Claude Code sessions accumulate context over time. When a session sits idle — the user steps away, gets on a call, or switches tasks — the context window continues to hold everything from the session, consuming tokens unnecessarily when the conversation resumes.
Currently, users must remember to manually run /compact before context gets too large. In practice this rarely happens, and sessions frequently hit context limits mid-task.
An automatic idle-triggered compact would solve this transparently.
Proposed Behavior
- Add a
settings.jsonoption, e.g.:
``json``
"idleCompactMinutes": 15
- If no user input and no tool activity occurs for that duration, Claude Code automatically runs
/compact - A brief notice is shown when the session resumes: "Session was compacted after 15 minutes of inactivity."
- Setting
0or omitting the key disables the feature (opt-in)
Why This Is Hard to Implement Today Without Native Support
The detection side is approximatable via hooks (writing a timestamp on PostToolUse / UserPromptSubmit and checking it from a cron job). However, there is currently no way to inject a /compact command into a running session from outside the process. Native support is required.
Expected Benefit
- Reduces mid-session context limit surprises
- Lowers token costs for users with long-running sessions
- No user action required — works transparently in the background
Environment
- Platform: macOS
- Claude Code CLI
- Relevant setting location:
~/.claude/settings.json
Proposed Solution
Proposed Behavior
Add a settings.json option, e.g.:
"idleCompactMinutes": 15
If no user input and no tool activity occurs for that duration, Claude Code automatically runs /compact
A brief notice is shown when the session resumes: "Session was compacted after 15 minutes of inactivity."
Setting 0 or omitting the key disables the feature (opt-in)
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
_No response_
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗