context-window-optimizer

Optimize context window usage by summarizing old conversation segments, extracting key facts and decisions to permanent memory, and keeping current context lean. Triggers when: (1) conversation history grows beyond ~50 messages or context feels heavy; (2) before long or complex tasks; (3) after significant decisions or work completions; (4) when explicitly asked to optimize context, compact context, or clean up context.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "context-window-optimizer" with this command: npx skills add klemenska/context-window-optimizer

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 TypeAction
Completed tasksSummarize outcome, archive details
DecisionsExtract to MEMORY.md or project file
Key factsExtract to relevant domain/project
Tool logsSummarize if successful, keep if debugging
Repeated conceptsRemove duplicates, keep one canonical
Off-topicSkip or summarize in notes
System promptsNever touch
Skills metadataOnly load relevant ones

Quick Commands

TaskCommand
Analyze current contextpython3 scripts/analyze_context.py --session current
Summarize sessionpython3 scripts/summarize_session.py --session current --output summary.md
Extract decisionspython3 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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Gigo Lobster Resume

🦞 GIGO · gigo-lobster-resume: 续跑入口:v2 stable 当前会清理旧 checkpoint 并从头重跑;保留此 slug 作为旧 checkpoint 兼容入口。 Triggers: 继续试吃 / 恢复评测 / resume tasting / continue lobster...

Registry SourceRecently Updated
General

YiHui CONTEXT MODE

context-mode is an MCP server that saves 98% of your context window by sandboxing tool outputs. It routes large file reads, shell outputs, and web fetches th...

Registry SourceRecently Updated
General

xinyi-drink

Use when users ask about 新一好喝/新一咖啡 drinks, stores, menu, activities, Skill用户大礼包, today drink recommendations, afternoon tea, feeling sleepy, or personalized...

Registry SourceRecently Updated
General

vedic-destiny

吠陀命盘分析中文入口。用于完整命盘研判、命主盘 Rashi chart 与九分盘 Navamsha chart 联读、既往事件回看、出生时间稳定度判断、事业主题、婚姻主题、时空盘专题,以及基于 Jagannatha Hora PDF、星盘截图或文本命盘数据的系统拆盘。当用户提到完整星盘、事业方向、婚姻问题、关系窗...

Registry SourceRecently Updated