- [MIPROv2](https://dspy.ai/api/optimizers/MIPROv2/)
Use this prompt to optimize token usage in prompt files while maintaining effectiveness.
---
## The Optimization Prompt
```sh
I need you to optimize this prompt for token efficiency while preserving its effectiveness. Apply these principles:
## Compression Guidelines
1. **Remove Redundancy**
- Eliminate repeated concepts or instructions
- Combine similar directives into single statements
- Remove verbose explanations where concise language suffices
2. **Preserve Critical Elements**
- Keep domain-specific terminology exact
- Maintain all constraints and requirements
- Preserve examples that demonstrate complex concepts
- Keep role definitions and core instructions
3. **Apply Compression Techniques**
- Convert verbose sentences to concise bullet points
- Replace "In order to do X, you should Y" with "To X: Y"
- Remove filler words: "basically", "essentially", "actually", "simply"
- Replace "you will need to" with "must" or imperative form
- Convert "it is important that you" to direct commands
- Use active voice over passive voice
4. **Structural Optimization**
- Front-load most critical instructions (avoid "lost in the middle")
- Group related instructions together
- Use hierarchical structure (headers, bullets) for scannability
- Remove meta-commentary about the prompt itself
5. **Strategic Decisions**
- Keep examples only if they demonstrate non-obvious behavior
- Preserve negative examples ("don't do X") only for critical mistakes
- Maintain edge case handling that's not intuitive
- Remove encouragement/motivation language unless behaviorally significant
6. **Quality Preservation**
- Target 30-50% token reduction for moderate optimization
- Target 60-70% token reduction for aggressive optimization
- Test that compressed version maintains intent
- Flag any ambiguities introduced by compression
## Your Task
1. Analyze the prompt below and identify optimization opportunities
2. Create an optimized version following the guidelines above
3. Provide a brief summary of:
- Estimated token reduction (percentage)
- Key compressions made
- Any potential risks or ambiguities introduced
## Original Prompt
[PASTE YOUR PROMPT HERE]
```
---
## Usage Examples
### Before Optimization (Verbose)
```sh
It is very important that you carefully read through all of the user's code before
making any suggestions. You should take your time to understand the context and the
purpose of what the user is trying to accomplish. In order to provide the best possible
assistance, you will need to analyze the codebase structure and identify any potential
issues or areas that could be improved.
When you are writing code, you should always follow the existing patterns and conventions
that are already present in the codebase. This is important because it helps maintain
consistency and makes the code easier to understand for other developers who might work
on it in the future.
```
**Token count:** ~120 tokens
### After Optimization (Concise)
```sh
Before suggesting changes:
- Read all user code thoroughly
- Understand context and purpose
- Analyze codebase structure
- Identify issues and improvements
When writing code:
- Follow existing patterns and conventions
- Maintain consistency for team readability
```
**Token count:** ~45 tokens (62% reduction)
---
## Optimization Strategies by Prompt Type
### System Prompts / Role Definitions
- **Focus:** Preserve role identity, core behaviors, constraints
- **Compress:** Verbose explanations of why the role exists
- **Target:** 40-50% reduction
### Task Instructions
- **Focus:** Preserve all steps, edge cases, validation rules
- **Compress:** Motivational language, redundant examples
- **Target:** 30-40% reduction
### Context/Documentation Prompts (like AGENTS.md)
- **Focus:** Critical domain knowledge, gotchas, constraints
- **Compress:** Historical context, verbose explanations, redundant links
- **Target:** 50-60% reduction
### Few-Shot Examples
- **Focus:** Diverse, non-obvious examples showing edge cases
- **Compress:** Similar examples, obvious patterns
- **Target:** Keep 2-3 high-quality examples vs 10+ similar ones
---
## Validation Checklist
After optimization, verify:
- [ ] All requirements and constraints preserved
- [ ] Technical terminology unchanged
- [ ] Examples demonstrate key concepts
- [ ] Critical warnings/gotchas remain
- [ ] Ambiguity not introduced
- [ ] Hierarchical structure maintained (most important first)
- [ ] Token reduction achieved (target: 30-70% depending on prompt type)
---
## Advanced: Contextual Retrieval Pattern
For very large instruction sets (>2000 tokens), consider splitting into:
1. **Core prompt** (~500 tokens): Always included, contains essential instructions
2. **Domain modules** (~300-500 tokens each): Loaded on-demand via CLAUDE.md references
3. **Examples repository**: Referenced by link, loaded only when clarification needed
Example structure:
```sh
CLAUDE.md (core, always loaded)
docs/ARCHITECTURE.md (loaded when architectural decisions needed)
docs/CONVENTIONS.md (loaded when writing code)
docs/examples/ (loaded on-demand for clarification)
```
This "just-in-time context loading" mirrors the research finding that **dynamic context loading is more efficient than pre-loading everything**.
---
## Token Estimation
Quick estimation rules:
- 1 token ≈ 4 characters (rough estimate)
- 1 token ≈ 0.75 words (English average)
- Use provider-specific tools for precision:
- Anthropic: Check token count in API response
- OpenAI: Use tiktoken library
- Claude Code: Monitor status bar percentage
---
## Related Research
This meta-prompt applies findings from token optimization research:
- Moderate compression (5-7x): 85-90% cost reduction, 5-15% accuracy trade-off
- Front-loading critical info avoids "lost in the middle" (30% performance degradation)
- Hierarchical organization improves model attention and retrieval
- Extractive compression (preserving original phrasing) is safer than abstractive