Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(compact): only auto-compact when context is >=30% of the model's window

Vyapak Goyal62b15df9f502
diff --git a/src/main/config.ts b/src/main/config.ts
index 8b11c83e..af6eb32f 100644
--- a/src/main/config.ts
+++ b/src/main/config.ts
@@ -12,8 +12,10 @@ export interface ScheduledMission {
to: string;
body: string;
enabled: boolean;
- /** When true, the scheduler also sends `/compact` to every live terminal when
- * this mission fires — keeping each agent's context lean on a cadence. */
+ /** When true, the scheduler asks the renderer to `/compact` live terminals when
+ * this mission fires — but only agents whose context has filled past a
+ * threshold (~30% of their model's window) are compacted, so small/idle
+ * sessions are left alone instead of compacting on every tick. */
autoCompact?: boolean;
lastFiredAt?: number;
/** Mission flavor. Absent ⇒ 'dispatch' (the classic interval-dispatch mission,
diff --git a/src/renderer/src/hooks/useHive.ts b/src/renderer/src/hooks/useHive.ts
index 325bb057..1faa1110 100644
--- a/src/renderer/src/hooks/useHive.ts
+++ b/src/renderer/src/hooks/useHive.ts
@@ -42,6 +42,14 @@ const COMPACT_CMD =
'/compact Summarise exactly what you are currently working on and the next step, ' +
'so you can resume from the same point — then continue that work after compacting.';
+// Auto-compact only fires once an agent's live context has filled to at least
+// this fraction of its model's window. It's a FRACTION of contextLimit (which is
+// per-agent/per-model), so a 200k session and a 1M session both compact at the
+// same 30% relative fill — not at a fixed token count. Agents below this, or with
+// no context telemetry yet, are left alone — so the hourly standup no longer
+// compacts every terminal unconditionally.
+const COMPACT_CONTEXT_THRESHOLD = 0.3;
+
// Per-pty submission chain. Every submitToPty for a given pty is appended here so
// two callers (e.g. the boot sequence's /remote-control and the inbox-wake nudge)
// can NEVER interleave their text + Enter — which jammed them onto one line and
@@ -619,6 +627,13 @@ export function useHive(config: HarnessConfig | null): void {
// /compact is a Claude Code slash command — non-Claude CLIs (agy, codex)
// would just receive it as literal prompt text. Skip them.
if (!isClaudeProvider(inferAgentProvider(a.command, a.provider))) continue;
+ // Only compact agents whose context has actually filled past the
+ // threshold. contextLimit is per-model (200k vs the 1M window), so this
+ // gate scales to each agent's own window instead of a fixed token count.
+ // Unknown telemetry (limit not polled yet) ⇒ skip — never compact blind.
+ const limit = a.contextLimit ?? 0;
+ const used = a.contextTokens ?? 0;
+ if (limit <= 0 || used / limit < COMPACT_CONTEXT_THRESHOLD) continue;
const queued = messageQueues[a.id] ?? [];
if (queued.some((m) => m.text.trimStart().startsWith('/compact'))) continue;
enqueueMessage(a.id, COMPACT_CMD);