skills/optimize-rules/SKILL.md
Optimize Claude Code rules by consolidating into a single efficient file. Triggers on 'optimize rules', 'optimize my rules', or /optimize-rules.
npx skillsauth add agentic-cookbook/tools optimize-rulesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
If $ARGUMENTS is --version, respond with exactly:
optimize-rules v1.1.0
Then stop. Do not continue with the rest of the skill.
Otherwise, print optimize-rules v1.1.0 as the first line of output, then proceed.
Version check: Read ${CLAUDE_SKILL_DIR}/SKILL.md from disk and extract the version: field from frontmatter. If it differs from this skill's version (1.1.0), print:
⚠ This skill is running v1.1.0 but vA.B.C is installed. Restart the session to use the latest version.
Continue running — do not stop.
Consolidate multiple Claude Code rule files into a single optimized file, reducing per-turn context cost while preserving all behavioral constraints.
--dry-run mode is read-only — it never modifies, creates, or deletes any filesParse $ARGUMENTS for flags and path:
--revert → jump to the Revert Workflow (Step 3)--dry-run → set dry-run mode (run audit and proposal only, no modifications)If no path is provided, default to .claude/rules/.
Resolve the path to an absolute path. Verify the directory exists. If it does not exist, print:
ERROR: Directory not found:
<path>
And stop.
If --dry-run is set, skip this step entirely — proceed directly to Step 4.
Before any work, print:
Rule Optimization
This skill will consolidate your rule files into a single optimized file. Your originals will be backed up and can be restored at any time with
/optimize-rules --revert.
Use AskUserQuestion: "Continue with rule optimization?"
Options:
Runs when --revert is present, or called internally by Step 4 during re-optimization.
Resolve target — use the path from Step 1 (or default .claude/rules/)
Compute backup path — the backup directory is a sibling of the target with the name unoptimized-rules/. For example:
.claude/rules/ → .claude/unoptimized-rules/foo/rules/ → foo/unoptimized-rules/Verify backup exists — if the backup directory does not exist, print:
No backup found at
<backup path>. Nothing to revert.
And stop.
Delete optimized-rules.md from the target directory. If it does not exist, print a warning but continue.
Copy all .md files from the backup directory back to the target directory.
Remove the backup directory.
Print confirmation:
=== REVERTED ===
Restored <n> rule files to <target path>
Removed backup at <backup path>
If invoked via --revert: stop here — do not continue to optimization phases.
If invoked internally by Step 4: continue to Phase 1.
Use Glob to find all *.md files in the target directory. If none found, print:
No
.mdfiles found in<path>. Nothing to optimize.
And stop.
Skip if --dry-run. Check if the backup directory already exists. If it does:
Read all .md files. Count total files, lines, and bytes. Store as the baseline.
Read every .md rule file in the target directory. For each file, extract:
globs, description)globs frontmatter.Print the audit summary:
=== AUDIT ===
Rules: <n> files, <lines> lines, <bytes> bytes
Constraints: <n> MUST, <n> MUST NOT, <n> SHOULD
Duplicates: <n> cross-file duplicates found
Mandatory reads: <n> external file references
Ungated rules: <n> (content-specific but no globs)
List the per-file breakdown:
<filename> <lines> lines <bytes> bytes <constraint count> constraints
...
If --dry-run is set, also print a detailed landscape report after the audit summary:
=== RULES LANDSCAPE ===
Directory: <absolute path>
Previously optimized: yes/no (backup directory exists: yes/no)
--- File Details ---
<For each .md file, print:>
<filename>
Type: <symlink → target | regular file>
Frontmatter: <list key frontmatter fields: globs, description>
Lines: <n> Bytes: <n>
Constraints: <n> MUST, <n> MUST NOT, <n> SHOULD
External reads: <list any mandatory file references, or "none">
Scope: <"gated by globs: <pattern>" or "ungated (applies to all files)">
--- Cross-File Analysis ---
Duplicate constraints: <n>
<For each duplicate group, list the constraint text and which files contain it>
Semantic overlaps: <n>
<For each overlap, list the constraint variants and which files contain them>
--- Symlink Map ---
<For each symlink, show: filename → absolute target path>
<For each regular file, show: filename (regular file)>
Based on audit findings, propose how to consolidate all rules into one optimized-rules.md:
Print the proposal:
=== OPTIMIZATION PLAN ===
Input: <n> rule files (<lines> lines, <bytes> bytes)
Output: 1 file (optimized-rules.md)
Strategy:
- Merge <n> files into unified structure with <n> concern sections
- Deduplicate <n> overlapping constraints
- Consolidate <n> MUST NOT items into unified section
- Inline <n> mandatory read summaries
- [any other specific proposals]
Estimated reduction: ~<pct>%
If --dry-run is set, print:
=== DRY RUN COMPLETE ===
No files were modified. Run `/optimize-rules` (without --dry-run) to execute.
Then stop. Do not continue to Phase 3.
Otherwise, use AskUserQuestion to confirm:
"Proceed with optimization?"
Options:
unoptimized-rules/)..md files from target to backup directory.${CLAUDE_SKILL_DIR}/references/optimization-checklist.md.optimized-rules.md:
optimized-rules.md to the target directory..md files from the target directory (do NOT remove optimized-rules.md).optimized-rules.mdVALIDATION FAILED: Missing constraint from <source file>: "<constraint text>"optimized-rules.mdPrint the final report:
=== OPTIMIZATION COMPLETE ===
Before: <n> files, <lines> lines, <bytes> bytes
After: 1 file, <lines> lines, <bytes> bytes
Reduction: <pct>% lines, <pct>% bytes
Constraints preserved: <n>/<n> ✓
Backup: <backup dir path>
To revert: /optimize-rules --revert [path]
Optimize the default rules directory:
/optimize-rules
Optimize a custom rules path:
/optimize-rules path/to/my/rules/
Preview what optimization would do (read-only):
/optimize-rules --dry-run
Dry-run a custom rules path:
/optimize-rules --dry-run path/to/my/rules/
Restore original rules after optimization:
/optimize-rules --revert
The optimization is complete. The original rules are backed up and can be restored with /optimize-rules --revert.
testing
Validate cookbook integrity — frontmatter, cross-references, indexes, skills, rules, file placement. Run from cookbook or consuming project.
tools
Remove the agentic cookbook from your project. Removes rules, state files, CLAUDE.md section, and optionally global plugins and status line.
tools
Analyze a macOS SwiftUI app and plan its conversion to native AppKit. Triggers on 'port to AppKit', 'convert SwiftUI to AppKit', 'remove SwiftUI', or /port-swiftui-to-appkit.
tools
--- name: plan-cookbook-recipe version: 2.3.0 description: Interactively design a new cookbook recipe through guided discussion disable-model-invocation: true context: fork allowed-tools: Read, Glob, Grep, Agent, Write, Edit, AskUserQuestion, Bash(git *), Bash(mkdir *), Bash(ls *) argument-hint: [recipe-name] [--version] --- # Plan Agentic Cookbook Recipe v2.3.0 ## Startup **First action**: If `$ARGUMENTS` is `--version`, print `plan-cookbook-recipe v2.3.0` and stop. Otherwise, print `plan-c