Code audit

From hawkyre/hawk-skills · View interactive version

Code audit is an AI agent skill from the GitHub repository hawkyre/hawk-skills. Review code or a diff with independent specialists for logic, security, simplification, research, and architecture. Use for code audits, quality checks, and reviews of your own changes. Report mode returns findings; cleanup mode applies verified local fixes. Use code-audit-hardcore for broader clean

How to use this skill

Skill file

Code Audit

The audit is a fan-out of independent specialists, each running as a fresh audit-* subagent in parallel. None of them knows what feature the code is for, what plan generated it, or what the user is trying to ship — the orchestrator (this skill) merges their findings. That blindness is the point: a reviewer who knows the goal rationalizes the code toward the goal.

Specialist briefs, anti-bias contracts, and output formats live in the agent files (audit-triage, audit-logic, audit-security, audit-simplification, audit-research, audit-architecture). This skill orchestrates; it does not redefine those briefs.

Posture — non-negotiable

The orchestrator and specialists evaluate quality, not style. Existing patterns are observations to be evaluated, not defaults to be matched. The repo is a starting point, not a baseline.

Refuse the lazy patch. The worst failure mode of an AI auditor is a fix that silences a symptom without addressing the cause. Concretely, the orchestrator downgrades to NOTE (does not apply in cleanup mode) any FIX that:

A lazy FIX is worse than no FIX, because it makes the underlying issue invisible. When in doubt: surface, don't patch.

The goal is to leave the touched code better than the average of its surroundings, not to match the average.

Think in systems. A fix for one instance is half a fix. When a finding is one member of a class (the same missing invariant, the same duplicated logic, the same gap at other call sites), the FIX targets the source that produces the class, not only the line in the diff. If that fix is cross-cutting, route it (below).

"It works" is not a defense. Working code that has a better version is a finding. No finding ends as "no action". Each finding ends in one of these states:

An observation with no better alternative is not a finding. Drop it.

Modes

This skill is the quick-wins-and-surface-the-big-stuff layer. Local FIXes get applied in cleanup mode; cross-cutting issues become high-priority NOTEs routed to code-audit-hardcore or a plan skill.

Cleanup mode is not licensed to do everything report mode finds. It applies the small wins (local fixes) and surfaces the big stuff (cross-cutting changes, plan-overrides) for explicit human or hardcore-audit decision.

Args

Tier → specialists

| Tier | Specialists |

| ---------- | ------------------------------------------------------- |

| light | logic, simplification |

| standard | logic, security, simplification, architecture |

| deep | logic, security, simplification, research, architecture |

Triage may pick any subset across these tiers. When tier is forced, the static mapping above is used.

Process

  1. Resolve scope. From the args, build the file list and capture the diff. Group by layer (frontend, backend, shared). Note immediate imports/exports — neighbour files are in scope for cross-cutting checks.

Diff capture:

```bash

git diff <range> > /tmp/hawk-code-audit-diff.patch 2>&1

git ls-files --others --exclude-standard > /tmp/hawk-code-audit-untracked.log

```

The untracked-files capture matters when scope is the working tree — staged-but-uncommitted new files belong in the audit. Get the file list with git diff --name-only <range> (small, inline). Specialist user-prompts receive per-file rg -n slices of the captures, never the raw concatenated diff.

  1. Triage (when tier=auto). Spawn the audit-triage subagent:

```

reviewer: audit-triage; brief: <USER PROMPT>

```

Where <USER PROMPT> contains:

Parse the structured reply:

```

tier: <light|standard|deep>

specialists: <subset>

reason: <…>

```

The triage decision is not surfaced to the user — log it internally and proceed. (If the user explicitly asks "why these specialists?", show the reason.)

If the reply doesn't parse (missing tier: line, unknown tier value, empty specialists list, no response): fall back to tier=standard (logic, security, simplification, architecture) and continue. Bias is up — never silently skip the audit because triage misbehaved.

