home / skills / openclaw / skills / context-budgeting-v2
This skill helps manage and optimize the OpenClaw context window by partitioning, checkpointing, and lifecycle rules to reduce costs and latency.
npx playbooks add skill openclaw/skills --skill context-budgeting-v2Review the files below or copy the command above to add this skill to your agents.
---
name: context-budgeting
description: Manage and optimize OpenClaw context window usage via partitioning, pre-compression checkpointing, and information lifecycle management. Use when the session context is near its limit (>80%), when the agent experiences "memory loss" after compaction, or when aiming to reduce token costs and latency for long-running tasks.
---
# Context Budgeting Skill
This skill provides a systematic framework for managing the finite context window (RAM) of an OpenClaw agent.
## Core Concepts
### 1. Information Partitioning
- **Objective/Goal (10%)**: Core task instructions and active constraints.
- **Short-term History (40%)**: Recent 5-10 turns of raw dialogue.
- **Decision Logs (20%)**: Summarized outcomes of past steps ("Tried X, failed because Y").
- **Background/Knowledge (20%)**: High-relevance snippets from MEMORY.md.
### 2. Pre-compression Checkpointing (Mandatory)
Before any compaction (manual or automatic), the agent MUST:
1. **Generate Checkpoint**: Update `memory/hot/HOT_MEMORY.md` with:
- **Status**: Current task progress.
- **Key Decision**: Significant choices made.
- **Next Step**: Immediate action required.
2. **Run Automation**: Execute `scripts/gc_and_checkpoint.sh` to trigger the physical cleanup.
## Automation Tool: `gc_and_checkpoint.sh`
Located at: `skills/context-budgeting/scripts/gc_and_checkpoint.sh`
**Usage**:
- Run this script after updating `HOT_MEMORY.md` to finalize the compaction process without restarting the session.
## Integration with Heartbeat
Heartbeat (every 30m) acts as the Garbage Collector (GC):
1. Check `/status`. If Context > 80%, trigger the **Checkpointing** procedure.
2. Clear raw data (e.g., multi-megabyte JSON outputs) once the summary is extracted.
This skill manages and optimizes an OpenClaw agent's finite context window through partitioning, checkpointing, and lifecycle rules. It reduces token cost and latency for long-running sessions while preventing memory loss after compaction. Use it to keep critical instructions hot and archive less-relevant data safely.
The skill divides session content into prioritized partitions (objective, short-term history, decision logs, background knowledge) and enforces size targets for each. Before any compaction it requires a mandatory pre-compression checkpoint that records status, key decisions, and next steps to a hot-memory file. An automation script finalizes the cleanup, and a heartbeat process monitors context usage to trigger checkpointing when thresholds are exceeded.
What must a checkpoint include?
A checkpoint must record current status, the key decision(s) made, and the immediate next step in the hot-memory file.
When does the heartbeat trigger checkpointing?
Heartbeat checks context usage every 30 minutes and triggers checkpointing when context exceeds about 80%.