Session Compactor for Openclaw

An automated session management tool that optimizes token consumption by compacting early message history into concise, high-density summaries.

fangbb-coder
v1.0.0
Apr 2, 2026
0
739
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install session-compactor

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install session-compactor using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Session Compactor?

Session Compactor is a specialized utility designed to manage long-running conversations with AI agents. As dialogues grow, they consume significant portions of the context window and increase operational costs. This skill addresses these challenges by monitoring token counts and programmatically replacing older messages with structured summaries. It ensures that the agent retains critical context, tool execution history, and key facts while freeing up space for new interactions. By integrating Session Compactor into your suite of Openclaw Skills, you can maintain high-performance AI workflows that remain cost-effective and contextually aware over extended periods of time.

Session Compactor Use Cases

  • Managing sessions where message counts exceed 30 and approach model context limits.
  • Reducing operational costs by minimizing repetitive token transmission in long-form dialogues.
  • Preservation of critical tool execution results while discarding verbose or redundant chat history.
  • Manual optimization of conversation history before initiating complex reasoning or coding tasks.

How Session Compactor Works

  1. Token Estimation: The skill employs a heuristic method (approx. 4 characters per token) to calculate the current session length.
  2. Threshold Detection: It constantly checks if the current token count exceeds the user-defined maxTokens limit.
  3. Target Selection: The algorithm identifies older messages for compression while ensuring the most recent messages are kept intact.
  4. Summary Generation: It extracts core session goals, tool call outcomes, and essential facts into a single structured summary.
  5. Message Replacement: Early history is permanently replaced with a system message containing the summary, significantly reducing the token footprint.

Session Compactor Setup

To enable this skill, update your openclaw.config.json configuration file:

{
  "skills": {
    "session-compactor": {
      "enabled": true,
      "maxTokens": 3000,
      "minMessagesToKeep": 5,
      "autoCompact": true
    }
  }
}

To trigger a manual session compression via the CLI, use the following command:

openclaw tools call compact_session '{"force": true}'

Session Compactor Data Schema & Taxonomy

The skill organizes session data through the following parameters and metadata taxonomy:

Parameter Type Default Description
maxTokens number 3000 The token threshold that triggers automatic compression.
minMessagesToKeep number 5 The minimum number of recent messages to preserve in full detail.
autoCompact boolean true Enables or disables background compression on session updates.
force boolean false Allows manual override to compact sessions regardless of token count.

Session Compactor Advanced Features

  • Heuristic Optimization: Uses logic inspired by high-performance implementations to accurately estimate token usage without external API calls.
  • Automatic Lifecycle Management: Seamless background execution ensures Openclaw Skills stay within context limits without user intervention.
  • Irreversible Compression: Maximizes space by permanently removing early message details once they are successfully summarized.
  • Structured Fact Retention: Specifically designed to keep tool call structures and key metadata that generic summarizers might lose.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*