home / skills / athola / claude-night-market / optimizing-large-skills

optimizing-large-skills skill

/plugins/conserve/skills/optimizing-large-skills

This skill guides you to optimize large skills by externalizing, consolidating, and progressively loading content to reduce size while preserving functionality.

npx playbooks add skill athola/claude-night-market --skill optimizing-large-skills

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
5.8 KB
---
name: optimizing-large-skills
description: Systematic methodology to reduce skill file size through externalization,
  consolidation, and progressive loading patterns. Use when skills exceed 300 lines,
  multiple code blocks (10+) with similar functionality, heavy Python inline with
  markdown, functions >20 lines embedded. Do not use when skill is under 300 lines
  and well-organized. creating new skills - use modular-skills instead. Consult this
  skill when skills-eval shows "Large skill file" warnings.
token_budget: 25
progressive_loading: true
---
## Table of Contents

- [When to Use](#when-to-use)
- [Core Pattern: Externalize-Consolidate-Progress](#core-pattern-externalize-consolidate-progress)
- [Quick Reference](#quick-reference)
- [Optimization Workflow](#optimization-workflow)
- [Key Success Factors](#key-success-factors)
- [Modules](#modules)

# Optimizing Large Skills

Systematic methodology for reducing skill file size while preserving functionality
through separation of concerns and strategic code organization.

## When To Use

**Symptoms that trigger this skill:**
- Skills-eval validation shows "[WARN] Large skill file" warnings
- SKILL.md files exceed 300 lines
- Multiple code blocks (10+) with similar functionality
- Heavy Python implementations inline with markdown
- Functions >20 lines embedded in documentation

**Quick Analysis:**
```bash
# Analyze any skill file for optimization opportunities
python skills/optimizing-large-skills/tools/optimization-patterns.py \
  skills/path/SKILL.md --verbose --generate-plan
```

## When NOT To Use

- Skill is under 300 lines and well-organized

## Core Pattern: Externalize-Consolidate-Progress

### Transformation Pattern

**Before**: 654-line skill with heavy inline Python implementations
**After**: ~150-line skill with external tools and references

**Key Changes:**
- Externalize heavy implementations (>20 lines) to dedicated tools
- Consolidate similar functions with parameterization
- Replace code blocks with structured data and tool references
- Implement progressive loading for non-essential content

## Quick Reference

### Size Reduction Strategies

| Strategy | Impact | When to Use |
|----------|--------|-------------|
| **Externalize Python modules** | 60-70% reduction | Heavy implementations (>20 lines) |
| **Consolidate similar functions** | 15-20% reduction | Repeated patterns with minor variations |
| **Replace code with structured data** | 10-15% reduction | Configuration-driven logic |
| **Progressive loading patterns** | 5-10% reduction | Multi-stage workflows |

### File Organization
```
skill-name/
  SKILL.md              # Core documentation (~150-200 lines)
  modules/
    examples.md         # Usage examples and anti-patterns
    patterns.md         # Detailed implementation patterns
  tools/
    analyzer.py         # Heavy implementations with CLI
    config.yaml         # Structured data
  examples/
    basic-usage.py      # Minimal working example
```

## Optimization Workflow

### Phase 1: Analysis
- [ ] Identify files >300 lines
- [ ] Count code blocks and functions
- [ ] Measure inline code vs documentation ratio
- [ ] Find repeated patterns and similar functions

### Phase 2: Externalization
- [ ] Move heavy implementations (>20 lines) to separate files
- [ ] Add CLI interfaces to externalized tools
- [ ] Create tool directory structure
- [ ] Add usage examples for each tool

### Phase 3: Consolidation
- [ ] Merge similar functions with parameterization
- [ ] Replace code blocks with structured data where appropriate
- [ ] Implement progressive loading for non-essential content
- [ ] Update skill documentation to reference external tools

### Phase 4: Validation
- [ ] Verify line count <300 (target: 150-200)
- [ ] Test all externalized tools work correctly
- [ ] Confirm progressive loading functions
- [ ] Run skills-eval validation to verify size reduction

## Quick Decision Tree

```
Is skill >300 lines?
├─ No → Continue as-is (well-organized skills don't need optimization)
└─ Yes → Analyze composition
    ├─ Has heavy code blocks (>20 lines)?
    │  └─ Yes → Externalize to tools/ with CLI (60-70% reduction)
    ├─ Has repeated patterns?
    │  └─ Yes → Consolidate with parameterization (15-20% reduction)
    ├─ Has structured config data embedded?
    │  └─ Yes → Extract to config.yaml (10-15% reduction)
    └─ Has non-essential details?
       └─ Yes → Use progressive loading (5-10% reduction)
```

## Key Success Factors

**DO:**
- ✅ Always add CLI interfaces to external tools
- ✅ Keep core concepts inline in SKILL.md
- ✅ Consolidate related functionality
- ✅ Include working examples
- ✅ Test all tools have correct references

**DON'T:**
- ❌ Externalize without CLI (hard to use/test)
- ❌ Create too many small files (increases complexity)
- ❌ Remove essential documentation (reduces discoverability)
- ❌ Add complex dependencies (hard to maintain)
- ❌ Skip usage examples (unclear tool usage)

## Next Steps

1. **Run automated analysis**: Use `optimization-patterns.py` to generate optimization plan
2. **Review modules**: Check `modules/patterns.md` for detailed implementation patterns
3. **Learn from examples**: Review `modules/examples.md` for anti-patterns to avoid
4. **Apply systematically**: Follow the 4-phase workflow above
5. **Validate results**: Run skills-eval to confirm optimization success

## Modules

- **[Detailed Patterns](modules/patterns.md)** - Externalization, consolidation, and progressive loading implementation details
- **[Examples & Anti-Patterns](modules/examples.md)** - Real-world impact, common mistakes, and rationalization prevention

## Result

**Expected Outcome:**
- 50-70% line count reduction
- 40-60% token usage reduction
- No skills-eval warnings
- Clear separation of concerns
- Maintainable external tools with CLI interfaces

Overview

This skill provides a systematic methodology to reduce large skill file size through externalization, consolidation, and progressive loading patterns. It targets skills that exceed ~300 lines, contain many similar code blocks, or embed heavy implementation details inline with documentation. The goal is to preserve functionality while improving maintainability, testability, and token efficiency.

How this skill works

The skill analyzes a target skill file to identify long inline implementations, repeated patterns, and embedded configuration. Heavy functions are moved into dedicated tool modules with CLI interfaces, similar functions are consolidated via parameterization, and non-essential sections are converted to progressively loaded resources. It produces a stepwise plan and verification checklist to reach a target compact documentation surface while keeping working examples and references to external tools.

When to use it

  • Skills-eval reports "Large skill file" warnings
  • Skill source exceeds ~300 lines or is hard to scan
  • There are 10+ similar code blocks or many long functions inline
  • Documentation mixes heavy Python implementations with prose
  • You need to reduce token usage for runtime execution or model prompts

Best practices

  • Externalize implementations >20 lines into tools with CLI so they remain testable
  • Consolidate repeated patterns into parameterized functions rather than duplicating code
  • Replace inline code with structured configuration where possible
  • Keep core concepts and examples inline, move heavy examples to example modules
  • Implement progressive loading for non-essential examples or deep reference material
  • Verify each external tool with unit or CLI tests after extraction

Example use cases

  • Reduce a 600+ line skill into ~150-200 lines by moving heavy logic to tools/ and examples/
  • Turn many repeated parsing snippets into a single parameterized parser utility
  • Extract large embedded Python scripts into standalone modules with CLI for easier testing and reuse
  • Convert embedded configuration blocks into YAML files referenced by the compact skill documentation
  • Apply progressive loading to load advanced examples only when requested to cut token cost

FAQ

Will extracting code break usage for end users?

No, if you provide CLI interfaces and clear references. External tools must include examples and installation notes so users can run them transparently.

How much size reduction can I expect?

Typical results show 50–70% line count reduction and 40–60% token usage reduction when heavy logic is externalized and repeated patterns are consolidated.