compaction-trigger

Reviewed at commit 24a93f7

Caution: Copies a TYPESAFE_API_KEY from your Claude settings into the session environment before compacting, so another compaction plugin can use it.

Requests a session compaction when the live context passes a token threshold, so verbatim compaction plugins run near the working ceiling instead of at the…

What we checked

Asks Claude Code to compact the conversation once the context passes a token threshold (150,000 by default), at most once every few turns, and logs a line when it does. It also hides another plugin's per-message decision dump from the transcript. It makes no network calls itself, but it reads your Claude settings for a TypeSafe API key.

Review details

Static review of the source at the pinned commit; not run. Delta review of the changes since 3a7dc7b; the rest carries over from the review at that commit. The change refactors the compaction bookkeeping into a small idle/compacting state, makes the turn.complete handler ignore sub-agent turns (agentId) and turns that arrive while a compaction is running, and moves the key-sync try/catch inside the compaction path so a failed sync is logged and compaction still proceeds; on an error the turn counter is restored. Behaviour toward the key is unchanged. Carried over: one module (hooks/trigger.ts, no runtime imports) registers ui.log and turn.complete. On turn.complete it reads $.session.usage(), and when context tokens reach the threshold and enough turns have passed it calls $.session.compact(), logging the result with $.ui.log. Before compacting it calls $.settings.read(), extracts only env.TYPESAFE_API_KEY, and if it differs from the process env value sets it with $.env.set so a separate verbatim compaction plugin does not use a stale key; the key is never logged or sent by this plugin. A ui.log handler redirects lines starting with 'decisions:' to the debug log. Errors are caught and logged and the turn continues. Threshold and spacing come from userConfig.

What it uses
  • Reads your prompts: no
  • Sees tool calls: no
  • Blocks or changes tool calls: no
  • Reads or writes files: yes
  • Runs programs on your machine: no
  • Calls the model (uses tokens): no
  • Sends data over the network: no
  • Stores data: no
  • Shows something on screen: yes
Hooked events

Requests a session compaction when the live context passes a token threshold, so verbatim compaction plugins run near the working ceiling instead of at the model window.

Made this mod? Add a badge to your README

modsforClaude badge for compaction-trigger

Paste this into your README. The badge says reviewed once the current version has been reviewed, and links readers to this page.

[![Listed on modsforClaude](https://modsforclaude.com/badge/compaction-trigger.svg)](https://modsforclaude.com/mods/compaction-trigger/)

← All mods