skill-optimizer
Optimize Claude Code skills for token efficiency using progressive disclosure and content loading order. Use when optimizing skills, reducing token usage, restructuring skill content, improving skill performance, analyzing skill size, applying 500-line rule, implementing progressive disclosure, organizing reference files, optimizing YAML frontmatter, reducing context consumption, improving skill architecture, analyzing token costs, splitting large skills, or working with skill content loading. Covers Level 1 (metadata), Level 2 (instructions), Level 3 (resources) loading optimization.
What this skill does
# Skill Optimizer
## Purpose
Optimize existing Claude Code skills to minimize token consumption by leveraging the three-level content loading architecture and progressive disclosure patterns.
## When to Use
Use this skill when:
- Analyzing existing skills for optimization opportunities
- Skills are too large (approaching or exceeding 500 lines)
- Need to reduce context consumption
- Restructuring skills for progressive disclosure
- Converting monolithic skills to multi-file architecture
- Optimizing YAML frontmatter for better discovery
- Improving skill performance and load times
- Auditing skills for token efficiency
- Creating new skills with optimization in mind
---
## Content Loading Architecture
### Three-Level Loading System
**Level 1: Metadata (Always Loaded - ~100 tokens/skill)**
- YAML frontmatter in SKILL.md
- Loaded at startup into system prompt
- Enables skill discovery without context overhead
- **Optimization Target**: Description field (max 1024 chars)
**Level 2: Instructions (Loaded When Triggered - <5,000 tokens)**
- Main SKILL.md content
- Loads dynamically when skill is relevant
- Contains workflows, best practices, guidance
- **Optimization Target**: Keep under 500 lines
**Level 3: Resources (Loaded As Needed - Variable)**
- Additional markdown files (REFERENCE.md, EXAMPLES.md, etc.)
- Code scripts in scripts/ directory
- Templates, schemas, documentation
- **Optimization Target**: No penalty until accessed
### Key Principle
**"Files don't consume context until accessed"** - Bundle comprehensive documentation in reference files without context penalty.
---
## Quick Optimization Workflow
### 1. Analyze Current State
**Check skill size:**
```bash
wc -l .claude/skills/skill-name/SKILL.md
```
**Identify optimization opportunities:**
- [ ] SKILL.md > 500 lines?
- [ ] Detailed API docs in main file?
- [ ] Extensive examples in main file?
- [ ] Long reference tables or schemas?
- [ ] Code snippets that could be scripts?
- [ ] Multiple distinct topics/sections?
### 2. Apply 500-Line Rule
**If SKILL.md > 500 lines:**
✅ **Keep in main file:**
- Purpose and when to use
- Quick start / common workflows
- Critical best practices
- Brief examples (5-10 lines)
- Cross-references to detailed files
❌ **Move to reference files:**
- Comprehensive API documentation
- Extensive code examples (>20 lines)
- Detailed troubleshooting guides
- Pattern libraries
- Schema definitions
- Long reference tables
### 3. Structure Reference Files
**Create organized reference hierarchy:**
```
skill-name/
├── SKILL.md # <500 lines, workflows & quick ref
├── REFERENCE.md # Comprehensive documentation
├── EXAMPLES.md # Detailed code examples
├── PATTERNS.md # Pattern library
├── TROUBLESHOOTING.md # Debug guide
└── scripts/ # Executable utilities
└── helper.sh
```
**Add table of contents to files >100 lines**
### 4. Optimize YAML Frontmatter
**Description optimization (max 1024 chars):**
✅ **Include:**
- All trigger keywords and phrases
- Use cases and scenarios
- File types and technologies
- Common action verbs
- Related concepts
❌ **Avoid:**
- Generic descriptions
- Missing key terms
- Overly verbose explanations
**Example:**
```yaml
---
name: database-development
description: Database development guidance for PostgreSQL including schema design, migrations, RLS policies, indexing strategies, privacy-preserving patterns, query optimization, and Prisma ORM. Use when working with tables, columns, indexes, migrations, RLS, Row-Level Security, database schema, SQL queries, Prisma schema, database optimization, privacy architecture, or PostgreSQL best practices.
---
```
### 5. Implement Progressive Disclosure
**Pattern:**
```markdown
## Topic Overview
Brief explanation (2-3 sentences).
**Key Points:**
- Important consideration 1
- Important consideration 2
**For detailed information**: [REFERENCE.md](REFERENCE.md#topic-details)
**Quick Example:**
\`\`\`typescript
// Minimal working example (5-10 lines)
\`\`\`
**For more examples**: [EXAMPLES.md](EXAMPLES.md#topic-examples)
```
---
## Optimization Patterns Summary
### Pattern 1: Extract API Documentation
**Strategy**: Move detailed API docs to REFERENCE.md
**Before**: 80+ lines of API documentation in SKILL.md
**After**: 10-line summary with link to complete docs
**Savings**: ~70 lines (~1,400 tokens)
**For complete pattern details**: [REFERENCE.md](REFERENCE.md#pattern-1-extract-api-documentation)
### Pattern 2: Extract Pattern Libraries
**Strategy**: Move code patterns to PATTERNS.md
**Before**: 200+ lines of pattern code in SKILL.md
**After**: 18-line summary with quick example
**Savings**: ~182 lines (~3,640 tokens)
**For complete pattern details**: [REFERENCE.md](REFERENCE.md#pattern-2-extract-pattern-libraries)
### Pattern 3: Extract Troubleshooting
**Strategy**: Move debug guides to TROUBLESHOOTING.md
**Before**: 300+ lines of troubleshooting in SKILL.md
**After**: 18-line summary with quick diagnostics
**Savings**: ~282 lines (~5,640 tokens)
**For complete pattern details**: [REFERENCE.md](REFERENCE.md#pattern-3-extract-troubleshooting)
### Pattern 4: Convert Code to Scripts
**Strategy**: Move executable code to scripts/ directory
**Before**: 55+ lines of bash script in SKILL.md
**After**: 7-line reference to executable script
**Savings**: ~48 lines (~960 tokens) + script code never enters context
**For complete pattern details**: [REFERENCE.md](REFERENCE.md#pattern-4-convert-code-to-scripts)
---
## Common Anti-Patterns
Avoid these common mistakes when creating or optimizing skills:
❌ **Anti-Pattern 1: Monolithic Skills**
- Single SKILL.md with 1000+ lines
- Solution: Split into main + reference files
❌ **Anti-Pattern 2: Incomplete References**
- Reference files exist but not linked
- Solution: Link all reference files from SKILL.md
❌ **Anti-Pattern 3: Nested References**
- References pointing to other references (>1 level)
- Solution: Keep hierarchy flat (max 1 level)
❌ **Anti-Pattern 4: Sparse Frontmatter**
- Minimal YAML description missing keywords
- Solution: Rich description with all triggers
❌ **Anti-Pattern 5: Code as Documentation**
- 100+ line scripts embedded in markdown
- Solution: Move to scripts/ directory
**For detailed anti-patterns and solutions**: [REFERENCE.md](REFERENCE.md#common-anti-patterns)
---
## Migration Workflow
### Quick Migration Steps
**Phase 1: Discovery**
```bash
# Check skill size
wc -l .claude/skills/skill-name/SKILL.md
# Identify sections to extract
grep "^##" .claude/skills/skill-name/SKILL.md
```
**Phase 2: Planning**
- Design file hierarchy (SKILL.md + reference files)
- Plan content distribution
- Identify scripts to extract
**Phase 3: Implementation**
```bash
# Create reference files
touch REFERENCE.md EXAMPLES.md
mkdir -p scripts
# Extract content systematically
# 1. Copy section to reference file
# 2. Replace in SKILL.md with summary + link
# 3. Verify link works
# 4. Remove detailed content from SKILL.md
```
**Phase 4: Optimization**
- Trim remaining content
- Optimize frontmatter with trigger keywords
- Add navigation aids (table of contents)
**Phase 5: Validation**
```bash
# Verify under 500 lines
wc -l .claude/skills/skill-name/SKILL.md
# Test links work
grep -o '\[.*\](.*\.md#.*)' SKILL.md
```
**For complete migration workflow**: [REFERENCE.md](REFERENCE.md#complete-migration-workflow)
---
## Advanced Techniques
Quick reference to advanced optimization strategies:
**Technique 1: Conditional Content Loading**
- Structure content so advanced sections load only when needed
- Benefits: Most users don't load advanced content
**Technique 2: Layered Examples**
- Progressive complexity: minimal → production → enterprise
- Benefits: Beginners see simple examples, advanced users access complex ones
**Technique 3: Executable Documentation**
- Scripts that both execute and document
- Benefits: Zero token cost, self-documenting output
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.