From prompt-engineering
Iteratively optimizes AI prompts for token efficiency by reducing verbosity, redundancy, and tightening phrasing while preserving semantics. Use for compress, shorten, reduce tokens, or maximize density requests.
npx claudepluginhub doodledood/claude-code-plugins --plugin prompt-engineeringThis skill uses the workspace's default tool permissions.
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).
Optimizes text, prompts, and documentation for LLM token efficiency by compressing verbose content with rule-based transformations in light, medium, or deep modes.
Compresses prompts and skills into minimal goal-focused instructions by dropping redundant details, trusting model capabilities, and maximizing action space. Use to condense or minimize prompts.
Optimizes prompts, docs, and text for LLM token efficiency using 41 research-backed rules across Claude behavior, structure, token savings, and comprehension. Cuts tokens 20-40%; use for cheaper API calls and clearer instructions.
Share bugs, ideas, or general feedback.
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).
This skill transforms verbose prompts into token-efficient versions through:
prompt-token-efficiency-verifier checks for inefficiencies before any changesLoop: 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.
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
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
.md, .txt, .yaml, .jsonStep 1.3: Read and measure original
Math.ceil(content.length / 4) (approximate)Step 1.4: Store metadata
original_path: Source file pathoriginal_content: Full prompt textoriginal_tokens: Estimated token countworking_path: /tmp/optimized-efficiency-{timestamp}.{ext} for iterationsMark "Input validation" todo completed.
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:
Step 2.3: Handle verifier response
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.
Mark "Optimization iteration 1" todo in_progress.
Key principle: All fixes are driven by verifier feedback. Do NOT analyze the prompt independently - only fix the specific inefficiencies the verifier reported.
For each iteration from 1 to 5:
Apply compressions from verifier feedback: For each inefficiency in the verifier's report, apply the suggested compression. Write optimized version to working_path.
Re-verify: Launch prompt-token-efficiency-verifier agent via Task tool:
Handle response:
Apply these techniques to fix inefficiencies flagged by the verifier:
| Technique | Description | Before → After |
|---|---|---|
| Redundancy removal | Eliminate repeated concepts | "It is important to note that you should always remember to..." → "Always..." |
| Terse phrasing | Replace verbose constructions | "In order to accomplish this task, you will need to..." → "To do this:" |
| Filler elimination | Remove hedging, qualifiers, throat-clearing | "Make sure that you do not forget to include..." → "Include:" |
| Structural optimization | Merge/reorganize sections | "First X. After that Y. Then Z." → "Steps: X → Y → Z" |
| Context-aware abbreviation | Abbreviate terms after first mention | "Model Context Protocol server" (×10) → "MCP server" (after first) |
| Dense formatting | Use lists, tables, compact notation | Prose paragraphs → Tables, bullet lists |
Transformation Rules:
Avoid creating ambiguity:
Mark "Output optimized prompt" todo in_progress.
Step 4.1: Calculate metrics
Math.ceil(compressed_content.length / 4)((original - compressed) / original * 100).toFixed(0)Step 4.2: Apply changes (atomic replacement)
If verification passed:
# Replace original atomically
mv {working_path} {original_path}
Step 4.3: Display results
If verification passed:
Optimized: {path}
Iterations: {count}
Original: {original_tokens} tokens
Optimized: {compressed_tokens} tokens
Reduction: {percentage}%
Changes applied:
- {summary of compressions}
Status: Token-efficient and lossless
If verification failed after 5 iterations:
Optimized with warnings: {path}
Iterations: 5
Original: {original_tokens} tokens
Optimized: {compressed_tokens} tokens
Reduction: {percentage}%
Unresolved issues:
- {list from last verification}
Review the changes manually.
Mark "Output optimized prompt" todo completed. Mark all todos complete.
| Principle | Rule |
|---|---|
| Verify first | Always run verifier before any optimization; maybe prompt is already efficient |
| Verifier-driven | Only fix inefficiencies the verifier identifies - no independent analysis or improvements |
| Track progress | Use task management to track phases; expand tasks on iteration |
| Losslessness | Never sacrifice semantic information for density; every fact must be preserved |
| Nuance preservation | Keep emphasis, intentional hedging, priority signals; 10% with nuance > 40% without |
| No ambiguity | Compressed must be as unambiguous as original |
| Verification required | Never output without verifier checking |
| Atomic output | Original untouched until verification passes |
| Scenario | Handling |
|---|---|
| No input provided | Error: "Usage: /optimize-prompt-token-efficiency " |
| File not found | Error: "File not found: {path}" |
| Unsupported type | Error: "Unsupported file type. Supported: .md, .txt, .yaml, .json" |
| Already efficient | Verifier returns VERIFIED on first check → Report: "Prompt is already token-efficient. No changes needed." |
| Initial verifier fails | Retry once; if still fails, Error: "Verification failed - cannot proceed without verifier." |
| Re-verification fails | Display error, retry once; if retry fails, output with warning |
| YAML/JSON structure | Preserve structure validity, compress string values only |
| Very large file (>50KB) | Process as single unit |
| 0-10% reduction | Success: "Content was already near-optimal density" |
| Verification fails 5x | Output best attempt with warning |
# Optimize a verbose CLAUDE.md
/optimize-prompt-token-efficiency CLAUDE.md
# Optimize a skill file
/optimize-prompt-token-efficiency claude-plugins/my-plugin/skills/my-skill/SKILL.md
# Optimize an agent prompt
/optimize-prompt-token-efficiency agents/code-reviewer.md
Optimized: docs/README.md
Iterations: 2
Original: 4,250 tokens
Optimized: 3,612 tokens
Reduction: 15%
Changes applied:
- Removed redundant intro section
- Consolidated overlapping examples
- Tersified verbose instructions
- Preserved emphasis markers and conditional logic
Status: Token-efficient and lossless
Prompt is already token-efficient. No changes needed.
Original: 1,995 tokens