adaptive-compaction
Adaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
What this skill does
<!-- Suggested allowed-tools: Read, Bash, Write, Edit. Suggested model: strong everyday coding model; upgrade for architecture review, not routine hook/script operation. --> # Adaptive Compaction Use this skill to install, inspect, or operate the adaptive compaction policy and recovery layer for coding agents. Keep the layer add-on only: decide when to preserve, prune, compact, fork, or ask; never rewrite the host agent core. ## Operating Rules Follow these rules before taking action: 1. Preserve state before any risky compaction path. 2. Run zero-LLM pruning before any LLM summary recommendation. 3. Treat relevance as advisory. Never use low relevance alone for destructive action. 4. Prefer fork/reset on topic shift when headroom is healthy. 5. Enforce `FORCED_COMPACT` only on hook-rich hosts. Degrade Codex and MCP-only hosts to advise/persist. 6. Keep stable instructions before volatile state to avoid prompt-cache churn. 7. Log every decision with thresholds and host capability tier. 8. Use portable paths such as `<skill-dir>/scripts/decide.py`; do not hardcode install paths. 9. When the per-turn `additionalContext` reports a non-NOOP action, **lead your next reply by surfacing it to the user in their language** (forced compaction needed, fork recommended, decision needs confirmation). Then continue with the user's actual request. Do not silently swallow these signals — that is the only channel by which the skill can ask the user to act. ## Load References Conditionally Do not read every reference by default. Load only the rows needed for the current request. | Task | Read | |---|---| | Check JSON contracts or script I/O | `<skill-dir>/references/contract.md` | | Explain or tune the four-signal decision table | `<skill-dir>/references/decision-policy.md` | | Make or review host portability claims | `<skill-dir>/references/capability-matrix.md` | | Validate release safety or risk coverage | `<skill-dir>/references/risk-acceptance-tests.md` | | Plan trace evaluation or v1 to v2 gates | `<skill-dir>/references/eval-protocol.md` | | Install Claude Code hooks | `<skill-dir>/assets/hooks/claude-code/settings.json` and the three shell scripts in that folder | | Install Codex hooks/config | `<skill-dir>/assets/hooks/codex/hooks.json` and `<skill-dir>/assets/hooks/codex/config.toml` | | Run deterministic fixture checks | `<skill-dir>/scripts/fixtures/*.json` | ## Workflow ### 1. Classify Host Capability Classify the host before choosing behavior: | Host | Tier | Behavior | |---|---|---| | Claude Code with lifecycle hooks | `hook-rich` | Allow snapshot-first `FORCED_COMPACT` through PreCompact block/allow. | | Codex CLI | `advise-persist` | Save state, log advice, shape prompts/config; do not claim opaque server control. | | Codex server compaction | `advise-persist` | Snapshot before and verify after when observable. | | MCP-only host | `persist-only` | Save/search/state only; no native compaction claim. | | Unknown host | `persist-only` | Downgrade conservatively and ask before destructive action. | Load `<skill-dir>/references/capability-matrix.md` when the host behavior is disputed or user-facing. ### 2. Score Signals Prepare host telemetry matching `<skill-dir>/references/contract.md`, then run: ```bash python3 <skill-dir>/scripts/score_signals.py < telemetry.json > signals.json ``` Use the scorer output as the only input to the decision table. Do not add model calls in v1. ### 3. Decide Action Run: ```bash python3 <skill-dir>/scripts/decide.py < signals.json > decision.json ``` Accept only these actions: - `NOOP` - `ZERO_LLM_PRUNE` - `SAVE_STATE` - `PREPARE_FOR_COMPACT` - `FORCED_COMPACT` - `FORK_OR_RESET` - `ASK_USER` If `FORCED_COMPACT` appears outside `hook-rich`, treat it as a bug. The decider should downgrade it to `PREPARE_FOR_COMPACT`. ### 4. Act on the Decision Use this table: | Decision | Action | |---|---| | `NOOP` | Continue without compaction. | | `ZERO_LLM_PRUNE` | Run `<skill-dir>/scripts/prune_zero_llm.py`; replace in-context blobs only with restore pointers. | | `SAVE_STATE` | Run `<skill-dir>/scripts/state_packet.py`; write `TASK_STATE.md` plus transcript pointer. | | `PREPARE_FOR_COMPACT` | Run `state_packet.py`, then advise the host/native compactor. | | `FORCED_COMPACT` | Allow only in Claude Code PreCompact after `state_packet.py` succeeds. | | `FORK_OR_RESET` | Recommend a fresh task/session and preserve old state if useful. | | `ASK_USER` | Ask before destructive action. | For pruning: ```bash python3 <skill-dir>/scripts/prune_zero_llm.py < telemetry.json > prune.json ``` For state: ```bash python3 <skill-dir>/scripts/state_packet.py < state-input.json > state-result.json ``` ### 5. Log the Decision Always append a JSONL decision entry: ```bash python3 <skill-dir>/scripts/decision_log.py < log-input.json > log-result.json ``` Include the selected action, headroom, relevance, burden, continuity flags, host tier, thresholds, and snapshot requirement. ## Hook Assets ### Claude Code Use `<skill-dir>/assets/hooks/claude-code/` for hook-rich enforcement: - `pre-compact.sh` calls `<skill-dir>/scripts/hook_bridge.py claude-pre-compact`. - `session-start.sh` calls `<skill-dir>/scripts/hook_bridge.py claude-session-start`. - `user-prompt-submit.sh` calls `<skill-dir>/scripts/hook_bridge.py claude-user-prompt-submit`. - `settings.json` shows the hook configuration snippet. The PreCompact path is the only v1 host-scoped native `FORCED_COMPACT` path. It snapshots first, then allows or blocks compaction according to the decision table. Set `ADAPTIVE_COMPACTION_SKILL_DIR=<skill-dir>` if the shell scripts are copied outside the skill folder. Set `ADAPTIVE_COMPACTION_DIR` to choose the runtime directory for `TASK_STATE.md`, transcript dumps, decision logs, and quarantine files. ### Codex Use `<skill-dir>/assets/hooks/codex/` for advise/persist integration: - `hooks.json` routes session, prompt, and stop events into `<skill-dir>/scripts/hook_bridge.py`. - `config.toml` contains a compact prompt snippet that asks native compaction to preserve the state packet shape. Never claim Codex server compaction content is controlled or auditable. Snapshot externally and log advice. ### Hook Bridge Use `<skill-dir>/scripts/hook_bridge.py` only as a host adapter. It normalizes hook JSON, imports the scorer/decider/pruner/state/log scripts, writes runtime artifacts, and emits hook-friendly JSON. Keep policy in the scripts and references, not in host assets. ## How the Decision Is Made (so you can reason about it) Runtime autonomy does NOT come from the agent deciding anything per turn. The host harness fires hooks deterministically; each hook runs zero-token Python (`score_signals.py` -> `decide.py`). There is no per-turn LLM call in v1. The skill `description` only matters when a human asks to install/tune/explain the policy -- it is NOT the runtime trigger. These are two separate planes; keep them separate when explaining to the user. The four signals and how each is judged (all deterministic, see `<skill-dir>/references/decision-policy.md` for exact formulas): - **Headroom** = free context fraction from token counts. Pure arithmetic. - **Relevance** = lexical + structural overlap of the new prompt vs the current objective / hot files / touched symbols / plan. No model call; advisory only -- never the sole cause of a destructive action. - **Burden** = estimated reclaimable tokens: duplicate reads, superseded writes, errored-tool inputs, oversized tool outputs. - **Continuity** = open edit / failing test / unresolved tool error / uncheckpointed plan flags. High continuity blocks mid-task compaction. `decide.py` runs the canonical table in `references/decision-policy.md` over these four plus the host capability tier, emitting one action. ## Install It Yourself If you can edit the host config, set this up directly instead of asking the user to do it by hand: 1. **Wire the hooks.** Add `<skill-dir>/
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.
skill-creator
IncludedCreate production-grade agent skills aligned with the 2026 AgentSkills.io spec and Anthropic best practices (2026). Also validates existing skills against the Intent Solutions 100-point rubric. Use when building, testing, validating, or optimizing Claude Code skills. Trigger with "/skill-creator", "create a skill", "validate my skill", or "check skill quality". Make sure to use this skill whenever creating a new skill, slash command, or agent capability.