harness-analyzer
Skill1 starsChanged 3 months agoMITView on GitHub
Use at the start of harness work in a new project, or when project grounding is missing or stale, to scan a codebase and GENERATE project-specific grounding skills, Mermaid diagrams, and a relevance index under .claude/skills/, then wire CLAUDE.md so future feature requests automatically follow the harness flow. Run this once before building features.
In this repository6 other files it gives its agents.
- harness-context-loaderSkill
- harness-learningsSkill
- harness-model-routerSkill
- harness-orchestratorSkill
- harness-verifierSkill
- verifySkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After a major refactor, dependency change, or convention shift (grounding is stale).
- Distinctive: line 31
Write one diagram per file.
- Distinctive: line 34
Read 3–6 representative source files.
- Very specific: line 46
If a frontend stack is present, look for tailwind.config.*, theme files, CSS custom properties, or a tokens file.
- Very specific: line 85
Keep each under ~150 lines.
- Very specific: line 89
Write .claude/skills/project-index.md — a compact map from area → grounding to pull.
- Very specific: line 105
Only list diagrams/skills you actually generated.
- Very specific: line 181
Never move or delete this content yourself — only report it.
- Distinctive: line 197
If a Learnings block still exceeds ~15-20 lines after the above, flag it the same way the CLAUDE.md health check does — a signal to promote …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Harness Analyzer
Scan the current project, then generate project-specific grounding skills under .claude/skills/ and wire CLAUDE.md so every later prompt is governed by the harness flow. You do this directly with your own tools (Glob, Grep, Read, Write) — there is no external program.
The output is real Claude Code skills, not data files. Because they live in .claude/skills/ with proper frontmatter, Claude auto-loads them in this project from then on.
When to run
- First time setting up the harness in a repo.
- After a major refactor, dependency change, or convention shift (grounding is stale).
Procedure
Gather evidence with Glob/Grep/Read — do not guess. Anything you can't determine from the repo, write as "unknown / not detected" rather than inventing it.
Diagram self-check: before writing any .mmd, confirm it has a valid header (graph, flowchart, or sequenceDiagram), every arrow connects two declared nodes, and there are no dangling edges. If a diagram can't be built from real evidence, skip it — never ship a faked or broken diagram. A minimal project may legitimately get only components.mmd.
1. Detect the stack
Glob for manifests at the root and one level down: package.json, pyproject.toml, requirements.txt, go.mod, Cargo.toml, pom.xml, *.csproj, Gemfile, composer.json. Read the primary manifest for language, framework, and scripts. Note the package manager from the lockfile.
2. Map the architecture
Glob source dirs (src/, app/, lib/, packages/*, cmd/, …). Identify module boundaries and how they depend on each other by sampling entry-point files. Capture this as standalone Mermaid diagram files under .claude/skills/project-architecture/diagrams/ (only nodes/edges you have evidence for):
components.mmd— module / dependency graph (graphorflowchart).data-flow.mmd— the canonical happy-path of a typical operation (e.g. route → controller → service → repository → DB), if the stack has a clear request/data flow.
Write one diagram per file. Do not embed these in the skill body — the body will reference them (step "Generate the grounding skills").
3. Extract code patterns
Read 3–6 representative source files. Record naming conventions (files, components/classes, functions, types), import style (absolute vs relative, path aliases), file/folder organization, and repeated idioms.
Also capture the patterns visually as standalone Mermaid files under .claude/skills/project-patterns-{lang}/diagrams/ (only what the code actually shows):
layers.mmd— allowed-dependency / layering rules (which layer may import which). Use agraphwith directed edges meaning "may depend on".idiom-<x>.mmd— asequenceDiagramof a genuinely recurring idiom (e.g.idiom-form-submit.mmd: submit → validate → API call → state update). Generate one per standout idiom; zero is acceptable if none recur clearly.
One diagram per file. The skill body references these rather than embedding them.
4. Detect test conventions
Find test files and identify the runner from the manifest. Read one test to capture the project's test shape and assertion style.
5. Detect design tokens (UI projects only)
If a frontend stack is present, look for tailwind.config.*, theme files, CSS custom properties, or a tokens file. Extract colors, spacing, typography, radii. Skip this skill entirely if no UI/tokens exist.
Generate the grounding skills
For each area you found evidence for, write a skill at .claude/skills/<name>/SKILL.md. Write creates the .claude/skills/ directory if the project doesn't have one yet, so this works in a fresh repo. Use the project- prefix so they're distinguishable from the core harness-* skills and from hand-written ones:
| Skill folder | Frontmatter description (the trigger) | Body |
project-patterns-{lang} | "Use when creating or editing {lang} files in this project, to follow its real naming, import, and file-structure conventions." | naming, imports, file org, idioms (step 3); link diagrams/layers.mmd and any diagrams/idiom-*.mmd |
project-architecture | "Use when adding or moving modules in this project, to respect its real architecture and where things belong." | module map + dependency notes; link diagrams/components.mmd and diagrams/data-flow.mmd (step 2) |
project-test-patterns | "Use when writing or running tests in this project, to match its runner and test style." | runner, layout, example assertion style (step 4) |
project-design-tokens | "Use when building or styling UI in this project, to use its real colors, spacing, and typography." | tokens (step 5) — only if detected |
Each generated file must be a valid skill, and must end with an empty, marker-delimited Learnings block:
---
name: project-patterns-react
description: <the trigger sentence from the table>
---
# <Title>
<concrete, project-specific guidance pulled from the REAL code — examples over prose>
## Learnings
<!-- harness:learnings:start -->
<!-- harness:learnings:end -->The Learnings block starts empty on first generation. harness-learnings (a separate skill) is the only thing that writes inside these markers during normal use — never write learnings here yourself during analysis. On re-analyze, preserve this block exactly as-is except for the pruning pass in step "Prune Learnings on re-analyze" below; regenerating the rest of the file must never wipe accumulated learnings.
Reference diagrams, don't embed them. A generated skill body must point at its diagram files by path relative to the skill folder, e.g.:
Data flow — read
diagrams/data-flow.mmdbefore adding or moving a service. Layering rules —diagrams/layers.mmd; do not introduce a dependency it forbids.
This keeps each skill light and lets the context-loader pull a diagram only when a task touches that area. Do not paste Mermaid blocks into the skill body.
Keep each under ~150 lines. Favor real snippets from the codebase over generic advice. These are grounding for an LLM that will auto-load them, so the description must accurately say when to use the skill.
Generate the relevance index
Write .claude/skills/project-index.md — a compact map from area → grounding to pull. This is what lets the loop load only what a task needs instead of re-guessing each time. Build rows only for areas you have evidence for; omit any you can't classify.
<!-- harness:index -->
| Area | Skills | Diagrams |
|-----------------|-------------------------------------------|---------------------------|
| api / services | project-patterns-<lang>, project-architecture | data-flow.mmd, layers.mmd |
| ui / components | project-patterns-<lang>, project-design-tokens | idiom-form-submit.mmd |
| data / db | project-architecture | data-flow.mmd |
| tests | project-test-patterns | — |
<!-- harness:index -->Rules:
- Areas come from the architecture map you built in step 2.
- Diagram cells are bare filenames; the owning skill folder is implied (architecture diagrams live under
project-architecture/diagrams/, pattern diagrams underproject-patterns-<lang>/diagrams/). - Only list diagrams/skills you actually generated. Use
—when none apply. - On re-analyze, regenerate this file from current evidence (overwrite).
Wire CLAUDE.md (governs the next prompt)
CLAUDE.md at the project root is what makes future prompts follow the harness flow. The harness section is delimited by stable markers so it can be updated idempotently on re-analyze:
<!-- harness:start -->
## Working in this repo (harness)
- **Stack:** <detected stack>
- **Grounding skills** (auto-loaded, under `.claude/skills/`; each links its diagrams under `diagrams/`):
- `project-patterns-<lang>` — naming, imports, file structure (+ `layers.mmd`, `idiom-*.mmd`)
- `project-architecture` — module map / where things belong (+ `components.mmd`, `data-flow.mmd`)
- `project-test-patterns` — test runner and style
- `project-design-tokens` — colors, spacing, typography (UI only)
- **Relevance map:** `.claude/skills/project-index.md` — area → which skills/diagrams to load for a task.
- **Loop state:** `harness-orchestrator` tracks progress in `.claude/harness/state.md` (resumable across sessions).
**For any non-trivial feature or change, use `harness-orchestrator`:**
it writes `.claude/harness/requirement.md` (your verbatim ask), decomposes into tasks, and
dispatches each to a fresh instance that grounds itself (harness-context-loader), builds
following the `project-*` conventions, and verifies itself (harness-verifier: lint/type/
format/test/patterns/diagrams/complexity/spec-conformance). Only claim a check passed
after seeing its output.
If the `project-*` skills are missing or stale, run `harness-analyzer` first.
**Project-specific conventions, gotchas, and corrections belong in the relevant
`project-*` skill's Learnings section — not here.** If you're about to add a bullet
describing a specific rule to this file, route it instead via `harness-learnings`.
**Quality gates (this repo's real commands):** lint: `<cmd>` · type-check: `<cmd>` · test: `<cmd>`
<!-- harness:config:start -->
## Harness configuration (edit freely — preserved across re-analyze)
**Model tier floor by task size** (complexity can still upgrade, never downgrades below this):
- S: (none — pure complexity routing, today's default)
- M: (none)
**Retry / escalation:**
- Same-tier retries before escalating: 1
- Max escalations: 2
- Escalation ceiling: opus (e.g. "sonnet" caps cost — task stays blocked rather than reaching opus)
**Area → grounding skill overrides** (adds to project-index.md, doesn't replace it):
- (none)
**Per-task log files** (`.claude/harness/logs/*.md` — secondary, human-readable expansions of `log.jsonl`; never read back by the loop):
- Write per-task/end-of-run log files: off (default; `log.jsonl` is written either way. Set to "on" to also get one `.md` file per task/end-of-run pass.)
<!-- harness:config:end -->
<!-- harness:end -->Apply it based on the current state (Read the file first if it exists):
- No
CLAUDE.md→ create it containing the block above (fill in real values; drop sections that don't apply). This is the only case where a wholeCLAUDE.mdis created from scratch — cases 2 and 3 below can also write the config sub-block's default values (case 2 always; case 3 only when no config markers existed yet). CLAUDE.mdexists, no<!-- harness:start -->marker → append the block to the end. Leave every existing line untouched.CLAUDE.mdexists with the markers (a prior run) → before replacing, extract whatever currently sits between<!-- harness:config:start -->and<!-- harness:config:end -->(if present) — this is user-edited, evidence-independent configuration, never regenerated. Replace the text between<!-- harness:start -->and<!-- harness:end -->with the freshly-generated block, then splice the extracted config content back in, replacing the freshly-generated (default) config sub-block with what the user actually had. If no config markers existed yet (a pre-config-featureCLAUDE.md), leave the freshly-generated defaults in place. Never duplicate any section, and never touch content outside<!-- harness:start -->/<!-- harness:end -->.
This makes the wiring create-if-absent, append-if-present-but-unwired, and update-in-place on re-analyze — always preserving the user's own content. (The repo's templates/claude.md.template has a fuller reference version, but write the block directly — don't depend on that file existing in the target project.)
CLAUDE.md health check
After wiring, measure the content outside the <!-- harness:start -->/<!-- harness:end --> markers: line count and rough word count. If it exceeds ~150–200 lines or ~1500 words, scan those lines for directive-shaped bullets (starting with or containing "always", "never", "don't", "remember", "note:") and report them to the user as candidates to route into the relevant project-* skill's Learnings block via harness-learnings, e.g.:
CLAUDE.md HEALTH CHECK
content outside harness markers: 640 lines (~2100 words) — over the ~150-200/~1500 budget
directive-shaped lines found:
L58: "Never use default exports, only named exports"
L61: "Remember: all API routes must validate input before touching the DB"
Suggestion: route these to project-patterns-ts / project-architecture via harness-learnings.Never move or delete this content yourself — only report it. The user (or harness-learnings, on request) decides what moves.
Works from any starting state
This runs whether or not the project already has a .claude/ folder or a CLAUDE.md:
- No
.claude/→Writecreates.claude/skills/for the generated skills. - No
CLAUDE.md→ create it. - Existing
CLAUDE.md→ merge the harness section in; never clobber the user's content.
Prune Learnings on re-analyze
On a re-analyze (not first-run generation), evaluate each generated skill's ## Learnings block against the fresh evidence gathered in this run:
- Confirmed and now broadly consistent across the freshly sampled files → promote it out of Learnings into the main generated body (it graduated from "learning" to "pattern"); remove it from Learnings.
- Contradicted by fresh evidence (the referenced file/module is gone, or current code demonstrably does the opposite) → drop it, and report the removal:
removed stale learning: "<text>" — contradicted by current code. - Unverifiable either way (rationale/history the code can't confirm or deny, e.g. "avoid library X, caused an incident") → keep by default; never silently delete tribal knowledge.
- Near-duplicates → dedupe into one canonical line.
- If a Learnings block still exceeds ~15-20 lines after the above, flag it the same way the
CLAUDE.mdhealth check does — a signal to promote the stable parts and let the rest go.
After running
Report which project-* skills you created and confirm CLAUDE.md is wired. Tell the user to start a new Claude Code session so the freshly generated project-* skills auto-load and the wired CLAUDE.md governs by itself. (In this session the flow still works without a reload, because harness-orchestrator and harness-context-loader read the generated files directly.)
See also
harness-context-loader— assembles the per-task brief from the generated skillsharness-orchestrator— drives the build loop the wired CLAUDE.md points toharness-verifier— checks output againstproject-patterns-*and the project's gatesharness-learnings— the only skill that writes inside a generated skill's Learnings markers during normal use
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

