360 Secure SkillHub
360 安全技能中心

context-optimization

该 Skill 是上下文优化中枢:在上下文占用接近 50% 或任务复杂时触发,按 MECW 原则评估上下文压力与合规性,依据占用等级选择 mecw-assessment、mecw-principles、subagent-coordination 等模块,协调子代理工作流、分配 token 预算,并给出大输出文件引用与选择性读取建议。

athola
athola
热度 62.95
最近更新 2026-08-26 21:11:31
分类:效率依赖:读写文件应用场景:工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add nm-conserve-context-optimization
Metadata
name
context-optimization
description
Optimizes context window via MECW principles and memory tiering
version
1.9.8
triggers
["context exceeds 30% or before long multi-step tasks"]
metadata
{"openclaw":{"homepage":"https://github.com/athola/claude-night-market/tree/master/plugins/conserve","emoji":"🦞"}}
source
claude-night-market
source_plugin
conserve

Night Market Skill — ported from claude-night-market/conserve. For the full experience with agents, hooks, and commands, install the Claude Code plugin.

Table of Contents

Context Optimization Hub

When To Use

  • Threshold Alert: When context usage approaches 50% of the window.
  • Complex Tasks: For operations requiring multi-file analysis or long tool chains.

When NOT To Use

  • Simple single-step tasks with low context usage
  • Already using mcp-code-execution for tool chains

Core Hub Responsibilities

  1. Assess context pressure and MECW compliance.
  2. Route to appropriate specialized modules.
  3. Coordinate subagent-based workflows.
  4. Manage token budget allocation across modules.
  5. Synthesize results from modular execution.

Module Selection Strategy

def select_optimal_modules(context_situation, task_complexity):
    if context_situation == "CRITICAL":
        return ['mecw-assessment', 'subagent-coordination']
    elif task_complexity == 'high':
        return ['mecw-principles', 'subagent-coordination']
    else:
        return ['mecw-assessment']

Context Classification

Utilization Status Action
< 30% LOW Continue normally
30-50% MODERATE Monitor, apply principles
> 50% CRITICAL Immediate optimization required

Large Output Handling (Claude Code 2.1.2+)

Behavior Change: Large bash command and tool outputs are saved to disk instead of being truncated; file references are provided for access.

Impact on Context Optimization

Scenario Before 2.1.2 After 2.1.2
Large test output Truncated, partial data Full output via file reference
Verbose build logs Lost after 30K chars Complete, accessible on-demand
Context pressure Less from truncation Same - only loaded when read

Best Practices

  • Avoid pre-emptive reads: Large outputs are referenced, not automatically loaded into context.
  • Read selectively: Use head, tail, or grep on file references.
  • Leverage full data: Quality gates can access complete test results via files.
  • Monitor growth: File references are small, but reading the full files adds to context.

Integration Points

  • Token Conservation: Receives usage strategies, returns MECW-compliant optimizations.
  • CPU/GPU Performance: Aligns context optimization with resource constraints.
  • MCP Code Execution: Delegates complex patterns to specialized MCP modules.

Resources

  • MECW Theory: See modules/mecw-principles.md for core concepts, the 50% rule, and quick-start code examples.
  • Context Analysis: See modules/mecw-assessment.md for risk identification.
  • Workflow Delegation: See modules/subagent-coordination.md for decomposition patterns.
  • Context Waiting: See modules/context-waiting.md for deferred loading strategies.

Troubleshooting

Common Issues

If context usage remains high after optimization, check for large files that were read entirely rather than selectively. If MECW assessments fail, ensure that your environment provides accurate token count metadata. For permission errors when writing output logs to /tmp, verify that the project's temporary directory is writable.