pi-dcp
БесплатноБез исполняемых скриптовНе проверенDynamic Context Pruning extension for pi. Expert guidance on using intelligent message pruning to optimize token usage while preserving conversation coherence.
Об этом скилле
Pi-DCP: Dynamic Context Pruning Expert
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.
Core Concepts
What Pi-DCP Does
Pi-DCP automatically removes obsolete and redundant messages from conversation context before each LLM call. This:
- Reduces token usage - Fewer messages sent to the LLM
- Lowers costs - Smaller prompts = cheaper API calls
- Preserves coherence - Smart rules keep important context
- Works transparently - No user intervention needed
Workflow: Prepare > Process > Filter
- Prepare Phase: Rules annotate message metadata (hashes, file paths, error status, etc.)
- Process Phase: Rules make pruning decisions based on metadata
- Filter Phase: Messages marked for pruning are removed
Built-in Rules
Deduplication
- Removes duplicate tool outputs based on content hash
- Keeps first occurrence, prunes later duplicates
- Never prunes user messages
Superseded Writes
- Removes older file write/edit operations when newer versions exist
- Tracks file paths and versions
- Only keeps the latest write to each file
Error Purging
- Removes resolved errors from context
- Identifies errors followed by successful retries
- Keeps unresolved errors for context
Recency Protection
- Always preserves recent messages (default: last 10)
- Overrides other pruning decisions
- Configurable threshold
Usage Guidance
Commands
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)
When to Use Debug Mode
Recommend /dcp-debug when:
- User suspects important context is being pruned
- Investigating unexpected LLM behavior
- Understanding what the extension is doing
- Tuning configuration
When to Adjust Recency Threshold
Recommend changing keepRecentCount:
Increase (e.g.,
/dcp-recent 20) if:- LLM seems to forget recent context
- Working on complex multi-step tasks
- Need more working memory
Decrease (e.g.,
/dcp-recent 5) if:- Token usage is still too high
- Conversation is very repetitive
- Most context is in recent messages anyway
When to Disable
Recommend /dcp-toggle to disable when:
- Debugging issues and want to see full context
- Working on tasks where all history matters
- Testing if pruning is causing problems
Custom Rules
Creating Custom Rules
Guide users on implementing PruneRule:
import 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';
}
},
};
Rule Design Patterns
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)
Metadata Fields
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.
Troubleshooting
"LLM forgot recent context"
- Check recency threshold:
/dcp-recent 15to increase - Enable debug:
/dcp-debugto see what's being pruned - Check if important messages are within recency window
"Still using too many tokens"
- Check stats:
/dcp-statsto see pruning rate - Consider adding custom rules for domain-specific pruning
- Reduce recency threshold if safe:
/dcp-recent 5
"Extension not working"
- Check if enabled:
/dcp-toggletwice (off then on) - Look for initialization message in logs
- Check for configuration errors in console
"Rule not found
Установить pi-dcp в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл pi-dcp?
Dynamic Context Pruning extension for pi. Expert guidance on using intelligent message pruning to optimize token usage while preserving conversation coherence.
Как установить скилл pi-dcp?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл pi-dcp запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic