/agentic-repos:ar-optimizerfrom agentic-repos
Audit and optimize a project's AI rule files. Detects redundancies, conflicts, staleness, example/rationale bloat, and fragmentation. Produces detailed reports and interactive cleanup recommendations. Say "ar-optimizer" or "optimize AI rules" to run.
Ships in agentic-repos. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Version: 2.3.0
Audit and optimize a project's AI rule files. Identifies issues that directly impact Claude's performance, context bloat, ignored instructions, conflicts, based on official Claude Code documentation:
ar-upgrade to audit only the files that upgrade touched (scoped, see "Scoped Mode" below)When invoked by ar-upgrade (or any caller) with a fixed scope, the optimizer skips full-project discovery and audits ONLY the provided files. This is the default behavior post-upgrade because tuning that lives outside the upgrade's touched files is presumed-good and must not be disturbed.
Either:
--scope flag or via an explicit instruction in the prompt, OR.claude/ar-optimizer.scope file exists in the project root with a newline-separated file list (consumed and deleted by the optimizer).When in scoped mode:
The whole point is to not disturb tuning in untouched files. If the optimizer would normally flag a redundancy that requires editing both an in-scope and out-of-scope file, prefer the in-scope edit and leave the out-of-scope file alone with a note.
Tell the user up front:
Scoped optimizer pass: {N} files (from {source}).
Files outside this scope will not be audited or changed in this run.
For a full-project audit, re-run `ar-optimizer` with no scope.
Skip this phase in Scoped Mode. Go straight to Phase 2 with the provided file list as the discovery manifest.
MUST find ALL AI configuration files across the entire project.
1a. Search by known patterns:
# Find all AI config files
find . -name "CLAUDE.md" -o -name "claude.md" -o -type d -name ".claude" \
-o -name ".cursorrules" -o -path "*/.cursor/rules/*.mdc" \
-o -name "AGENTS.md" -o -name "agents.md" -o -name "CODEX.md" \
-o -name "AI.md" -o -name "RULES.md" -o -name "CODING_STANDARDS.md" \
-o -name "CONVENTIONS.md" -o -name "GEMINI.md" -o -name ".windsurfrules" \
-o -path "*/.github/copilot-instructions.md" \
-o -path "*/.claude/skills/*/SKILL.md" -o -path "*/SKILLS/*.md" \
-o -name ".aider*"
1b. Search by content (catch custom locations):
# Find markdown files with AI instruction phrases
find . -name "*.md" -exec grep -l -i "when working on this project\|AI assistant\|code style\|do not\|always use\|never commit" {} + 2>/dev/null
1c. Check user-level config:
ls -la ~/.claude/CLAUDE.md 2>/dev/null
1d. Understand tech stack (for inferable-from-code detection):
# Detect frameworks and build tools
grep -E '"(react|vue|angular|express|next)"' package.json 2>/dev/null
for f in build.gradle pom.xml Cargo.toml pyproject.toml; do [ -f "$f" ] && echo "$f"; done
1e. Check for project configuration (if available):
# Read project configuration if present
if [ -f .claude/config_hints.json ]; then
STANDARDS_LOCATION=$(jq -r '.standards_location // ".cursor/rules"' .claude/config_hints.json)
PLATFORM=$(jq -r '.platform // "unknown"' .claude/config_hints.json)
echo "Standards location: $STANDARDS_LOCATION"
echo "Platform: $PLATFORM"
fi
Output format:
## Discovery Results
**Files found:** {n}
### By Tool: Claude Code | Cursor | Generic | Skills | Custom
### Tech Stack: Languages | Frameworks | Build | Testing
| File | Lines | Est. Tokens | Status |
|------|-------|-------------|--------|
| CLAUDE.md | 250 | 1800 | ⚠️ Warning |
| **Total** | **595** | **4170** | ⚠️ High |
If no files found: Report "❌ No AI rule files found. Recommendation: Run /init to create CLAUDE.md"
Read each discovered file and extract every instruction/rule. Tag into categories:
Categories: CODE_STYLE (formatting, naming, imports) | ARCHITECTURE (structure, patterns, boundaries) | TESTING (strategy, coverage, frameworks) | GIT (commits, branching, PRs) | TOOLING (build, CI/CD, setup) | BEHAVIOR (AI persona, tone, verbosity) | WORKFLOW (steps, checklists, verification) | PROJECT_CONTEXT (domain knowledge, business logic) | SAFETY (destructive action guards) | PERFORMANCE (optimization, limits) | SECURITY (auth, secrets, vulnerabilities) | OTHER
Parsing checklist:
Output format:
## Parsed Instructions
### CLAUDE.md (1800 tokens)
1. [CODE_STYLE, line 12] "Use 4-space indentation for TypeScript files"
2. [ARCHITECTURE, line 45-60, 3 examples] "Organize code by feature, not type" (420 tokens)
...
**Total instructions parsed:** 47 | **Unique concepts:** ~35 (12 duplicates detected)
Run 14 checks across ALL parsed instructions. Each issue type directly impacts Claude's performance.
Detect: Same semantic instruction in 2+ files or 2+ locations in one file.
Example: "Use 4-space indentation" appears in AGENTS.md:12, .cursorrules:5, CLAUDE.md:30
Report: REDUNDANT, Indentation rule repeated 3× across 3 files
Detect: File restates its own point in different sections (AI-generated bloat pattern).
Heuristics: Same key phrase 2+ times in different sections | Numbered list defined once then re-listed | Paragraphs with >70% token overlap
Report: ECHO, "{phrase}" appears {n} times in {file} at lines {lines}
Detect: Two instructions oppose each other.
Example: AGENTS.md says "Always use named exports" but .cursorrules says "Prefer default exports"
Report: CONFLICT, Export style: named (AGENTS.md:14) vs default (.cursorrules:8)
Detect: References to deprecated packages/APIs, removed files/directories, outdated version numbers
Report: STALE, Reference to {thing} which no longer exists
Detect: Rule illustrated with 2+ examples that teach the same thing (AI-generated over-explanation).
Heuristics: 2+ code blocks demonstrating same pattern | Multiple "good vs bad" pairs teaching identical lesson | Verbose before/after comparisons
Example: "Use early returns" has 4 examples all showing if/return pattern → 3 are redundant
Report: EXAMPLE_BLOAT, "{rule}" has {n} examples in {file}, {n-1} can be removed
Detect: Closely related instructions scattered across many files instead of co-located.
Report: FRAGMENTED, {category} rules spread across {n} files: {list}
Detect: Instructions describing things Claude can determine by reading code.
Examples: ❌ "Use React 18" (package.json) | ❌ "Express.js for API" (imports) | ❌ "PostgreSQL database" (config files) | ❌ "Tests are in test/" (folder structure)
Report: INFERABLE, "{instruction}" can be determined from code (file: {file})
Best practice: "Only include what Claude can't infer from code alone"
Detect: Instructions describing standard language/framework conventions Claude already knows.
Examples: ❌ "Use camelCase for JS variables" | ❌ "Import React at top" | ❌ "Close database connections" | ❌ "Write clean code" | ❌ "Follow PEP 8"
Report: STANDARD_CONVENTION, "{instruction}" is standard {language/framework} convention Claude already knows
Best practice: Exclude "Standard language conventions" and "Self-evident practices"
Detect: Long API docs, tutorials, or reference material embedded in rules files.
Heuristics: Code blocks >30 lines | Detailed API reference sections | Tutorial "how to" sections >50 lines | Content duplicating external docs
Report: EMBEDDED_DOCS, {n} lines of documentation in {file} should be links to external docs
Best practice: "Exclude detailed API documentation (link to docs instead)"
Detect: Rules using "must", "never", "always", "critical" but lacking emphasis formatting.
Examples: ❌ "Never commit secrets to git" | ❌ "Always run tests before pushing" | ❌ "You must use git hooks"
Report: MISSING_EMPHASIS, Critical rule "{rule}" in {file} lacks emphasis (IMPORTANT/WARNING/etc.)
Best practice: "Add emphasis (e.g., 'IMPORTANT' or 'YOU MUST') to improve adherence"
Detect: CLAUDE.md token count exceeds recommended size.
Thresholds: Warning: >2000 tokens | Critical: >4000 tokens
Report: SIZE_WARNING, CLAUDE.md is {n} tokens ({percent}% of recommended max)
Why critical: CLAUDE.md loads every session. Recommended max: 150 lines / 2000 tokens.
disable-model-invocationDetect: Manually-invoked workflow skills lacking the disable-model-invocation: true flag.
Heuristics: Contains numbered steps | Has side effects (git, file writes, API calls) | Verb-based name (fix-, deploy-, run-*)
Carve-out, do NOT flag mid-flow / conversational action skills. A skill that the orchestrator (or the model mid-task) is expected to invoke programmatically must set disable-model-invocation: false on purpose, so model-invocability is correct, not a defect. Treat false as intentional for: skills the orchestrator hands off to during a run (ar-record-improvement, ar-taskflow-review, ar-taskflow-fix-comments) and conversational action skills the model should fire when the user asks (a_sk_commit, a_sk_pr). Only flag a true/missing flag on a skill that is genuinely user-only (setup/destructive/standalone, e.g. ar-init-*, ar-install, ar-upgrade).
Report: MISSING_FLAG, Skill "{name}" appears to be a manually-invoked workflow but lacks 'disable-model-invocation: true'
Best practice: "For skills you invoke manually, set disable-model-invocation: true to keep descriptions out of context until you need them; for skills meant to run mid-flow or fire on a conversational ask, set it false so the model can invoke them."
Detect: CLAUDE.md imports large files that should be skills instead.
Heuristics: @path/to/file.md syntax | Imported file >500 tokens | Contains domain knowledge or workflows (not project config)
Report: HEAVY_IMPORT, CLAUDE.md imports {file} ({n} tokens). Consider converting to skill (loads on-demand) instead.
Why critical: CLAUDE.md imports load every session. Skills only load when needed.
Detect: Skills/agents/rules carrying justification, history, or design-narration prose that doesn't change behavior. Instructions must say WHAT to do; WHY belongs in the CHANGELOG and commit history. Heuristics:
## Why this exists / ## Why this matters / **Why:** / **Why this asymmetry:** / **Rationale:** sections or blocks explaining design choices(NEW in vX.Y.Z), (vX.Y.Z change), (vX.Y.Z fix), "previously was…", "the vX.Y.Z design…", "pre-vX.Y.Z…", meaningless inside an installed artifact (an install is always exactly one version)## Purpose opener)⏱ Cost: adds a sub-agent round-trip, opt-in), these justify an opt-in default the user must choose, which IS behavior
Report: RATIONALE_BLOAT, {file}:{lines} "{marker}", delete; relocate nothing (the CHANGELOG already records the why)
Fix: delete the prose; if the rationale is genuinely undocumented, move it to the framework CHANGELOG entry, never keep it in the artifact body.Output a structured report with:
CRITICAL: Present ALL findings and get explicit approval before ANY changes. DO NOT proceed to Phase 6 until developer responds.
For each issue, present:
Developer can "apply all approved" or "skip".
After developer answers, produce concrete changeset:
## Proposed Changes
**Deletions:** Remove `.cursorrules` line 5 (redundant indentation rule)
**Modifications:** AGENTS.md:14 change "named exports" → "{developer's choice}"
**Consolidations:** Move all CODE_STYLE rules → AGENTS.md § Code Style | Remove CODE_STYLE from CLAUDE.md, .cursorrules
**New Additions:** Add missing SAFETY rule to AGENTS.md: "{rule}"
Ask: Shall I apply these changes? (yes / no / let me adjust)
If confirmed:
7a. Apply Changes (in order):
7b. Optimize Files - Apply compression rules to every affected file:
(NEW in vX.Y.Z) markers, design narration), see check 3n; the CHANGELOG already records the why7c. Show Before/After, per-file token table (before | after | reduction %)
7d. Re-validate, re-run Phases 2-4 to confirm zero conflicts, redundancies, bloat, and CLAUDE.md under 2000 tokens
7e. Final Report, issues resolved, files optimized/deleted, token reduction %, context impact (before → after tokens/session), next steps (test in new session, commit, run quarterly)
FIRST: Ask developer which file should be the single source of truth:
Multiple AI config files found. Which should be your single source of truth?
(a) AGENTS.md (conventional) | (b) CLAUDE.md (Claude Code) | (c) .cursorrules (Cursor) | (d) Other: ___
Recommendation: Choose file that's most complete, matches primary AI tool, easily imported by others.
Once determined, all consolidation recommendations use this file as target.
When consolidating:
@path/to/main.md syntax# .cursorrules → See @AGENTS.md for core rules. → ## Cursor-specific overrides: [Override] Use inline completions (AGENTS.md says plan first)[Override]What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub mahsanamin/agentic-repos --plugin agentic-repos20 skills in this plugin
/ar-agent-readyAssess how agent-ready a repository is and raise it. Reads the actual codebase, extracts its real conventions into rule files, wires the config seam, and reports a readiness scorecard. Say "ar-agent-ready", "make this repo agent-ready", or "extract the rules for this project"./ar-api-dd-compareAudit what the code ASSUMES against what production ACTUALLY does, using Datadog traces, and turn mismatches into fix tickets. Say "ar-api-dd-compare" or "trace audit". On-demand only (Datadog MCP is interactively authenticated)./ar-dd-api-performanceScan a window of Datadog traffic (default last day, production), sample traces for APIs over the latency/error thresholds, cross-reference this repo's code, and maintain per-API optimization report files under the workspace Performance_Findings directory, then commit them. On-demand only. Say "ar-dd-api-performance", "api performance scan", "which APIs are slow", or "update the performance reports"./ar-global-pr-reviewerReview any GitHub PR from anywhere on the machine, no project checkout needed. Clones the repo, sets up a review worktree, does a best-effort test run, reviews changed code for logical bugs and missing-test gaps against the project's rules, dedups against existing comments, and posts an inline review with fixes. Say "ar-global-pr-reviewer", "review pr globally", or "global review <PR-URL>"./ar-init-mcpsInitialize issue-tracker integration for Claude Code. For GitHub Issues (the default) this verifies the gh CLI is authenticated, no MCP needed. For Jira (Atlassian) or Linear it sets up the Model Context Protocol (MCP) server. Say "ar-init-mcps" or "setup mcps"./ar-init-skillsInitialize skills configuration for this project. Use when setting up for first time or when skill.config is missing. Say "ar-init-skills" or "setup skills".