claude-code - 💡(How to fix) Fix [FEATURE] Auto-compact on idle timeout [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45040Fetched 2026-04-09 08:14:41
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

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.

Root Cause

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.

Code Example

"idleCompactMinutes": 15
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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.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)

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

extent analysis

TL;DR

Implement a configurable idle timeout feature in Claude Code to automatically run the /compact command when no user input or tool activity occurs for a specified duration.

Guidance

  • To implement this feature, add a settings.json option, e.g., "idleCompactMinutes": 15, to allow users to configure the idle timeout duration.
  • Create a mechanism to detect idle time, potentially using hooks like PostToolUse and UserPromptSubmit to track user activity.
  • Develop a way to inject the /compact command into a running session, which may require native support or an external script.
  • Display a brief notice when the session resumes after being compacted, e.g., "Session was compacted after 15 minutes of inactivity."

Example

// Example settings.json configuration
{
  "idleCompactMinutes": 15
}

Notes

The implementation of this feature may require native support or significant changes to the existing codebase. The proposed solution relies on the ability to detect idle time and inject commands into a running session, which may not be straightforward to achieve.

Recommendation

Apply a workaround by creating an external script that periodically checks for idle time and runs the /compact command manually, as native support for this feature is not currently available. This approach can help mitigate the issue until a more integrated solution is implemented.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING