context-pruning-directive

context-pruning-directive is a skill for Claude Code from alivirgo/Major-AI-Skills. It costs 26 tokens per session (1,251 once invoked), scanned A, original, MIT.

A method for removing stale tool results, old build logs, and completed conversation details from an agent's working context while retaining short summaries. It keeps long-running sessions from continually carrying every past output.

In plain words
What is it for?
Use it in agents that perform many tool calls, such as reading files, running commands, or executing tests over a long session.
Why use it?
Repeatedly sending the full history consumes context space and can make relevant details harder to find. Compacting finished work leaves more room for current files, commands, and decisions.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: mentions Codex.

Part of the major-ai-skills plugin — 147 skills, 7 plugins shipped together

Good fit Use it in agents that perform many tool calls, such as reading files, running commands, or executing tests over a long session.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/alivirgo/major-ai-skills/context-pruning-directive
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add alivirgo/Major-AI-Skills --skill context-pruning-directive
Clone the repo
git clone --depth 1 https://github.com/alivirgo/Major-AI-Skills

Made for: Claude Code.

Or install major-ai-skills, the plugin that ships this one along with the rest of its 147 skills, 7 plugins.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for context-pruning-directive

README.md
[![agentmods](https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/context-pruning-directive/github.svg)](https://agentmods.dev/skills/alivirgo/major-ai-skills/context-pruning-directive)
Your own site
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/context-pruning-directive"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/context-pruning-directive/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for context-pruning-directive

Your own site · 80×15
<a href="https://agentmods.dev/skills/alivirgo/major-ai-skills/context-pruning-directive"><img src="https://agentmods.dev/badge/skills/alivirgo/major-ai-skills/context-pruning-directive.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,251 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00026 $0.01251
Opus 5 $0.00013 $0.00626
Sonnet 5 $0.00005 $0.00250
Haiku 4.5 $0.00003 $0.00125

Measured today against content hash eae98d2450f7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

context-pruning-directive scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/context-pruning-directive/SKILL.md · 119 lines

How it starts

The opening of the file, as written. The whole thing — 119 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Dynamic Context Pruning (Sliding Memory Compactor)

Overview

In long-running autonomous agent sessions, every new message appends the entire historical transcript to the input array. If an agent executes 40 tool calls (reading files, executing bash commands, running test suites), historical tool outputs accumulate in the context window.

This unpruned history causes Quadratic Token Growth ($O(N^2)$): a 5,000-token file read at Turn 2 is needlessly re-sent on Turns 3 through 50, consuming 240,000 redundant input tokens and causing "Lost-in-the-Middle" Attention Degradation.

The Dynamic Context Pruning Protocol actively sanitizes historical turns: replacing stale, completed tool outputs with compact 1-line tombstone summaries and maintaining a high-density rolling memory buffer.


Unpruned Quadratic Accumulation vs. Dynamic Context Pruning

┌─────────────────────────────────────────────────────────────┐
│                 Context Growth Dynamics                     │
│                                                             │
│  Unpruned Transcript ($O(N^2)$ Quadratic Explosion):        │
│  • Turn 2: Reads 800-line file (4,000 tokens)               │
│  • Turn 3..50: 4,000 tokens re-sent on every turn           │
│  ↳ Total Waste: 4,000 tokens $\times$ 48 turns = 192,000 tokens! │
│  ↳ Latency increases from 1.2s to 18.5s per turn            │
│                                                             │
│  Dynamic Context Pruning ($O(N)$ Linear Bounded Memory):    │
│  • Turn 2: Reads 800-line file $\rightarrow$ Edits target lines    │
│  • Turn 3: Old read pruned $\rightarrow$ `[Read: auth.ts (lines 40-50)]`│
│  ↳ Context remains strictly bounded $< 6,000$ tokens        │
│  ↳ 78% Cost Reduction, Stable Sub-second Latency            │
└─────────────────────────────────────────────────────────────┘

The 3-Tier Context Pruning Strategy

┌───────────────────────────────────────────────────────────────────────────┐
│ 1. EPHEMERAL TOOL PRUNING: Compress old tool outputs older than 2 turns   │
│    `cat package.json` (300 lines) $\rightarrow$ `[Tool Output: package.json verified]`│
│                                                                           │
│ 2. SLIDING CONVERSATION WINDOW: Keep only last $K=6$ turns verbatim       │
│                                                                           │
│ 3. MILESTONE STATE CONDENSATION: Summarize completed phases into 3 bullets│
└───────────────────────────────────────────────────────────────────────────┘

Read the full file on GitHub · 119 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today Changed · -14 tokens per session eae98d2450f7
  2. 6d ago First seen · 119 lines · 40 tokens per session scan A 5d3a09c87f3b

Subscribe to this mod's changes

context-pruning-directive is a skill published in the GitHub repository alivirgo/Major-AI-Skills (1 stars, last pushed today), licensed MIT. It adds 26 tokens to every session and 1,251 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-05.

Related

Other skills, from other repositories

agent-memory-mcp-v2

Agent Memory Skill workflow skill. Use this skill when the user needs A hybrid memory system that provides persistent, searchable knowledge management for AI agents (Architecture, Patterns, Decisions) and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing…

diegosouzapw/awesome-omni-skills · 62 tokens

geminiignore-finops

Configure and optimize .geminiignore files for AI context window efficiency and token cost reduction (FinOps).

sinhoneyy/master-skills · 27 tokens

agent-memory-mcp

A hybrid memory system that provides persistent, searchable knowledge management for AI agents (Architecture, Patterns, Decisions).

rootcastleco/rei-skills · 26 tokens

agent-memory-systems

Memory is the cornerstone of intelligent agents. Without it, every interaction starts from zero. This skill covers the architecture of agent memory: short-term (context window), long-term (vector s...

rootcastleco/rei-skills · 43 tokens

agent-memory-systems-v2

Agent Memory Systems workflow skill. Use this skill when the user needs "Memory is the cornerstone of intelligent agents. Without it, every and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing off.

diegosouzapw/awesome-omni-skills · 54 tokens

agent-memory-systems

Agent Memory Systems workflow skill. Use this skill when the user needs "Memory is the cornerstone of intelligent agents. Without it, every and the operator should preserve the upstream workflow, copied support files, and provenance before merging or handing off.

diegosouzapw/awesome-omni-skills · 52 tokens