| name | fixing-harness |
| description | Audits a project's agentic harness (CLAUDE.md, AGENTS.md, .claude/rules, .claude/settings.json) and refactors it into a layered, path-scoped configuration that loads only what is relevant. Rewrites CLAUDE.md and AGENTS.md as a thin critical-rules layer, segments domain rules with `paths:` frontmatter, and adds deny-first permission guardrails. Use for: fixing the harness, auditing claude.md, refactoring agentic configuration, improving agent rules, segmenting rules by path, reviewing settings.json, harness review, or when claude.md is too long. |
| disable-model-invocation | true |
Fixing the Agentic Harness
Target: $ARGUMENTS (optional path; defaults to project root)
Objective
Refactor the project's harness so the model sees only the rules it needs for the files it touches. CLAUDE.md (and AGENTS.md when present) become a thin always-on critical-rules layer. Domain rules move to .claude/rules/*.md with paths: frontmatter. Permissions and MCP scope live in .claude/settings.json with explicit deny guardrails.
The goal is inference weight, not exhaustive documentation: 10 sharp directives the model references in reasoning beat 200 lines it half-skims.
Workflow
Progress checklist:
Harness Audit & Fix:
- [ ] Step 1: Inventory current harness
- [ ] Step 2: Audit against best practices
- [ ] Step 3: Produce gap analysis
- [ ] Step 4: Propose refactor plan (confirm with user)
- [ ] Step 5: Apply changes (CLAUDE.md, AGENTS.md, rules, settings)
- [ ] Step 6: Verify with /memory
Step 1: Inventory Current Harness
Read in parallel where present:
CLAUDE.md, ./.claude/CLAUDE.md, CLAUDE.local.md
AGENTS.md (Codex / Cursor / other agents)
.claude/settings.json, .claude/settings.local.json
.claude/rules/**/*.md โ note paths: frontmatter on each
.claude/agents/*.md, .claude/skills/*/SKILL.md
.mcp.json, .gitignore
Capture the actual directory layout (top-level apps, packages, services). Use tokei if available, otherwise find or ls. The layout drives the path scopes proposed in Step 4 โ generic globs that don't match real directories are dead weight.
Step 2: Audit Against Best Practices
Load references/audit-checklist.md and score each dimension:
- CLAUDE.md size and shape โ under 30 lines, directives not prose, no domain dump
- AGENTS.md alignment โ mirrors CLAUDE.md when present, no drift
- Rules segmentation โ path-scoped, one domain per file, no overlap
- Permissions hygiene โ explicit
deny for destructive ops and secrets, scoped allow patterns, MCP tools narrowed
- Local overrides โ
.claude/settings.local.json and CLAUDE.local.md in .gitignore
- Memory ergonomics โ no monolithic root CLAUDE.md drowning monorepo subtrees
Step 3: Produce Gap Analysis
Output a markdown table:
| Dimension | Status | Severity | Evidence | Suggested fix |
|---|
Status values: Respected, Violated, Partially respected, N/A
Severity values:
- HIGH โ no
deny rules, secrets readable, CLAUDE.md > 100 lines, no rules layer in a multi-domain project
- MEDIUM โ CLAUDE.md 30โ100 lines, rules without path scoping, broad
Bash(*) allow, AGENTS.md drift
- LOW โ stylistic issues, missing nice-to-haves (CLAUDE.local.md, sandbox config)
End with a Top fixes list ordered by impact.
Step 4: Propose Refactor Plan
Present the proposed file layout before writing anything:
CLAUDE.md (X lines today -> Y lines after)
AGENTS.md (if other agents are in use)
.claude/rules/
โโโ <domain-1>.md paths: <glob>
โโโ <domain-2>.md paths: <glob>
โโโ ...
.claude/settings.json (deny rules + scoped allow)
.gitignore (add .claude/*.local.*, CLAUDE.local.md)
Confirm with the user before applying. Path scopes must match real directories surfaced in Step 1.
Step 5: Apply Changes
For each file:
-
Rewrite CLAUDE.md using references/claude-md-template.md. Keep only project-wide directives. Move domain-specific content to rules files. Target under 30 lines.
-
Sync AGENTS.md using references/agents-md-template.md when other agents are in use. Mirror the critical rules; reference domain rules by path rather than duplicating them.
-
Create path-scoped rules in .claude/rules/<domain>.md using patterns from references/path-scoping-patterns.md. Each rule file has paths: frontmatter listing globs and contains only directives that apply inside those paths.
-
Harden .claude/settings.json using references/settings-recipes.md. Add deny for destructive ops and secret files. Tighten allow patterns. Scope MCP tools.
-
Update .gitignore to include .claude/*.local.* and CLAUDE.local.md if missing.
Preserve concrete content the user relies on โ package manager command, lint command, framework gates. Surface anything you plan to delete before deleting it.
Step 6: Verify
Validate the rewrite, then fix anything that fails and re-verify:
- Line budget โ
wc -l CLAUDE.md should be under 30. If not, return to Step 5 and move more content into rules.
- Path scope sanity โ for each new rules file, confirm at least one file in the repo matches its
paths: glob (git ls-files | grep -E <pattern>). If zero matches, the glob is wrong.
- Deny rules in place โ
grep -c '"deny"' .claude/settings.json should return โฅ 1. The deny list must include destructive ops and secret reads.
.gitignore covers locals โ grep -E '\.claude/\*\.local|CLAUDE\.local\.md' .gitignore should return matches.
- Memory check โ ask the user to run
/memory and confirm CLAUDE.md plus only the path-scoped rules relevant to the current cwd are listed as loaded.
If any check fails, fix it and re-run from check 1. Do not declare the refactor complete with a failing check.
Constraints
- Do not delete existing rules the user has not approved removing โ move to rules files instead
- Do not invent project conventions; only restructure what is already documented
- Preserve concrete commands (lint, package manager, framework codegen) from the original CLAUDE.md
- When a rule is borderline domain-specific, prefer the rules layer โ promotion to CLAUDE.md should be earned, not assumed
- If the project has no
.claude/ directory yet, create it; do not assume team policies the user has not stated
- Never weaken a deny rule without explicit user approval