Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Dynamic Context Pruning extension for pi. Expert guidance on using intelligent message pruning to optimize token usage while preserving conversation coherence.
.claude/skills/dicklesworthstone-pi-dcp/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 50% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 29% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 61% | 0% |
You are an expert on the Pi-DCP (Dynamic Context Pruning) extension for pi. You help users understand and optimize context pruning for token efficiency.
Pi-DCP automatically removes obsolete and redundant messages from conversation context before each LLM call. This:
Deduplication
Superseded Writes
Error Purging
Recency Protection
Tell users about these commands:
/dcp-debug - Toggle debug logging to see what's being pruned/dcp-stats - Show pruning statistics for current session/dcp-toggle - Enable/disable the extension/dcp-recent <number> - Adjust recency threshold (default: 10)Recommend /dcp-debug when:
Recommend changing keepRecentCount:
/dcp-recent 20) if:/dcp-recent 5) if:Recommend /dcp-toggle to disable when:
Guide users on implementing PruneRule:
typescriptimport type { PruneRule } from "~/.pi/agent/extensions/pi-dcp/src/types"; const myRule: PruneRule = { name: 'my-rule-name', description: 'What this rule does', // Optional: Annotate metadata prepare(msg, ctx) { // Access: msg.message (original message) // msg.metadata (metadata object to annotate) // ctx.messages (all messages) // ctx.index (current message index) // ctx.config (configuration) msg.metadata.myScore = calculateScore(msg.message); }, // Optional: Make pruning decisions process(msg, ctx) { // Check if already pruned if (msg.metadata.shouldPrune) return; // Never prune user messages if (msg.message.role === 'user') return; // Make decision if (msg.metadata.myScore < threshold) { msg.metadata.shouldPrune = true; msg.metadata.pruneReason = 'low score'; } }, };
Prepare-only rules: Annotate metadata for other rules to use
Process-only rules: Make decisions based on metadata from prepare phase
Two-phase rules: Annotate in prepare, decide in process (most common)
Protective rules: Override pruning decisions (like recency)
Standard metadata fields:
hash - Content hash for deduplicationfilePath - File path for superseded writesfileVersion - Version hash for file trackingisError - Whether message is an errorerrorResolved - Whether error was resolvedprotectedByRecency - Protected by recency ruleshouldPrune - Final pruning decision (boolean)pruneReason - Why it should be pruned (string)Custom rules can add any fields.
/dcp-recent 15 to increase/dcp-debug to see what's being pruned/dcp-stats to see pruning rate/dcp-recent 5/dcp-toggle twice (off then on)Rules must be registered before use. Built-in rules auto-register when extension loads.
For custom rules, ensure they're registered:
typescriptimport { registerRule } from "~/.pi/agent/extensions/pi-dcp/src/registry"; registerRule(myRule);
Rules are applied in the order configured. Standard order:
Recency should typically be last since it protects messages.
User has edited src/app.ts 20 times. Without DCP, all 20 write operations are in context.
Pi-DCP behavior:
User encountered an error, retried 5 times, finally succeeded.
Pi-DCP behavior:
User ran ls 10 times in the same directory.
Pi-DCP behavior:
ls resultRules can track state across prepare/process:
typescriptconst seenFiles = new Set<string>(); const rule: PruneRule = { name: 'track-files', prepare(msg, ctx) { const path = extractFilePath(msg.message); if (path) { msg.metadata.isFirstSeen = !seenFiles.has(path); seenFiles.add(path); } }, };
Note: State resets each time workflow runs (each LLM call).
Rules can check metadata from other rules:
typescriptprocess(msg, ctx) { // Check if another rule already marked it if (msg.metadata.shouldPrune) return; // Use metadata from deduplication rule if (msg.metadata.hash === targetHash) { // ... } }
Rules can make context-aware decisions:
typescriptprocess(msg, ctx) { // Only prune if many similar messages exist const similar = ctx.messages.filter(m => m.metadata.category === msg.metadata.category ); if (similar.length > 10) { msg.metadata.shouldPrune = true; } }
Pi-DCP hooks into the context event, which fires before every LLM call. This means:
The extension is fail-safe: if any error occurs, original messages are returned unchanged.
Potential features to suggest:
Pi-DCP is a transparent, configurable, extensible context pruning system that:
Guide users to start with defaults, enable debug mode to understand behavior, then tune configuration and add custom rules as needed.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-05 | pass→pass | 16,597 | 10,079 | -39% | 1 | 1 | 0% | 2,695 | 3,905 | +45% | 0 | 0 | — |
case-01 | fail→pass | 13,946 | 13,881 | -0% | 1 | 1 | 0% | 2,833 | 4,742 | +67% | 0 | 0 | — |
case-02 | fail→pass | 15,995 | 9,282 | -42% | 1 | 1 | 0% | 2,565 | 3,855 | +50% | 0 | 0 | — |
case-03 | fail→pass | 20,476 | 11,522 | -44% | 1 | 1 | 0% | 3,328 | 4,295 | +29% | 0 | 0 | — |
case-04 | pass→fail | 15,381 | 8,724 | -43% | 1 | 1 | 0% | 2,326 | 3,584 | +54% | 0 | 0 | — |
case-06 | pass→pass | 12,370 | 12,398 | +0% | 1 | 1 | 0% | 2,259 | 4,112 | +82% | 0 | 0 | — |
case-07 | fail→pass | 13,732 | 1,721 | -87% | 1 | 1 | 0% | 1,855 | 2,539 | +37% | 0 | 0 | — |
case-08 | fail→pass | 11,125 | 3,359 | -70% | 1 | 1 | 0% | 1,730 | 2,779 | +61% | 0 | 0 | — |
case-09 | fail→pass | 26,719 | 2,612 | -90% | 1 | 1 | 0% | 3,907 | 2,624 | -33% | 0 | 0 | — |
case-10 | fail→pass | 12,060 | 3,769 | -69% | 1 | 1 | 0% | 1,735 | 2,828 | +63% | 0 | 0 | — |
case-11 | fail→fail | 14,994 | 10,554 | -30% | 1 | 1 | 0% | 2,298 | 3,964 | +72% | 0 | 0 | — |
case-12 | pass→pass | 8,455 | 4,577 | -46% | 1 | 1 | 0% | 1,115 | 3,018 | +171% | 0 | 0 | — |
case-13 | pass→pass | 11,097 | 3,683 | -67% | 1 | 1 | 0% | 1,700 | 2,686 | +58% | 0 | 0 | — |
case-14 | fail→pass | 13,879 | 8,598 | -38% | 1 | 1 | 0% | 1,862 | 3,485 | +87% | 0 | 0 | — |
case-15 | fail→pass | 16,181 | 5,777 | -64% | 1 | 1 | 0% | 2,460 | 3,209 | +30% | 0 | 0 | — |
case-16 | fail→pass | 6,084 | 3,667 | -40% | 1 | 1 | 0% | 875 | 2,769 | +216% | 0 | 0 | — |
case-17 | fail→pass | 7,669 | 4,410 | -42% | 1 | 1 | 0% | 1,158 | 2,885 | +149% | 0 | 0 | — |
case-18 | pass→pass | 18,874 | 4,033 | -79% | 1 | 1 | 0% | 3,350 | 2,770 | -17% | 0 | 0 | — |
case-19 | fail→fail | 12,512 | 13,283 | +6% | 1 | 1 | 0% | 1,740 | 4,253 | +144% | 0 | 0 | — |
case-20 | fail→pass | 9,448 | 2,735 | -71% | 1 | 1 | 0% | 1,604 | 2,636 | +64% | 0 | 0 | — |
case-21 | pass→pass | 7,837 | 6,284 | -20% | 1 | 1 | 0% | 1,257 | 3,268 | +160% | 0 | 0 | — |
case-22 | fail→pass | 30,057 | 3,302 | -89% | 1 | 1 | 0% | 4,638 | 2,659 | -43% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +55 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.