← Back to Skills Marketplace
lizlzzzz

context-compression-claude-code

by lizlzzzz · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ⚠ suspicious
219
Downloads
0
Stars
0
Active Installs
3
Versions
Install in OpenClaw
/install context-compression-claude-code
Description
Use this skill whenever the conversation context is getting long, when a user asks to "compress", "summarize", or "clean up" the conversation, or when you de...
README (SKILL.md)

Origin: This skill was extracted from Claude Code's internal implementation and rules. Claude Code openly exposes its safety mechanisms (hooks, system prompts, skill definitions) in the ~/.claude/ directory. The tiered compression strategy, layer classification system, and memory file structure were reverse-engineered from Claude Code's PreCompact/PostCompact hooks and session memory handling, then adapted for OpenClaw's multi-channel environment.

Context Compression

Why Tiered Compression Is Needed

A one-size-fits-all approach to dropping context either leaves the agent without memory or burns through context too quickly. The core principle of tiered strategy is: different information has different lifecycles. A user's statement "I prefer concise responses" is worth remembering forever; but a resolved error message from three days ago has no value today.


Before Compression: Identify the Scenario

Before starting compression, determine which conversation scenario you're in, as retention strategies differ:

Scenario Characteristics Compression Tendency
Task-oriented Clear goal, step-driven Keep goal and incomplete steps, compress process details
Chat-oriented Open topics, no clear task Keep only user preference signals, discard aggressively
Research-oriented Gathering information, continuous accumulation Keep conclusions and sources, compress procedural discussions
Group-chat Multiple people, high noise Discard aggressively, keep only directly relevant content

Three-Layer Compression Strategy

Layer 1: Must Preserve (Keep Original)

These contents remain in original or near-original form after compression:

  • User's explicitly stated goals, requirements, deadlines
  • Incomplete tasks (in-progress, interrupted)
  • Confirmed important decisions ("We decided to go with Plan B")
  • User-expressed explicit preferences ("I don't like X", "Always use Y format going forward")
  • Key credentials or config (accounts, paths, special settings)

Layer 2: Compress to Summary (Extract and Keep)

Keep conclusions, discard process:

  • Completed tasks → One-sentence conclusion ("Completed X, result was Y")
  • Long explanations → Core point in 1-2 sentences
  • Tool call outputs → Keep only final results, discard intermediate steps
  • Repeated topics → Merge into one record

Layer 3: Discard Directly

  • Small talk, thanks, acknowledgment messages ("ok", "thanks", "got it")
  • Rejected or obsolete proposals
  • Multiple attempts at the same question (keep only the final effective one)
  • Pure transitional content ("let me think", "hold on")
  • Resolved error messages that won't be needed again

Compression Execution Steps

Step 1: Scan All Conversation Identify all Layer 1 content, make a checklist — this cannot be discarded.

Step 2: Process Layer 2 For each conversation segment, judge: Is there a conclusion worth keeping? If yes, distill into one sentence.

Step 3: Generate Compressed Summary In chronological order, combine Layer 1 content + Layer 2 extractions into a compact context summary, typically no more than 600 characters.

Step 4: Update Memory File Write high-persistence-value information (user preferences, long-term goals, important decisions) to the memory file. See memory-template.md for format.

Step 5: Inform the User Briefly explain what was compressed and what key information was preserved, so the user knows the context has been updated.


OpenClaw Multi-Channel Supplementary Rules

OpenClaw runs across multiple messaging platforms, pay extra attention:

Group chat scenarios: Other members' messages default to Layer 3 (discard) unless the user explicitly responds to or quotes that message.

Cross-day conversations: Judge by topic unit, not time unit. An unfinished task from yesterday belongs to Layer 1; a completed topic from yesterday drops one level today.

Channel switching: If the user asks similar questions on different channels (WhatsApp vs Telegram), it indicates genuine concern — promote priority to Layer 1.


Optional: Auto-Trigger (Hook Configuration)

If you use Claude Code or an agent that supports PreCompact hooks, you can configure auto-trigger. See setup-hook.md for details.

Without hook configuration, you can trigger manually: just tell the agent "compress my context" or "context is getting long, clean it up".

