Skip to content

suggest-compact: counter temp files never cleaned up, and count resets every /compactΒ #2156

Description

@jbegarek

Summary

Two small, related issues with the counter file in scripts/hooks/suggest-compact.js.

1. Counter temp files are never cleaned up

Each session writes claude-tool-count-<sessionId> into the temp dir (getTempDir()), and nothing ever removes it. Over time these accumulate β€” at least one file per session, indefinitely.

Suggestion: sweep on run β€” delete claude-tool-count-* files older than N days (env-tunable, e.g. COMPACT_STATE_TTL_DAYS, default 14) at the start of main(). Cheap and keeps the temp dir bounded.

2. The count resets on every /compact

The counter is keyed on session_id, which rotates when a session is compacted or resumed. So the "50 calls, then every 25" cadence restarts from zero after each /compact. In compact-heavy / long multi-phase workflows the count signal often never reaches the threshold, which is ironic for a compaction helper.

Suggestion: key the cumulative count on something stable across compaction β€” e.g. project path + calendar day (claude-tool-count-<projHash>-<YYYYMMDD>) β€” so it survives the session-id rotation. (A context-size signal, proposed separately in #2155, would address window pressure more robustly regardless of count.)

Both are minor; happy to PR either or both.

Filed after auditing a local copy of the skill; surfaced via Claude Code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions