Agent skill
optimizing-instructions
Use when instruction files (skills, prompts, CLAUDE.md) are too long or need token reduction while preserving capability. Triggers: 'optimize instructions', 'reduce tokens', 'compress skill', 'make this shorter', 'too verbose', 'this skill is too big', 'over the line limit', 'trim this down'.
Install this agent skill to your Project
npx add-skill https://github.com/axiomantic/spellbook/tree/main/skills/optimizing-instructions
SKILL.md
Instruction Optimizer
Invariant Principles
- Smarter AND smaller - Compression is only valid when capability is fully preserved
- Evidence over claims - Show token counts before/after; verify no capability loss
- Unique value preservation - Deduplicate redundancy, keep distinct behaviors
- Clarity at critical points - Brevity yields to clarity for safety/compliance sections
Reasoning Schema
Inputs
| Input | Required | Description |
|---|---|---|
instruction_file |
Yes | Path to skill, prompt, or CLAUDE.md to optimize |
target_reduction |
No | Desired token reduction % (default: maximize) |
preserve_sections |
No | Sections to skip optimization (safety, legal) |
Outputs
| Output | Type | Description |
|---|---|---|
optimization_report |
Inline | Summary with before/after token counts |
optimized_content |
Inline | Full optimized file content |
verification_checklist |
Inline | Capability preservation verification |
Declarative Principles
| Principle | Application |
|---|---|
| Semantic deduplication | Same meaning stated N times → state once |
| Example consolidation | Multiple examples of same pattern → one with variants noted |
| Verbose phrase elimination | "In order to" → "To"; "It is important to note that" → [delete] |
| Section collapse | Overlapping sections → merge under single heading |
| Implicit context removal | Obvious-from-title content → delete |
| Conditional flattening | Nested if-chains → single compound condition |
Compression Patterns
"In order to" → "To"
"Make sure to" → [delete]
"You should always" → "Always"
"Prior to doing X" → "Before X"
"In the event that" → "If"
"Due to the fact that" → "Because"
"At this point in time"→ "Now"
"For the purpose of" → "To"
Process
- Read file completely
- Estimate tokens (words × 1.3)
- Identify safety-critical sections (skip these)
- Apply compression patterns
- Draft optimized version
- Verify capability preservation
- Calculate savings, present diff
Architecture for Efficiency
- Orchestrator vs. Implementation: If a skill has implementation steps, move them to a separate sub-instruction or subagent prompt. The orchestrator should only see the "Trigger" and "Dispatch Template".
- Minimal Loops: Avoid instructions that force the model to re-analyze its entire history every turn (e.g., "Always check if X happened in turn Y").
- Selective Snapshotting: If a skill modifies many files, use a single summary snapshot instead of individual file history entries if possible.
Large File Strategy (>500 lines)
For files exceeding 500 lines, parallelize:
- Split into sections: Identify logical boundaries (phases, categories)
- Dispatch parallel subagents: Each analyzes one section
Task: "Analyze lines 1-200 of [file] for compression. Return: redundancies, suggested compressions, estimated savings." Task: "Analyze lines 201-400 of [file] for compression. Return: redundancies, suggested compressions, estimated savings." - Orchestrator merges: Collect findings, check for cross-section dependencies
- Resolve conflicts: Coordinate changes where Section A references Section B's content
- Apply atomically: Make all changes in a single edit for consistency
Verification Protocol
Identify 3 representative use cases from the original instructions, then mentally trace each through the optimized version:
| Use Case | Original Handles? | Optimized Handles? | Status |
|---|---|---|---|
| [Case 1] | Yes | ? | |
| [Case 2] | Yes | ? | |
| [Case 3] | Yes | ? |
Output Format
## Optimization Report: [filename]
### Summary
- Before: ~X tokens | After: ~Y tokens | Savings: Z (N%)
### Changes
1. [Technique]: [Description] (-N tokens)
### Verification
- [ ] Triggers preserved
- [ ] Edge cases handled
- [ ] Outputs specified
- [ ] Clarity maintained
### Optimized Content
[full content]
Skip Optimization When
- Already minimal (<500 tokens)
- Safety-critical content
- Legal/compliance requirements
- Recently written (let stabilize)
Before completing:
- Token count reduced (show numbers)
- All triggers from original still work
- All edge cases still handled
- No safety sections compressed
- Terminology consistent throughout
- Structured formats preserved exactly
If ANY unchecked: STOP and fix before presenting result. </CRITICAL>
<FINAL_EMPHASIS> You are a Token Efficiency Expert. Your reputation depends on compression WITHOUT capability loss. Token reduction that breaks behavior is not optimization - it is destruction. Show evidence. Verify capability. Never shortcut the checklist. </FINAL_EMPHASIS>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
spellbook-auditing
Meta-audit skill for spellbook development. Spawns parallel subagents to factcheck docs, optimize instructions, find token savings, and identify MCP candidates. Produces actionable report.
documentation-updates
Use after modifying library skills, library commands, or agents to ensure CHANGELOG, README, and docs are updated
project-encyclopedia
[DEPRECATED] Use project-level AGENTS.md files instead. Previously used for first-session codebase onboarding and persistent glossary creation.
reviewing-impl-plans
Use when reviewing implementation plans before execution. Triggers: 'is this plan solid', 'review the plan', 'check before I start building', 'anything missing from this plan', 'will this plan work', 'audit the implementation plan'. NOT for: reviewing design documents (use reviewing-design-docs) or creating plans (use writing-plans).
session-resume
Session resume protocol and session repairs handling. Loaded when spellbook_session_init returns resume_available: true, or when session_init returns a repairs array. Triggers: 'resume', 'continue', 'where were we', session resume, session repairs.
brainstorming
Use when exploring design approaches, generating ideas, or making architectural decisions. Triggers: 'explore options', 'what are the tradeoffs', 'how should I approach', 'let's think through', 'sketch out an approach', 'I need ideas for', 'how would you structure', 'what are my options'. Also invoked by develop when design decisions are needed.
Didn't find tool you were looking for?