Audit
Standalone Codex host branch
Claude frontmatter, TLDR, agent teams, dynamic workflows, codex-verifier, and
codex-run.ts do not apply in standalone Codex. Keep source inspection
read-only. Map with rg --files, rg -n, direct import/caller searches, focused
file reads, and the repo's own diagnostics; never claim TLDR ran. Use Context7
only when the user configured that MCP. Otherwise inspect pinned manifests and
lockfiles, consult official package documentation through native browsing when
available, and label currency or API claims unverified when neither source is
reachable. This package does not auto-run unpinned registry MCP packages.
For fan-out, create each new reader with spawn_agent, continue a live reader
with send_message, trigger another turn for an idle existing reader with
followup_task, wait with wait_agent, and stop its current turn with
interrupt_agent only when necessary. Only read-only reviewers
may overlap. Writers share the working tree unless the live host explicitly
offers isolation, so the main session writes the final report after readers
finish; any implementer and test-writer phases must be serialized with
non-overlapping ownership.
One skill, twelve modes. Ten audit modes (Codebase, Docs, Process, Performance, Tests, State, Threat-Model, Motion, SEO, Platform) read the surface in full (never sample), hunt with explicit categories, and ship a prioritized, executable report or plan set. Full runs every applicable mode and merges the reports (see Mode: Full). Debt is a mechanical grep that collects SHORTCUT: markers into a ledger and makes no judgement (see Mode: Debt).
Codebase mode's structure lens should push to be ambitious: do not merely identify local cleanup opportunities, actively search for "code judo" moves. Every adversarial mode holds no loyalty to the current design — hunt defects, drift, dead ends, and abuse paths rather than confirm things work.
Mode Router
A request for everything, or one that names two or more verticals ("audit performance, code quality, and security"), routes to Full mode. The bare phrase "audit the codebase" routes straight to Codebase mode, whose single pass carries both lenses.
Trigger phrases by mode:
| Mode | Phrases |
|---|---|
| Full | "full audit", "audit everything", "audit all of it", "complete audit", "every audit mode", or two or more verticals named in one request |
| Codebase | "audit the codebase", "nuclear review", "thermonuclear review", "code judo", "deep code quality audit", "harsh maintainability review", "whole codebase review", "should this exist", "adversarial audit", "fable audit", "expectation gaps", "correctness audit" |
| Docs | "audit the docs", "docs audit", "doc drift" |
| Process | "process audit", "audit the workflows", "walk the journeys", "end-to-end audit" |
| Performance | "perf audit", "performance audit", "why is the app slow", "bundle audit", "build is slow", "speed audit" |
| Tests | "audit the tests", "test audit", "low-value tests", "prune the test suite", "junk tests" |
| State | "find all the implicit state machines", "implicit state", "impossible states", "state audit", "boolean soup" |
| Threat-Model | "threat model", "STRIDE", "attack surface", "abuse paths" |
| Motion | "motion audit", "audit the animations", "improve the animations" |
| SEO | "seo audit", "aeo", "ai engine optimization", "answer engine", "discoverability audit", "rank better", "llms.txt" |
| Platform | "platform audit", "guideline audit", "does this follow the HIG", "Fluent audit", "Material audit", "native audit", "liquid glass audit" |
| Debt | "debt ledger", "shortcut ledger", "what did we defer", "what corners did we cut" |
Debt mode is a mechanical grep — run it standalone or as a cheap first pass before Codebase mode.
When to use vs other review skills
/dr-review— per-diff Darkroom checklist (TypeScript / React / a11y / perf / security, plus motion when the diff touches it). Every change./audit(this skill) — periodic whole-repo audit; Full mode merges every mode that applies into one ranked report./poke-holes— adversarial check of a single change/claim, not a repo sweep.
Each mode answers one question:
| Mode | Asks | Fits when |
|---|---|---|
| Codebase | Should this code exist, and does it do what it promises? | Major version cuts, after velocity sprints, before a load-bearing migration |
| Docs, Process | Do the docs tell the truth, and do the journeys walk end-to-end? | Before releases, after feature bursts |
| Performance | Where is time actually going, measured? | Before a launch, after a dependency-heavy sprint, "the site feels slow" with no number |
| Tests | Which tests guard nothing? | Slow or brittle suite, after a burst of agent-written tests |
| State | Where is one lifecycle spread across flags, and which impossible states can it reach? | Stuck spinners or stale errors, after a burst of feature work on stateful UI, before a refactor |
| Threat-Model | What can go wrong, and who would exploit it? | Before a security-sensitive launch or a new internet-facing surface |
| Motion | Where does the animation work have the highest leverage? | After a UI-heavy sprint, before a client showcase |
| SEO | Will this site be found, ranked, and cited? | Before a site launch, first pass on any client marketing/content site |
| Platform | Does this native app use the system's chrome and keep character to its budget? | Before a release of an iOS, macOS, Windows, or Android app; after a UI-heavy sprint; when an app looks out of place next to the system apps |
| Debt | What did we defer on purpose? | Cheap first pass before Codebase |
A typical sequence: /audit codebase produces findings → engineers cherry-pick the highest-leverage ones → the right executor by finding type: dead code and duplication go to the deslopper agent (auto-removes what's provably dead, stages consolidations for approval), structural rework to the implementer agent, client-runtime perf findings to /fix.
Claude Code only (v2.1.154+): standalone Codex skips this tip and the
Workflow command below. In Claude, run
/effort ultracodebefore invoking
this skill. Whole-repo audits are the canonical shape that benefits from dynamic workflows — phase state lives in the workflow script rather than Claude's context window, individual areas can be reviewed in parallel (up to 16 concurrent), and the run can resume from cached agent results within the session. Dynamic workflows default to a medium size guideline, aiming for fewer than 10 agents (Pro plans default to small) — it's advisory, not enforced, but a repo with more modules than that is worth raising
workflowSizeGuidelinefor explicitly before the fan-out phase rather than silently exceeding the default.
A ready-made example for codebase mode's structure lens ships at
references/nuclear-review.workflow.js(installed to~/.claude/skills/audit/references/). It is opt-in, not a dependency — the mode works with no Workflow tool. Run it withWorkflow({ scriptPath: "~/.claude/skills/audit/references/nuclear-review.workflow.js" }), or copy it into.claude/workflows/. It maps the repo, fans out one structural reviewer per module, audits dependencies, and synthesizes one report. Treat it as a template — adapt its module list, schemas, and phases to the repo at hand rather than running it verbatim.
Shared Contract (Codebase, Docs, Process, Tests, State, Threat-Model, SEO, Platform, Performance, and Full modes)
Role. No loyalty to the current design/structure/flows. Act simultaneously as a senior staff engineer, a skeptical first-time consumer, and an adversarial reviewer. Understand deeply enough to challenge, not merely validate.
Method. Per area, state how it SHOULD behave, then read (or run) to confirm or refute; every expectation-vs-reality gap is a finding. Findings follow the finding contract in references/audit-contract.md §3 (stable IDs, CONFIRMED/PLAUSIBLE, disprove first, concrete scenario, considered & rejected). CONFIRMED requires one file:line; a finding located by a bare file, a glob, or an absence ("no tests") is PLAUSIBLE wherever it is reported, chat included. Performance mode tightens it: PLAUSIBLE does not exist there (see its evidence rule). Where something is sound, say so once and move on; spend effort where it isn't.
Cross-model + intent passes. In Claude, run the shared procedures in references/audit-contract.md (§1 Codex cross-model pass via codex-verifier on the finding list, §2 team-knowledge reconciliation). Both are gated and fail open. Standalone Codex never uses the bridge; it may use a fresh native read-only reviewer under the lifecycle above. The one-line invariants: reconcile AFTER findings exist, and a documented decision reclassifies severity, never deletes a finding.
Output. First grade the findings: write them as JSON lines to a scratch file, one per line with id, status, location, issue, scenario and direction, then run bun "$HOME/.claude/src/scripts/grade-findings.ts" <file>. It relabels any CONFIRMED finding with no file:line to PLAUSIBLE and gives the reason; the report uses its labels. To win CONFIRMED back, add the file:line and rerun; never relabel by hand. Performance's measured findings pass through unchanged. If the script is not installed, apply the same rule yourself. Then write the full report to docs/audits/[mode]-audit-YYYY-MM-DD.md (create the dir; leave uncommitted — the maintainer owns git). Structure top-heavy:
- Summary table: ID | severity | area | one-line issue | file:line | CONFIRMED/PLAUSIBLE.
- Map (system map / doc map / process state machine — per mode below).
- Findings by hunt category, severity order. Each: stable ID (H1/M1/L1 by severity, or the mode prefix from Mode: Full), location, one-line issue, concrete scenario, status, recommended direction.
- Design tensions: the 3-5 deepest structural issues ("the approach, not a line"), each with the alternative you'd weigh.
- Open questions: what the artifact alone can't resolve — maintainer answers required.
- Considered & rejected: the ledger from the finding contract. Check it before hunting.
Chat reply = exec summary only: counts by severity + top 3-5 findings + report path.
Optional issue filing. When the maintainer wants findings executable by agents, file each as a GitHub issue (one per finding, severity labels, CONFIRMED/PLAUSIBLE in the body, an epic for the design tensions, question-labeled issues for the open questions), then run parallel fix agents whose PRs cite the IDs.
Mode: Codebase
One merged audit, two lenses on one whole-repo read: structure (should this code exist?) and behavior (does it do what it promises?). Rides the Shared Contract above.
Scope
The entire codebase, not the current diff:
- All source modules — application code, libraries, scripts, hooks, configs
- The dependency manifest (
package.json+ lockfile) — every direct dependency - Folder structure, module boundaries, top-level architectural surfaces (routes, providers, exported APIs)
- Entry points and real (not documented) execution paths; module contracts, explicit and implied
- Data models, invariants, and where they're enforced vs assumed
- External surfaces (APIs, CLIs, config, env vars, file formats, network calls) and the onboarding path a newcomer would actually follow
Skip vendored code, generated files, and node_modules.
Workflow
Phase 0 — Map the codebase
Establish ground truth before judging anything.
# Top-level structure
fd -t d -d 2 --hidden -E node_modules -E .git -E dist -E build
# File-size distribution (largest first) — find the 1k-line crossings
fd -t f -E node_modules -E .git -E dist -E build \
-e ts -e tsx -e js -e jsx -e py -e go -e rs -x wc -l {} \; | sort -rn | head -50
# Direct deps with versions
jq '.dependencies + .devDependencies' package.json
In Claude, if the project uses tldr, prefer it for the call graph + dead-code pass. Standalone Codex skips these commands and uses the native searches in its host branch:
tldr arch .
tldr dead . --entry-points "main,test_"
If dead returns unsupported-by-native-engine (the default engine does not implement it), say
the dead-code pass did not run — do not record "no dead code" as a finding. An empty result from
dead or impact is not evidence; confirm with Grep before acting on it.
If the opt-in tldr-code CLI is installed (~/.claude/code-intel/tldr-code/0.4.0/tldr — see
docs/tldr-cheatsheet.md), prefer it for the dead-code pass instead:
~/.claude/code-intel/tldr-code/0.4.0/tldr dead . --lang typescript
It exits 0 even on errors — never trust its exit code. Check that stdout parses as JSON and
that functions_analyzed > 0; non-JSON stdout or functions_analyzed: 0 means the scan did not
run and must be reported as "scan unavailable", never as "no dead code". **dead_functions from
tldr-code is ADVISORY ONLY — confirm every candidate with Grep before recording it as a
finding.**
When the project depends on deslop-cli (check package.json — it's the same advisory probe
/proof-of-work runs), add it as a second dead-code signal: npx deslop. Same rule as
tldr-code: advisory only, Grep-confirm every candidate. Two scanners agreeing upgrades conviction;
either one alone still needs confirmation.
Phase 1 — Dependency audit (Context7 when configured)
For each direct dependency in package.json, use the context7 MCP server to
verify when it is configured. Standalone Codex otherwise uses the native/manual
fallback in its host branch and does not execute an unpinned registry MCP:
- Currency — is the installed version current, or stale? Note major-version gaps.
- Usage quality — is the codebase using the dependency in the way the maintainers currently recommend? Old APIs, deprecated patterns, missing newer affordances?
- Necessity — could it be replaced by a platform built-in, an existing canonical helper, or a smaller dependency?
- Overlap — does it duplicate the role of another dependency? (Two date libraries, two state managers, two HTTP clients.)
- Footprint cost — for any dependency contributing >50KB to the client bundle, is the usage scope worth the cost? Could it be code-split, lazy-loaded, or replaced?
Use context7 in two steps per dependency:
mcp__context7__resolve-library-id { libraryName: "<package>", query: "<what we use it for>" }
mcp__context7__query-docs { libraryId: "<resolved id>", query: "current recommended usage vs <pattern we use>" }
Cap context7 calls at 3 per dependency (per the server's own guidance). Batch the audit: pick the top 10–20 by either bundle weight or surface-area coverage rather than auditing every transitive dep.
Output for each flagged dep: current version → recommended version, deprecated APIs in use, suggested fix.
Phase 2 — The hunt, both lenses
Walk the largest files first, then the modules with the most outbound dependencies, then the entry points. Apply both lists to every meaningful surface in one pass.
Structure lens — non-negotiable standards:
- Be ambitious about structural simplification. Do not stop at "this could be a bit cleaner." Look for reframings that make whole branches, helpers, modes, conditionals, or layers disappear entirely. Assume there is often a "code judo" move available — a re-organization that uses the existing architecture more effectively and makes the surface dramatically simpler. Prefer the solution that feels inevitable in hindsight; if you see a path to delete complexity rather than rearrange it, push hard for that path.
- Flag every file over 1k lines. A strong code-quality smell by default; prefer extracting helpers, subcomponents, or modules. Waive only for a compelling structural reason with the file still clearly organized.
- Do not tolerate spaghetti. Ad-hoc conditionals, scattered special cases, one-off branches in otherwise cohesive flows — a design problem, not a stylistic nit. Push logic into a dedicated abstraction, helper, state machine, or module instead of tangling existing paths.
- Bias toward cleaning the design, not preserving working code. If behavior can stay the same while structure gets meaningfully cleaner, push for the cleaner version. Prefer simplifications that remove moving pieces over refactors that spread the same complexity around.
- Prefer direct, boring code over hacky or magical code. Flag thin abstractions, identity wrappers, pass-through helpers, and generic mechanisms that hide simple data-shape assumptions.
- Push hard on type and boundary cleanliness. Question unnecessary optionality,
unknown,any, cast-heavy code, and silent fallbacks papering over unclear invariants; prefer explicit typed models and shared contracts. - Keep logic in the canonical layer and reuse existing helpers. Call out feature logic leaking into shared paths, details leaking through APIs, and bespoke one-offs where a canonical utility exists.
- Treat unnecessary sequential orchestration and non-atomic updates as design smells. Serialized-for-no-reason work and updates that can leave state half-applied — flag both without over-indexing on micro-optimizations.
- Dependencies must be current and well-used. Flag deprecated majors, superseded usage patterns, role-duplicating deps, disproportionate footprints, and deps a platform primitive could replace.
- Implicit state machines. Run the sweep and per-machine record from Mode: State on every surface you read; a reachable impossible state is a correctness finding, the rest go under structure with the union that replaces them. In Full mode, skip this item when State mode is selected.
Behavior lens — hunt categories:
- Correctness — logic errors, races, off-by-one, unhandled edges, silently swallowed failures, wrong error propagation.
- Alternative/unintended paths — second call? concurrent calls? empty/null/huge input? partial failure mid-op? retries? the "holding it wrong" path?
- Incoherences — names that lie about behavior, two modules solving one problem differently, config honored here and ignored there, duplicated sources of truth that can drift, dead code, contradictory defaults.
- Affordance mismatches — "I expected to do X this way but can't, or it does something else." Where does the API shape promise a capability the code doesn't deliver? Where is the easy path also the dangerous one?
- Missing functionality — what a reasonable user expects (validation, idempotency, cleanup, observability, cancellation, timeouts) but is absent.
- Boundary and safety — leaky abstractions, invariants in the wrong layer, unvalidated input crossing a boundary; injection, path traversal, unbounded growth, resource leaks, missing authz, exposed secrets — only where real.
- Documentation — README/docstrings/comments that are wrong, stale, or contradict the code; undocumented public behavior/params/errors/side effects; examples that wouldn't run.
- Developer experience — can a newcomer build, run, test, and debug from the docs alone? Confusing errors, silent misconfig, setup footguns.
Phase 2b — Claude-only cross-model structural pass (when the Codex bridge is available)
Standalone Codex skips this phase. In Claude, run the shared cross-model
procedure (references/audit-contract.md §1) with this mode's audit prompt:
bun "$HOME/.claude/src/scripts/codex-run.ts" ask "Audit this repository for structural problems: files over ~1000 lines, thin wrappers that don't earn their keep, logic leaked across boundaries, and duplicated abstractions. Walk the largest files and the modules with the most outbound dependencies first. Report the highest-leverage 'code judo' restructurings — ones that delete whole branches rather than rearrange them — ordered by conviction."
Fold Codex's findings into Phase 3 per the contract: convergence = high-conviction, divergence noted not dropped, gated and fails open.
Phase 2c — team-knowledge reconciliation (when the corpus is reachable)
Phases 2 and 2b judge structure intent-blind, so deliberate design reads as debt. Run the shared reconciliation procedure — references/audit-contract.md §2: generate findings blind FIRST, then cross-reference the corpus; a documented decision reclassifies severity, never suppresses a finding; gated, fails open.
SHORTCUT: markers (AGENTS.md Laziness Ladder) get the same treatment as team-knowledge notes: a marked deferral is a documented decision, not ordinary debt — cite the marker instead of re-litigating it, and escalate only if its stated upgrade trigger has actually fired. Debt mode owns the full ledger; this mode just respects it.
Phase 3 — Synthesis
Produce the Shared Contract report, with two mode-specific additions: open with a one-line verdict — CLEAN / NEEDS RESTRUCTURING / NEEDS MAJOR REWORK — and lead the findings with a Code-Judo Opportunities section (dramatic simplifications: what to delete, not just polish). The map section includes an "expectation gaps" list: short "expected X, found Y" entries for affordance/docs/DX. Prioritize ruthlessly — a smaller number of high-conviction findings beats a long list; do not flood the report with nits when larger structural issues exist.
Severity ordering within the report: structural regressions and missed code-judo moves first, then correctness/incoherence findings, then dependency staleness with material impact, then boundary/type-contract problems, then file-size and legibility concerns.
Phase 4 — Documentation updates (after fixes land)
When findings turn into code changes, the same pass updates the docs that describe them. A report-only run skips this phase but flags it for whoever applies the fixes.
| Type of change | What to update |
|---|---|
| New skill / agent / hook / profile | docs/skills.md (skills) or the matching docs/*-reference.md, CHANGELOG.md, and every stated skill/agent count (CLAUDE-FULL.md, the baseline in src/lib/lint-skills.ts) |
| Structural refactor (dedup, extract module, rename across files) | CHANGELOG.md: what moved and why |
| Dependency upgrade or deprecated-API swap | CHANGELOG.md: the package, old vs new pattern, caller-visible behavior |
| New canonical helper that supersedes inline duplicates | CHANGELOG.md, and rules/*.md if it is now the project-wide pattern |
| Type/boundary cleanup at a JSON or external-input boundary | CHANGELOG.md, and docs/security-reference.md if validation changed |
| API surface change (exported signature, public schema) | CHANGELOG.md, any docs/*-reference.md naming the symbol; bun run schemas:emit if the zod surface moved |
- Follow the repo's CHANGELOG format (this repo dates entries per version), one short paragraph per entry naming the files changed and why.
- Counts must match reality. Update every reference when a skill, agent, or rule is added or removed.
- Regenerate derived docs. After changing a zod schema in
src/schemas/, runbun run schemas:emitand keep theschemas/*.schema.jsondiff with the source change. - Update
docs/skills.mdand the routing prose inMANUAL.mdwhen a skill's invocation phrasing changes or a skill is added.
Verify the doc pass:
bun run lint:skills # frontmatter sanity
bun run schemas:check # derived schemas in sync with sources
Remedies and approval bar
Preferred remedies are the structure-lens standards turned into actions: delete a layer of indirection rather than polish it, reframe state so conditionals disappear, split oversized files, replace condition chains with a typed model, move logic to the layer that owns the concept, reuse the canonical helper, and upgrade or replace dependencies. Do not accept "maybe rename this" feedback when the real issue is structural.
Review tone. Direct, serious, demanding about quality. Not rude, but do not soften major issues into mild suggestions. If the codebase is messier than its features warrant, say so clearly. If a path to a dramatic simplification was missed, say that too.
A codebase passes when every structure-lens standard holds (no file over 1000 lines without explicit justification, no code-judo move left on the table, dependencies within one major of current) and no CONFIRMED correctness, incoherence, or affordance finding is left unaddressed or unacknowledged. Otherwise the report gives explicit, actionable feedback and pushes for the cleaner shape.