When tier is forced, skip this step and use the static mapping.

  1. Load shared context (orchestrator only — pasted into each specialist's user prompt). Load only what's relevant to the diff scope, matched by file extension, layer, or domain. Skip standards and common-mistakes files that don't apply to any file in scope.

Progressive loading is deliberate: less standing context per specialist means stronger attention to each loaded item. Specialists do not fetch additional context — what's in their prompt is what they have.

  1. Spawn the specialists in parallel. Use the active system's delegation tool for each role. For each role in the triage subset:

```

reviewer: audit-logic; brief: <USER PROMPT>

reviewer: audit-security; brief: <USER PROMPT>

reviewer: audit-simplification; brief: <USER PROMPT>

reviewer: audit-research; brief: <USER PROMPT>

reviewer: audit-architecture; brief: <USER PROMPT>

```

Skip any role not in the triage subset.

Do not delegate to code-audit. It is a skill, not an agent. Run the audit specialists directly from the main session.

  1. Merge the outputs.

1. It names a specific path:line and a named issue.

2. You can write the change as a FIX with a runnable Verify clause.

3. The change passes the lazy-patch check.

A vague NOTE ("this abstraction could be better"): make it concrete yourself. Name the lines, the change, and the benefit. If you cannot name a benefit, drop it.

Empirical: findings flagged by multiple specialists are materially stronger signals than solo findings. Don't discard that information at the merge step.

  1. Verify before claiming a FIX — the orchestrator's last gate. Run each check that applies to the FIX. Anything that fails verification becomes a NOTE, not a FIX.

Classify scope as the last verification step:

  1. Act on the merged output.

If any state is hit — stop and surface; do not apply through it.

Otherwise: apply each Scope: local FIX. After applying all local FIXes, run each FIX's Verify: clause individually — the verify clause must pass to confirm the fix resolved the finding rather than masking it. If a verify clause fails, revert that specific FIX and surface to the user. Once all applied FIXes have passing verify clauses, run the project check command with the layered retry ladder:

Scope: cross-cutting and Scope: plan-override FIXes are not applied in cleanup mode — they remain as surfaced findings in the report. This is the boundary between code-audit and hardcore-audit.

Specialist user-prompt template

The agent's system prompt already contains the role, anti-bias contract, verification rule, and output schema. The orchestrator sends only the per-call context:

## Files / diff in scope

{{per-file `rg -n` slices of the diff capture, or full file content
when the file is outside the diff}}

## Standards (pasted inline, do not fetch)

{{full content of every relevant `.agents/standards/` file}}

## Common mistakes (pasted inline, do not fetch)

{{full content of every relevant `.agents/common-mistakes/` file}}

## Context

{{optional — e.g. "this diff covers N increments, +A/-B lines, M files"
for callers like implement-plan-audited; omit for plain code-audit}}

## Verify clause requirement

For every FIX you propose, include a `Verify:` clause — a concrete,
runnable check (a command, a test name, an assertion, a query) that
confirms the FIX resolves the finding rather than masking it. FIXes
without runnable Verify clauses are downgraded to NOTEs by the
orchestrator.

That's the entire user prompt. No role re-statement, no anti-bias restatement, no output-format restatement — those are in the agent.

Output template (orchestrator → user)

# Code Audit Report: {{scope}}

## FIX

1. [path:line] — issue
   Why: …
   Fix: …
   Verify: <runnable check>
   Strength: <N>/<S> (specialists that independently flagged this)
   Scope: local | cross-cutting | plan-override
   Source: logic / security / simplification / research / architecture
   (multiple if specialists agreed)

## NOTE

1. [path:line] — improvement
   Benefit: …
   Blocker: …
   Next: code-audit-hardcore | plan-small | plan-large

## QUESTION

1. … (surfaces blocking ambiguities and plan-overrides — do not guess)

In report mode, stop here. In cleanup mode, apply each Scope: local FIX (after running its Verify clause individually), then run the check command with the layered ladder. Scope: cross-cutting and Scope: plan-override FIXes remain surfaced; they're not auto-applied.

Rules

Most rules are stated once in Posture or Process. This section is the index — follow the pointer for the canonical wording. Net-new rules (not stated elsewhere) are at the bottom.

| Rule | Canonical location |

| ---- | ------------------ |

| Repo is a starting point, not a baseline | Posture |

| Think in systems: fix the source of the class, not the instance | Posture |

| "It works" is not a defense; each finding is applied, routed, or asked | Posture |

| Concrete NOTEs are promoted to FIXes | Process Step 5 |

| Lazy patches downgraded to NOTE | Posture (5-item enumeration) |

| Plan is not sacred — surface as QUESTION or Scope: plan-override | Posture + Process Step 6 |

| Every FIX must include a runnable Verify: clause | Process Step 6 |

| Strength N/S tracked through merge | Process Step 5 |

| Cleanup applies Scope: local FIXes only | Process Step 6 + Step 7 |

| Behavior-changing FIXes always surfaced (even when applied) | Process Step 6 |

| Stop-out check before applying any FIX | Process Step 7 |

| Layered retry ladder (not flat 3-attempt) | Process Step 7 |

| Specialists run in parallel as fresh subagents | Process Step 4 |

| Triage classifies; it never reviews code | Process Step 2 |

| Each specialist prompt is self-contained — no goal context | Specialist user-prompt template |

| Verification gates are the orchestrator's job, not the specialists' | Process Step 6 |

| Cleanup must not skip the project check command | Process Step 7 |

Net-new (not stated elsewhere):

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.