[FEATURE] Idle / timeout / debounced hook event to enable customized handoffs, etc.
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
Problem
Claude Code has no hook event that fires on inactivity. Because the model is
stateless, every turn re-sends the full conversation, and the prompt cache goes
cold after the TTL (5 min on API keys, 1 hour on a subscription). If I step away
and resume a large session the next day, turn 1 re-reads the entire history at
full input rate. The expensive failure mode is forgetting a fat session is open
and resuming it cold.
I'd like to customize handoffs, cleanup, etc. after N minutes of inactivity,
while the cache is still warm, so I can have my customized /handoff ready next time I
come back to /clear and avoid being stuck with native /compact
without ever paying the cold re-read. Today this is impossible from inside Claude
Code: the hook events (SessionStart, SessionEnd, UserPromptSubmit, Stop,
StopFailure, PreCompact, ...) have no idle/timeout trigger, so it requires an
external launchd/cron watcher polling the transcript JSONL.
Why it matters
Direct token savings, prevents forgotten cold-thread re-reads, and unlocks
clean async handoff workflows (e.g. handing in-flight work to a fresh session or
another agent).
Proposed Solution
Random ideas:
- An
Idlehook event that fires after a configurable inactivity threshold (e.g.idleThresholdMsin settings.json). Payload should includesession_idandtranscript_pathso the hook can generate a handoff, auto-compact, or notify. - Optional built-in "auto-handoff/auto-compact on idle" setting that uses (1).
- Customizable compact / auto-compact before cache cools
- Add a
PreCacheCoolinghook - Bonus: a summarize-before-resume option in the
--resumepicker (this used to feel available and is now gone), so reopening an old session can start from a compacted summary instead of full history.
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
Interactive mode (TUI)
Use Case Example
- I'm deep in a large Claude Code session with my custom /handoff command
configured (it writes a tailored handoff doc, not the native /compact summary).
- I get pulled away mid-task and don't return for an hour. The prompt cache
goes cold; my session is still open but I've forgotten about it.
- With an
Idlehook firing after, say, 10 min of inactivity, Claude Code
runs my /handoff automatically while the cache is still warm, then I can
safely /clear.
- When I come back the next day, I resume from my pre-built handoff instead of
a full cold re-read of the entire history at full input rate.
- This saves me time and tokens because the expensive cold re-read never
happens, and I'm never stuck with the native /compact when I'd rather use my
own handoff format.
Additional Context
_No response_