Skip to content

Feature: Configurable early auto-compaction threshold (don't wait until 200K tokens) #30411

Description

@kaykas

Problem

Auto-compaction only fires when the session hits the context limit (~200K tokens). By that point:

  • Responses are already 5–10x slower than at session start (sending 180K+ tokens per request)
  • The compaction itself may fail if the session contains thinking blocks
  • The user experience is: things get progressively slower with no warning, then freeze

There is no config option to trigger compaction earlier (e.g. at 60% or 70% of the context window).

Real-world impact

Running claude-sonnet-4-6 (200K context). Sessions become noticeably slow at ~120–130K tokens and unusable at ~150K+. Auto-compaction at 200K is too late — by then responses take 5–10 minutes on a Telegram session.

Today: 3 separate manual interventions needed across the same session (12:43pm, 3:18pm, 11:17pm) because the session kept re-bloating between compactions. No way to prevent this without constant manual monitoring.

Proposed fix

Add a config option to trigger auto-compaction at a percentage or absolute token threshold:

{
  "agents": {
    "defaults": {
      "compaction": {
        "autoCompactThreshold": 0.70
      }
    }
  }
}

When totalTokens crosses contextTokens * autoCompactThreshold, OpenClaw automatically compacts before the next response — not after hitting the wall.

Why this matters more than it seems

The current UX is: session gets slow → user notices something is wrong → user has to know to type /compact → if the session has thinking blocks, /compact silently fails → user is stuck.

With early auto-compaction: sessions stay fast indefinitely, no manual intervention required, thinking-block sessions get reset before they become unrecoverable.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions