← 返回 Skills 市场
klemenska

Context Window Optimizer

作者 klemenska · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
172
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install context-window-optimizer
功能描述
Optimize context window usage by summarizing old conversation segments, extracting key facts and decisions to permanent memory, and keeping current context l...
使用说明 (SKILL.md)

Context Window Optimizer

Manage context strategically to prevent token waste and keep conversations effective.

Core Principle

Context is a shared resource. Keep it lean so there's room for actual work.

When to Optimize

  • Conversation exceeds ~50 messages
  • Context feels heavy before a new task
  • Starting a complex multi-step task
  • After significant decisions or completions
  • Explicit request to optimize/compact

Optimization Workflow

Step 1: Assess Context State

Run the analyzer to get context metrics:

python3 scripts/analyze_context.py --session current

This reports:

  • Message count and approximate token count
  • Age of oldest message
  • Density score (signal vs noise)

Step 2: Identify Optimization Targets

Look for:

  • Old已完成 tasks with verbose logs
  • Repeated explanations of same concept
  • Off-topic tangents
  • Raw tool outputs that could be summarized
  • Decisions that should move to permanent memory

Step 3: Extract to Memory

Decisions → MEMORY.md or relevant project file:

## Decisions (from 2026-03-25 session)
- Chose PostgreSQL over MongoDB for project X
- Agreed on 3-day sprint cadence
- User prefers detailed explanations, not summaries

Key facts → appropriate domain/project file:

## Project X Facts
- Tech stack: React + Node + Postgres
- Main user pain point: slow onboarding
- Current velocity: 5 story points/sprint

Patterns → ~/self-improving/memory.md:

## User Preferences
- Always explain the "why" before the "what"
- Prefers bullet points over paragraphs

Step 4: Summarize Dense Segments

For long work sessions, create a summary instead of keeping all details:

## Session Summary: 2026-03-25

### Work Completed
- Set up authentication flow
- Fixed memory leak in worker process
- Designed new API schema

### Decisions Made
- Use JWT over sessions (simpler, scales better)
- Defer caching to v2 (not blocking)

### Open Questions
- Final tech stack for notifications (push vs polling)
- Need user feedback on onboarding flow

### Next Steps
- Implement auth endpoints
- Write tests for worker
- Schedule design review

Step 5: Archive, Don't Delete

Never delete context — archive it:

  • Move summaries to memory/YYYY-MM-DD.md
  • Keep pointers in session for recovery
  • Use [[archived:filename.md]] notation

Context Density Rules

Content Type Action
Completed tasks Summarize outcome, archive details
Decisions Extract to MEMORY.md or project file
Key facts Extract to relevant domain/project
Tool logs Summarize if successful, keep if debugging
Repeated concepts Remove duplicates, keep one canonical
Off-topic Skip or summarize in notes
System prompts Never touch
Skills metadata Only load relevant ones

Quick Commands

Task Command
Analyze current context python3 scripts/analyze_context.py --session current
Summarize session python3 scripts/summarize_session.py --session current --output summary.md
Extract decisions python3 scripts/extract_decisions.py --session current

Files

  • scripts/analyze_context.py — Context metrics and optimization suggestions
  • scripts/summarize_session.py — Create session summary
  • scripts/extract_decisions.py — Pull out decisions and key facts
  • references/patterns.md — Common summarization patterns
安全使用建议
This skill appears to implement context summarization as advertised, but it reads your OpenClaw session transcripts and writes persistent memory files without redaction. Before installing or enabling it: (1) inspect the scripts locally (they are included) and confirm you are comfortable with reading ~/.openclaw/agents/main/sessions/*.jsonl; (2) run it first in a controlled/test account or sandbox with non-sensitive sessions; (3) add or request secret/PII redaction (credentials, tokens, long stack traces) before archiving; (4) restrict where memory files are written and ensure the directory has appropriate permissions and encryption if needed; (5) consider running commands with --no-llm / dry-run to preview extracts; (6) require the author to add explicit metadata declaring the config paths accessed and an explanation of retention/cleanup policy. If you deal with sensitive data, do not enable automatic or autonomous invocation of this skill until these mitigations are in place.
功能分析
Type: OpenClaw Skill Name: context-window-optimizer Version: 1.0.0 The skill bundle is designed to manage and optimize the AI agent's context window by analyzing, summarizing, and archiving session history. The Python scripts (analyze_context.py, extract_decisions.py, and summarize_session.py) perform local file operations on session logs located in ~/.openclaw/ and use keyword-based logic to extract relevant information. There is no evidence of data exfiltration, unauthorized network access, or malicious execution patterns.
能力评估
Purpose & Capability
The name/description match the included scripts: analyze_context.py, extract_decisions.py, and summarize_session.py perform analysis, extraction, and summarization of session transcripts. Accessing session transcripts and producing summary/memory files is coherent with the stated purpose. However, the skill does not declare the implicit config path it uses (~/.openclaw/agents/main/sessions/) or the fact that it will write persistent memory files in the user's home directory, which should have been surfaced in the metadata.
Instruction Scope
SKILL.md plus the scripts instruct the agent to read full session transcripts, extract decisions/key facts, and write/archive them to persistent files (e.g., MEMORY.md, ~/self-improving/memory.md, memory/YYYY-MM-DD.md). There is no built-in redaction or secret-filtering: extract_decisions.py explicitly includes tool call arguments and slices content, which can capture commands, tokens, stack traces, or other sensitive data. The instructions encourage moving conversation content into permanent memory — that centralization is a sensitive operation and is not scoped to exclude secrets or PII.
Install Mechanism
No install spec (instruction-only) and included Python scripts run locally. This is low-risk from an installation origin perspective: nothing is downloaded from remote URLs and no package install is automated.
Credentials
The skill requests no environment variables and declares no config paths, yet the scripts directly read ~/.openclaw/agents/main/sessions/*.jsonl and may write to user home paths. That filesystem access is disproportionate to what the metadata advertises (no required config paths). The scripts also parse tool outputs and command arguments (partial command text captured), which increases the chance of harvesting credentials or secrets from session history.
Persistence & Privilege
always:false and the skill does not modify other skills or system settings. However, it is explicitly designed to create and archive persistent memory files (MEMORY.md, memory/YYYY-MM-DD.md, ~/self-improving/memory.md). Persistent storage of extracted content is expected for this use case but raises privacy risk because archived content could include sensitive data and may be accessible to other skills or processes.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install context-window-optimizer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /context-window-optimizer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of context-window-optimizer. - Summarizes old conversation segments and archives unnecessary details to keep context lean. - Extracts key facts and decisions into permanent memory or relevant project files. - Provides clear workflow and scripts for analyzing and optimizing context window usage. - Lists common triggers and quick commands for when and how to optimize context. - Offers rules for context density and methods for archiving, not deleting, context.
元数据
Slug context-window-optimizer
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Context Window Optimizer 是什么?

Optimize context window usage by summarizing old conversation segments, extracting key facts and decisions to permanent memory, and keeping current context l... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 172 次。

如何安装 Context Window Optimizer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install context-window-optimizer」即可一键安装,无需额外配置。

Context Window Optimizer 是免费的吗?

是的,Context Window Optimizer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Context Window Optimizer 支持哪些平台?

Context Window Optimizer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Context Window Optimizer?

由 klemenska(@klemenska)开发并维护,当前版本 v1.0.0。

💬 留言讨论