Usage Guidance
This skill mostly does what its name claims (compress conversation context), but it recommends persisting 'key credentials or config' into a memory file and instructs editing user hook configuration to auto-trigger — both increase risk. Before installing or enabling hooks: 1) Do not store secrets (passwords, API keys, tokens, private paths) in the memory file — redact them or omit Layer 1 credential entries. 2) Inspect and back up any config files (e.g., ~/.claude/settings.json) before applying hook changes. 3) If you allow the skill to write memory, ensure the memory file path and file permissions are restricted to your user. 4) Prefer manual invocation until you trust the exact behavior; ask the author to clarify why credentials must be preserved and what protections are used. 5) If you need help, test in an isolated account or environment first. These steps will reduce the chance sensitive data is retained or automatically processed.
Capability Assessment
Purpose & Capability
Name/description promise: compress conversation context and produce a memory file. Actual requirements: none (instruction-only). However, the skill explicitly recommends preserving 'Key credentials or config' in Layer 1 and writing those to a persistent memory file under ~/.claude/..., which is not obviously necessary for a compression utility and expands the skill's scope into storing potentially sensitive secrets.
Instruction Scope
SKILL.md instructs the agent to scan the entire conversation, generate compressed summaries, and update a persistent memory file (memory-template.md) under the user's home directory. It also provides optional hook setup that edits ~/.claude/settings.json to run a command on PreCompact. Writing conversation-derived data (and especially credentials/config) to disk and modifying hook settings is beyond a minimal 'summarize' action and increases privacy risk.
Install Mechanism
Instruction-only skill with no install spec, no downloaded code, and no extra binaries required — low installation risk. The provided setup-hook uses existing system files and a local python invocation, but nothing is downloaded or executed from remote sources.
Credentials
The skill requires no environment variables or external credentials, which is good, but it instructs preserving and storing 'Key credentials or config (accounts, paths, special settings)' in a persistent memory file. Requesting or recommending persistent storage of secrets is disproportionate to context compression and could lead to unintentional credential retention/exfiltration if the agent or environment is compromised.
Persistence & Privilege
The skill isn't 'always: true' and is user-invocable by default. However, the optional setup-hook instructions modify user hook configuration to auto-trigger compression, which would give the skill persistent automatic invocation if the user applies those changes. That behavior is optional but significant if enabled.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install context-compression-claude-code
  3. After installation, invoke the skill by name or use /context-compression-claude-code
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.2
- Full documentation rewritten in English for broader accessibility and clarity. - Added an “Origin” note detailing the skill’s extraction from Claude Code and its adaptation for OpenClaw. - Translated and refined all step-by-step instructions, tables, and strategy explanations. - Kept all compression rules and tiered strategies unchanged in logic, but clarified wording and structure. - Supplemented documentation to explain OpenClaw’s multi-channel rules and use-cases.
v1.0.1
- No file changes or functional modifications in this version. - Documentation and usage instructions remain unchanged. - No new features, bug fixes, or updates introduced.
v1.0.0
- Major simplification: The skill has been restructured from a detailed shell script collection to a strategy guide with markdown templates. - All previous shell scripts and configuration files have been removed. - Added documentation files: memory-template.md and setup-hook.md. - SKILL.md now outlines a tiered context compression strategy and manual/automatic usage scenarios instead of implementation details. - The new version is documentation-focused and does not include executable components.
Metadata
Slug context-compression-claude-code
Version 1.0.2
License MIT-0
All-time Installs 1
Active Installs 0
Total Versions 3
Frequently Asked Questions

What is context-compression-claude-code?

Use this skill whenever the conversation context is getting long, when a user asks to "compress", "summarize", or "clean up" the conversation, or when you de... It is an AI Agent Skill for Claude Code / OpenClaw, with 219 downloads so far.

How do I install context-compression-claude-code?

Run "/install context-compression-claude-code" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is context-compression-claude-code free?

Yes, context-compression-claude-code is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does context-compression-claude-code support?

context-compression-claude-code is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created context-compression-claude-code?

It is built and maintained by lizlzzzz (@lizlzzzz); the current version is v1.0.2.

💬 Comments