From please-optimize-my-claude
Optimizes CLAUDE.md hierarchy across global/project/repo levels: deduplicates content, detects misplacements, compresses bloat, checks staleness, generates token usage reports. Use for bloated or disorganized CLAUDE.md files.
npx claudepluginhub thedoublejay/please-optimize-my-claudeThis skill uses the workspace's default tool permissions.
Optimize the CLAUDE.md hierarchy in this project — deduplicate content across levels,
Optimizes CLAUDE.md hierarchies, .claude/rules, ecosystem files, and docs/ folders per Anthropic best practices. Detects redundancies, conflicts, and suggests improvements.
Analyzes CLAUDE.md files for token bloat by checking overall size, large sections, duplicates, verbose patterns, long code blocks, excessive whitespace; suggests fixes with savings estimates.
Audits CLAUDE.md files in repositories: discovers files via find, evaluates quality against rubrics, generates reports, and applies targeted improvements after approval.
Share bugs, ideas, or general feedback.
Optimize the CLAUDE.md hierarchy in this project — deduplicate content across levels, detect misplaced sections, compress bloat, and generate visual token reports.
auto → Apply all optimizations (prompts for backup)analyze → Report only, no changesrestore → Undo from .claude-md-backup/--research → Also fetch latest best practices from webParse $ARGUMENTS to determine mode and flags.
Execute these phases in order:
~/.claude/CLAUDE.md (global). If not found or permission denied, note and continue.~/.claude/rules/**/*.md (global rules). Note which have paths: frontmatter (conditional loading)..git/ directory.<project-root>/CLAUDE.md if it exists.**/CLAUDE.md excluding node_modules/, .git/, dist/, build/, vendor/, .claude-md-backup/.CLAUDE.local.md alongside each CLAUDE.md found..claude/rules/**/*.md in the project root and each subdirectory.@path/to/file import references (relative to importing file, up to 5 levels deep).{ global, globalRules, root, rootRules, subdirectories: [{claudeMd, localMd, rules, imports}...] }.<!-- ... -->) before counting (Claude Code strips these before injection).Run ALL detectors. Collect issues into a list with structure:
{ type, severity, file, lines, description, suggestion, tokensRecoverable }
Detectors to run:
2a. Duplication Detection — Compare content blocks across all hierarchy levels (including .claude/rules/, CLAUDE.local.md, @import content). Flag exact and semantic duplicates (same behavior — removing either loses no unique guidance); identify their lowest common ancestor level.
2b. Misplacement Detection — Flag: project-specific patterns (repo names, ticket IDs like [PROJ-1234]) in global; repo-specific paths/commands in root; universal rules buried in repo files.
2c. Bloat Detection — Flag: sections >300 words, oversized code examples, repeated explanations, workflow blocks duplicated across repos.
2d. Stale Content Check — Verify npm run commands exist in nearest package.json. Flag sections unchanged 90+ days via git blame. Check for stale file/directory references.
2e. Contradiction Detection — Find conflicting instructions across levels on the same topic.
Distinguish: contradiction (mutually exclusive) vs refinement (one narrows the other) vs exception
(one scopes out a subset). Only flag actual contradictions. Respect paths: frontmatter scoping —
rules in different path scopes cannot contradict. Present with confidence levels.
2f. Token Budget Audit — Flag files exceeding budgets (global <1,000, root <3,000, repo <2,500). Calculate "What Claude Sees" per working directory: all of CLAUDE.md (ancestor levels), CLAUDE.local.md, rules (unconditional), rules (path-conditional, shown separately), and @import-expanded content.
2g. Best Practices Comparison — Use Glob to find **/please-optimize-my-claude/references/best-practices.md, then Read it for the reference. Check for missing recommended sections, anti-patterns, structure issues. With --research, also fetch latest recommendations via WebSearch/WebFetch.
2h. Missing Index Detection — Check if root CLAUDE.md has a repository/directory index. If missing, prepare an auto-generated index table (repo name, type, purpose, CLAUDE.md link).
2i. Security Scan — Scan all CLAUDE.md files for accidentally committed sensitive content. Flag with severity critical:
sk-, ghp_, xoxb-, AKIA (AWS), Bearer, base64 blobs >40 charslocalhost with ports, VPN/internal domainspassword, secret, api_key, token, private_key followed by = or : and a non-placeholder valueENV_VAR=actual_value patterns (flag the value, not the variable name)For each finding: show the file, line number, matched pattern, and a suggested replacement (e.g., redact to <your-api-key> or remove the line entirely). Security issues are always shown first in the report, before all other findings. In auto mode, prompt separately before removing security findings — never silently delete them.
Output the visual report to the user. Use Unicode box drawing characters (─│┌┐└┘├┤┬┴┼), block elements (█░), and status indicators (✅ ⚠️).
Include ALL report sections:
Interactive: Show the full report first, then use AskUserQuestion once with options: "Apply all", "Pick categories to apply", "Review each finding individually", "Skip (report only)". If reviewing individually, show each issue with a diff preview and ask: "Apply? [y]es / [n]o / [s]kip all of this type / [q]uit".
Auto: Prompt once for backup confirmation. Backup project files to
.claude-md-backup/<ISO-8601-timestamp>/ (preserving relative paths) and global files to
~/.claude/backups/<ISO-8601-timestamp>/. Auto-add .claude-md-backup/ to project .gitignore
if not present. Keep last 5 backups. Apply all optimizations. Show Phase 5 comparison.
Analyze: Stop after Phase 3. Do not modify any files.
Restore: Find the latest directory in .claude-md-backup/. List files to restore.
Confirm with user. Copy files back to original locations.
After applying optimizations, re-count tokens for all modified files. Show the before/after comparison with bar charts and percentage reduction. Show backup path and restore command.
If discovery finds only 1 CLAUDE.md file AND it exceeds 3,000 tokens, offer to split it into a hierarchy. Identify content categories (global preferences, project conventions, repo-specific details) and propose a split plan.
~/.claude/backups/, project files to .claude-md-backup/paths: scoping