Skill 详情
optimize-prompt-token-efficiency
Strong for compressing individual prompts, not general token optimization.
使用前先检查
自动化审核只检查相关性,不代表安全审查或推荐。使用前请阅读来源中的说明。
SKILL.md
这段内容是审核时保存的快照。外部来源才是完整且最新的版本。
---
name: optimize-prompt-token-efficiency
description: 'Iteratively optimizes prompts for token efficiency by maximizing information density - reduces verbosity, removes redundancy, tightens phrasing while preserving semantic content. Use when asked to compress, shorten, reduce tokens, tighten, maximize density, increase information density, or make a prompt more concise.'
---
# Optimize Prompt Token Efficiency
Iteratively optimize prompt token efficiency by maximizing information density through verification loops. Primary goal: reduce token consumption while preserving all semantic content for AI-consumed prompts (CLAUDE.md, skills, agent prompts, specs).
## Overview
This skill transforms verbose prompts into token-efficient versions through:
1. **Verification First** - `prompt-token-efficiency-verifier` checks for inefficiencies before any changes
2. **Optimization** - Apply targeted compression based on verifier feedback
3. **Re-verification** - Verify compression is lossless, iterate if issues remain (max 5 iterations)
4. **Output** - Atomic replacement only after verification passes
**Loop**: Read → Verify → (Exit if efficient) → Optimize based on feedback → Re-verify → (Iterate if issues) → Output
**Key principle**: Don't try to optimize in one pass. The verifier drives all changes - if it finds no inefficiencies, the prompt is already token-efficient.
## Workflow
### Phase 0: Create Task List (use task management immediately)
Create todos tracking workflow phases. List reflects areas of work, not fixed steps.
**Starter todos**:
```
- [ ] Input validation
- [ ] Initial verification
- [ ] (Expand: optimization iterations on INEFFICIENCIES_FOUND)
- [ ] Output optimized prompt
```
### Phase 1: Input Validation
**Mark "Input validation" todo `in_progress`.**
**Step 1.1: Parse arguments**
Extract file path from `$ARGUMENTS`. If no path provided, error with usage instructions.
**Step 1.2: Validate file**
- Check file exists using Read tool
- Verify supported type: `.md`, `.txt`, `.yaml`, `.json`
- If unsupported, error: "Unsupported file type. Supported: .md, .txt, .yaml, .json"
**Step 1.3: Read and measure original**
- Read file content
- Estimate token count: `Math.ceil(content.length / 4)` (approximate)
- Store original content and token count for comparison
**Step 1.4: Store metadata**
- `original_path`: Source file path
- `original_content`: Full prompt text
- `original_tokens`: Estimated token count
- `working_path`: `/tmp/optimized-efficiency-{timestamp}.{ext}` for iterations
**Mark "Input validation" todo `completed`.**
### Phase 2: Initial Verification
**Mark "Initial verification" todo `in_progress`.**
**Step 2.1: Copy to working path**
Copy original content to working_path using Write tool (verification needs a file path).
**Step 2.2: Run verifier first**
Launch prompt-token-efficiency-verifier agent via Task tool BEFORE any optimization:
- subagent_type: "prompt-engineering:prompt-token-efficiency-verifier"
- prompt: "Verify prompt token efficiency. File: {working_path}. Check for redundancy, verbose phrasing, filler words, structural inefficiencies, and compression opportunities. Report VERIFIED if already efficient, or INEFFICIENCIES_FOUND with specific details."
**Step 2.3: Handle verifier response**
- If "VERIFIED": Mark todo completed, proceed directly to Phase 4 (Output) with message: "Prompt is already token-efficient. No changes needed."
- If "INEFFICIENCIES_FOUND": Mark todo completed, save the issues list, add "Optimization iteration 1" todo and proceed to Phase 3
- If verifier fails or returns unexpected format: Retry once with identical parameters. If retry fails, report error: "Verification failed - cannot proceed without verifier."
**Step 2.4: Display verifier findings**
If inefficiencies found, show user summary and proceed:
```
Verifier found {count} token efficiency issues. Proceeding with optimization...
```
**Mark "Initial verification" todo `completed`.**
### 在 GitHub 阅读完整来源 (打开外部页面)