refactor-skill-structure
Refactor an over-long or poorly structured SKILL.md by extracting examples to references/EXAMPLES.md, splitting compound procedures, and reorganizing sections for progressive disclosure. Use when a skill exceeds the 500-line CI limit, when code blocks dominate the skill body, when a procedure step contains multiple unrelated operations, or after a content update pushed the skill over the line limit.
Best use case
refactor-skill-structure is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Refactor an over-long or poorly structured SKILL.md by extracting examples to references/EXAMPLES.md, splitting compound procedures, and reorganizing sections for progressive disclosure. Use when a skill exceeds the 500-line CI limit, when code blocks dominate the skill body, when a procedure step contains multiple unrelated operations, or after a content update pushed the skill over the line limit.
Teams using refactor-skill-structure should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/refactor-skill-structure/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How refactor-skill-structure Compares
| Feature / Agent | refactor-skill-structure | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Refactor an over-long or poorly structured SKILL.md by extracting examples to references/EXAMPLES.md, splitting compound procedures, and reorganizing sections for progressive disclosure. Use when a skill exceeds the 500-line CI limit, when code blocks dominate the skill body, when a procedure step contains multiple unrelated operations, or after a content update pushed the skill over the line limit.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
SKILL.md Source
# Refactor Skill Structure
Refactor a SKILL.md that has exceeded the 500-line limit or developed structural problems. This skill extracts extended code examples to `references/EXAMPLES.md`, splits compound procedures into focused sub-procedures, adds cross-references for progressive disclosure, and verifies the skill remains complete and valid after restructuring.
## When to Use
- A skill exceeds the 500-line limit enforced by CI
- A single procedure step contains multiple unrelated operations that should be separate steps
- Code blocks longer than 15 lines dominate the SKILL.md and could be extracted
- The skill has accumulated ad-hoc sections that break the standard six-section structure
- After a content update pushed the skill over the line limit
- A skill review flagged structural issues that go beyond content quality
## Inputs
- **Required**: Path to the SKILL.md file to refactor
- **Optional**: Target line count (default: aim for 80% of the 500-line limit, i.e., ~400 lines)
- **Optional**: Whether to create `references/EXAMPLES.md` (default: yes, if extractable content exists)
- **Optional**: Whether to split into multiple skills (default: no, prefer extraction first)
## Procedure
### Step 1: Measure Current Line Count and Identify Bloat Sources
Read the skill and create a section-by-section line budget to identify where the bloat is.
```bash
# Total line count
wc -l < skills/<skill-name>/SKILL.md
# Line count per section (approximate)
grep -n "^## \|^### " skills/<skill-name>/SKILL.md
```
Classify bloat sources:
- **Extractable**: Code blocks >15 lines, full configuration examples, multi-variant examples
- **Splittable**: Compound procedure steps doing 2+ unrelated operations
- **Trimable**: Redundant explanations, overly verbose context sentences
- **Structural**: Ad-hoc sections not in the standard six-section structure
**Got:** A line budget showing which sections are over-sized and which bloat category applies to each. The largest sections are the primary refactoring targets.
**If fail:** If the skill is under 500 lines and no structural issues are apparent, this skill may not be needed. Verify the refactoring request is justified before proceeding.
### Step 2: Extract Code Blocks to references/EXAMPLES.md
Move code blocks longer than 15 lines to a `references/EXAMPLES.md` file, leaving brief inline snippets (3-10 lines) in the main SKILL.md.
1. Create the references directory:
```bash
mkdir -p skills/<skill-name>/references/
```
2. For each extractable code block:
- Copy the full code block to `references/EXAMPLES.md` under a descriptive heading
- Replace the code block in SKILL.md with a brief 3-5 line snippet
- Add a cross-reference: `See [EXAMPLES.md](references/EXAMPLES.md#heading) for the complete configuration.`
3. Structure `references/EXAMPLES.md` with clear headings:
```markdown
# Examples
## Example 1: Full Configuration
Complete configuration file for [context]:
\```yaml
# ... full config here ...
\```
## Example 2: Multi-Variant Setup
### Variant A: Development
\```yaml
# ... dev config ...
\```
### Variant B: Production
\```yaml
# ... prod config ...
\```
```
**Got:** All code blocks >15 lines are extracted. The main SKILL.md retains brief inline snippets for readability. Cross-references link to the extracted content. `references/EXAMPLES.md` is well-organized with descriptive headings.
**If fail:** If extracting code blocks does not reduce the line count sufficiently (still over 500), proceed to Step 3 for procedure splitting. If the skill has very few code blocks (e.g., a natural-language skill), focus on Steps 3 and 4 instead.
### Step 3: Split Compound Procedures into Focused Steps
Identify procedure steps that perform multiple unrelated operations and split them.
Signs of a compound step:
- The step title contains "and" (e.g., "Configure Database and Set Up Caching")
- The step has multiple Expected/On failure blocks (or should have)
- The step is longer than 30 lines
- The step could be skipped or done in a different order from its sub-parts
For each compound step:
1. Identify the distinct operations within the step
2. Create a new `### Step N:` for each operation
3. Renumber subsequent steps
4. Ensure each new step has its own Expected and On failure blocks
5. Add transition context between new steps
**Got:** Each procedure step does one thing. No step exceeds 30 lines. Step count may increase but each step is independently verifiable.
**If fail:** If splitting a step creates steps that are too granular (e.g., 20+ total steps), consider grouping related micro-steps under a single step with numbered sub-steps instead. The sweet spot is 5-12 procedure steps.
### Step 4: Add Cross-References from SKILL.md to Extracted Content
Ensure the main SKILL.md maintains readability and discoverability after extraction.
For each extraction:
1. The inline snippet in SKILL.md should be self-sufficient for the common case
2. The cross-reference should explain what additional content is available
3. Use relative paths: `[EXAMPLES.md](references/EXAMPLES.md#section-anchor)`
Cross-reference patterns:
- After a brief code snippet: `See [EXAMPLES.md](references/EXAMPLES.md#full-configuration) for the complete configuration with all options.`
- For multi-variant examples: `See [EXAMPLES.md](references/EXAMPLES.md#variants) for development, staging, and production variants.`
- For extended troubleshooting: `See [EXAMPLES.md](references/EXAMPLES.md#troubleshooting) for additional error scenarios.`
**Got:** Every extraction has a corresponding cross-reference. A reader can follow the main SKILL.md for the common case and drill into references for details.
**If fail:** If cross-references make the text flow awkward, consolidate multiple references into a single note at the end of the procedure step: `For extended examples including [X], [Y], and [Z], see [EXAMPLES.md](references/EXAMPLES.md).`
### Step 5: Verify Line Count After Refactoring
Re-measure the SKILL.md line count after all changes.
```bash
# Check main SKILL.md
lines=$(wc -l < skills/<skill-name>/SKILL.md)
[ "$lines" -le 500 ] && echo "SKILL.md: OK ($lines lines)" || echo "SKILL.md: STILL OVER ($lines lines)"
# Check references file if created
if [ -f skills/<skill-name>/references/EXAMPLES.md ]; then
ref_lines=$(wc -l < skills/<skill-name>/references/EXAMPLES.md)
echo "EXAMPLES.md: $ref_lines lines"
fi
# Total content
echo "Total content: $((lines + ${ref_lines:-0})) lines"
```
**Got:** SKILL.md is under 500 lines. Ideally under 400 lines to leave room for future growth. The `references/EXAMPLES.md` has no line limit.
**If fail:** If still over 500 lines after extraction and splitting, consider whether the skill should be decomposed into two separate skills. A skill covering too much ground is a sign of scope creep. Use `create-skill` to author the second skill and update Related Skills cross-references in both.
### Step 6: Validate All Sections Still Present
After refactoring, verify the skill still has all required sections and the frontmatter is intact.
Run the `review-skill-format` checklist:
1. YAML frontmatter parses correctly
2. All six required sections present (When to Use, Inputs, Procedure, Validation, Common Pitfalls, Related Skills)
3. Every procedure step has Expected and On failure blocks
4. No orphaned cross-references (all links resolve)
```bash
# Quick section check
for section in "## When to Use" "## Inputs" "## Procedure" "## Pitfalls" "## Related Skills"; do
grep -q "$section" skills/<skill-name>/SKILL.md && echo "$section: OK" || echo "$section: MISSING"
done
grep -qE "## Validation( Checklist)?" skills/<skill-name>/SKILL.md && echo "Validation: OK" || echo "Validation: MISSING"
```
**Got:** All sections present. No content was accidentally deleted during extraction. Cross-references in SKILL.md resolve to actual headings in EXAMPLES.md.
**If fail:** If a section was accidentally removed, restore it from git history: `git diff skills/<skill-name>/SKILL.md` to see what changed. If cross-references are broken, verify the heading anchors in EXAMPLES.md match the links in SKILL.md (GitHub-flavored markdown anchor rules: lowercase, hyphens for spaces, strip punctuation).
## Validation
- [ ] SKILL.md line count is 500 or fewer
- [ ] All code blocks in SKILL.md are 15 lines or fewer
- [ ] Extracted content is in `references/EXAMPLES.md` with descriptive headings
- [ ] Every extraction has a cross-reference in the main SKILL.md
- [ ] No compound procedure steps remain (each step does one thing)
- [ ] All six required sections are present after refactoring
- [ ] Every procedure step has **Got:** and **If fail:** blocks
- [ ] YAML frontmatter is intact and parseable
- [ ] Cross-reference links resolve to actual headings in EXAMPLES.md
- [ ] `review-skill-format` validation passes on the refactored skill
## Pitfalls
- **Extracting too aggressively**: Moving all code to references makes the main SKILL.md unreadable. Keep 3-10 line snippets inline for the common case. Only extract blocks that are >15 lines or show multiple variants.
- **Broken anchor links**: GitHub-flavored markdown anchors are case-sensitive in some renderers. Use lowercase headings in EXAMPLES.md and match exactly in cross-references. Test with `grep -c "heading-text" references/EXAMPLES.md`.
- **Losing Expected/On failure during splits**: When splitting compound steps, ensure each new step gets its own Expected and On failure blocks. It is easy to leave one step without these blocks after a split.
- **Creating too many tiny steps**: Splitting should produce 5-12 procedure steps. If you end up with 15+, you have split too aggressively. Merge related micro-steps back into logical groups.
- **Forgetting to update references/EXAMPLES.md headings**: If you rename a section in EXAMPLES.md, all cross-reference anchors in SKILL.md must be updated. Grep for the old anchor name to catch all references.
## Related Skills
- `review-skill-format` — Run format validation after refactoring to confirm the skill is still compliant
- `update-skill-content` — Content updates are often the trigger for structural refactoring when they push a skill over the line limit
- `create-skill` — Reference the canonical structure when deciding how to organize extracted content
- `evolve-skill` — When a skill needs to be split into two separate skills, use evolution to create the derivativeRelated Skills
tidy-project-structure
Organize project files into conventional directories, update stale READMEs, clean configuration drift, and archive deprecated items without changing code logic. Use when files are scattered without clear organization, READMEs are outdated or contain broken examples, configuration files have multiplied across dev/staging/prod, deprecated files remain in the project root, or naming conventions are inconsistent across directories.
provision-infrastructure-terraform
Provision and manage cloud infrastructure using Terraform with HCL modules, remote state backends, workspaces, and plan/apply workflow. Implement infrastructure as code patterns with variable management, output values, and state locking for team collaboration. Use when provisioning new cloud infrastructure, migrating from ClickOps or CloudFormation to declarative IaC, managing multi-environment infrastructure, versioning infrastructure changes alongside application code, or enforcing standards through reusable modules.
create-work-breakdown-structure
Create a Work Breakdown Structure (WBS) and WBS Dictionary from project charter deliverables. Covers hierarchical decomposition, WBS coding, effort estimation, dependency identification, and critical path candidates. Use after a project charter is approved, when planning a classic or waterfall project with defined deliverables, breaking a large initiative into manageable work packages, or establishing a basis for effort estimation and resource planning.
skill-name-here
One to three sentences describing what this skill accomplishes, followed by key activation triggers. This field is the primary mechanism agents use to decide whether to activate the skill — it is read during discovery before the full body is loaded. Start with a verb. Include the most important "when to use" conditions inline. Max 1024 characters.
write-vignette
Create R package vignettes using R Markdown or Quarto. Covers vignette setup, YAML configuration, code chunk options, building and testing, and CRAN requirements for vignettes. Use when adding a Getting Started tutorial, documenting complex workflows spanning multiple functions, creating domain-specific guides, or when CRAN submission requires user-facing documentation beyond function help pages.
write-validation-documentation
Write IQ/OQ/PQ validation documentation for computerized systems in regulated environments. Covers protocols, reports, test scripts, deviation handling, and approval workflows. Use when validating R or other software for regulated use, preparing for a regulatory audit, documenting qualification of computing environments, or creating and updating validation protocols and reports for new or re-qualified systems.
write-testthat-tests
Write comprehensive testthat (edition 3) tests for R package functions. Covers test organization, expectations, fixtures, mocking, snapshot tests, parameterized tests, and achieving high coverage. Use when adding tests for new package functions, increasing test coverage for existing code, writing regression tests for bug fixes, or setting up test infrastructure for a package that lacks it.
write-standard-operating-procedure
Write a GxP-compliant Standard Operating Procedure (SOP). Covers regulatory SOP template structure (purpose, scope, definitions, responsibilities, procedure, references, revision history), approval workflow design, periodic review scheduling, and operational procedures for system use. Use when a new validated system requires operational procedures, when existing informal procedures need formalisation, when an audit finding cites missing procedures, when a change control triggers SOP updates, or when periodic review identifies outdated procedural content.
write-roxygen-docs
Write roxygen2 documentation for R package functions, datasets, and classes. Covers all standard tags, cross-references, examples, and generating NAMESPACE entries. Follows tidyverse documentation style. Use when adding documentation to new exported functions, documenting internal helpers or datasets, documenting S3/S4/R6 classes and methods, or fixing documentation-related R CMD check notes.
write-incident-runbook
Create structured incident runbooks with diagnostic steps, resolution procedures, escalation paths, and communication templates for effective incident response. Use when documenting response procedures for recurring alerts, standardizing incident response across an on-call rotation, reducing MTTR with clear diagnostic steps, creating training materials for new team members, or linking alert annotations directly to resolution procedures.
write-helm-chart
Create production-ready Helm charts for Kubernetes application deployment with templating, values management, chart dependencies, hooks, and testing. Covers chart structure, Go template syntax, values.yaml design, chart repositories, versioning, and best practices for maintainable and reusable charts. Use when packaging a Kubernetes application for repeatable deployments, parameterizing manifests for multiple environments, managing complex multi-component applications with dependencies, or standardizing deployment practices with versioned rollback capability across teams.
write-continue-here
Write a CONTINUE_HERE.md file capturing current session state so a fresh Claude Code session can pick up where this one left off. Covers assessing recent work, structuring the continuation file with objective, completed, in-progress, next-steps, and context sections, and verifying the file is actionable. Use when ending a session with unfinished work, handing off context between sessions, or preserving task state that git alone cannot capture.