Strategic compact

From hashgraph-online/awesome-codex-plugins · View interactive version

Strategic compact is an AI agent skill from the GitHub repository hashgraph-online/awesome-codex-plugins. 上下文优化技能,通过 trigger-based 懒加载和 context composition awareness 自动重组长会话上下文。

How to use this skill

Skill file

Strategic Compact Skill

上下文优化技能,通过 trigger-based 懒加载和 context composition awareness 自动重组长会话上下文。

何时激活

核心功能

1. Trigger-Based 懒加载

Claude Code 默认由原生 auto-compact 决定压缩时机;下列百分比 trigger 只用于手动兜底模式:

| Trigger | 条件 | 行为 |

|---------|------|------|

| context_65% | 上下文使用 > 65% | 触发 advisory 压缩建议 |

| context_70% | 上下文使用 > 70% | 触发压缩建议 |

| context_85% | 上下文使用 > 85% | 强烈建议手动压缩 |

| logical_break | 检测到逻辑断点 | 建议整理 |

| specialist_done | specialist 完成 | 归档输出 |

2. Context Composition Awareness

理解上下文不同部分的价值:

高价值(总是保留):

中等价值(根据大小决定):

低价值(安全丢弃):

压缩策略

Phase 1: 保存决策到内存

提取所有决策,保存到 ~/.claude/memory/error_experience/decisions/

Phase 2: 保存待办到摘要

提取 pending items 和 next hints,保存到 session summary

Phase 3: 压缩对话

保留系统提示和最近 20 轮对话,压缩中间部分

Phase 4: 精简工具输出

将长工具输出替换为摘要:[File X read, Y lines]

与 Other Skills 的关系

| Skill | 关系 |

|-------|------|

| Memory Persistence | Strategic Compact 使用其存储来保存决策和摘要 |

| Error Experience Library | 从压缩的上下文中提取错误模式 |

| Continuous Learning | Instincts 从归档的上下文中生成 |

使用场景

场景 1:长会话自动整理

用户:连续工作 2 小时后
Claude Code:上下文接近原生 auto-compact 阈值
系统:触发 PreCompact(auto),保存 compact 轮次并清理旧计量缓存
Claude Code:自动执行压缩
系统:下一轮只读取压缩后的新 usage,不复用压缩前的高水位

场景 2:Specialist 输出归档

用户:运行 /code-review
Specialist:输出详细代码审查报告
系统:检测到 specialist_done trigger
系统:提取关键结论,丢弃详细追踪
系统:保存结论到 memory store

Context 计算与 Compact 轮次

手动兜底阈值

| 使用率 | 紧迫度 | 建议操作 |

|--------|--------|---------|

| < 65% | low | 无需操作 |

| 65-70% | advisory | 提醒控制上下文增长 |

| 70-85% | medium | 建议压缩,可选择性执行 |

| 85-95% | high | 强烈建议压缩 |

| > 95% | critical | 必须立即压缩 |

命令接入

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.