Overview
Run a structured, evidence-based audit of a codebase. Two phases always run in order: first detect context, then apply the requested domains.
Usage: /audit [domain?]
- No domain → run all domains (default)
- Available domains:
security | contracts | patterns | observability | ops | all
Safety
Do not run destructive operations (DB resets, production deploys, mass deletes, git push --force, etc.) unless the user explicitly asks in the same session. Use read-only inspection: read files, Glob, Grep, and read-only git commands (git log -1, git grep) — no history rewrites.
Phase 1 — Context Detection
Always runs first. Read the project to understand what you're working with. Identify and state explicitly:
- Language(s): Go, Python, TypeScript, Rust, etc.
- Runtime / framework: gRPC, FastAPI, Next.js, Express, Django, etc.
- Auth mechanism: JWT, sessions, OAuth, API keys, none
- Data layer: SQL (which DB), NoSQL, ORM, raw queries, none
- Infra: Docker, Kubernetes, serverless, bare metal
- API surface: REST, gRPC, GraphQL, tRPC, WebSockets
- Test strategy: unit, integration, e2e, none / partial
- CI: GitHub Actions, GitLab CI, none, unknown
Minimum reads before Phase 2
Read at least:
- Root directory layout (top-level dirs)
- One dependency manifest (
go.mod, package.json, pyproject.toml, Cargo.toml)
- One main entrypoint or app bootstrap (
cmd/, main.go, src/index.ts)
- One config example (env template,
config.toml, docker-compose.yml, etc.)
Large / monorepo / polyglot repos
If the repo is large or a monorepo:
- State each major component (
gateway/, services/profile/, contracts/) with its own mini-context if stacks differ.
- Prioritize: entrypoints, public API routes, auth boundaries, contract sources (
proto, OpenAPI), CI workflows, infrastructure that defines secrets and CORS/TLS.
- Deep-dive additional files only when a risk is indicated or the domain requires it. Say what you sampled — don't claim you read the entire tree.
Output findings in a Context block (see Output Format). If the project is ambiguous, split by component.
Do not proceed to Phase 2 until Phase 1 is complete.
Phase 2 — Audit Domains
Apply each requested domain using the context from Phase 1. Adapt every check to what actually exists — skip checks for components that are not present (e.g. don't require a GraphQL schema if there is no GraphQL).
security
Core questions:
- Is authentication enforced where it should be? Are public routes explicit, not accidentally open?
- Are secrets (keys, passwords, tokens) absent from code, committed config, and history? Flag tracked
.env with real values, hardcoded production keys, etc.
- Is user input validated at the boundary before business logic / persistence?
- Are security headers present on HTTP responses where applicable?
- Is session / token invalidation possible and enforced on logout / revoke (if applicable)?
- Known CVEs: only report as a finding if you ran a supported scanner in this session (
govulncheck, osv-scanner, npm audit). Otherwise state: NOTE: Dependency CVE posture not verified in this run (no scanner executed). — this is an explicit gap, not a PASS.
Optional when relevant: CORS correctness (credentials + allowlist), admin/docs exposure in production, idempotency of sensitive operations.
contracts
Core questions:
- Does the declared API surface (spec, schema, types, proto) match the actual implementation?
- Are breaking changes guarded, versioned, or documented?
- Is documentation (OpenAPI, GraphQL schema, exported types) generated from a single source of truth vs manually maintained (drift risk)?
- Do internal consumers depend on the declared contract, not leaked implementation details?
patterns
Core questions:
- Is error handling explicit / typed where the language encourages it? Avoid leaking stack traces or internal messages to untrusted clients.
- Dependency direction: avoid disallowed cycles / layer violations for this codebase's stated architecture.
- Configuration: loaded and validated at startup, not scattered ad-hoc
getenv calls in domain logic.
- Abstractions: justified by actual use, not speculative.
- Idioms: respect language / framework conventions.
- State: mutation boundaries are clear (who owns mutable state, concurrency).
observability
Core questions:
- Are errors logged with enough context to diagnose without a debugger (request id, route, safe fields)?
- Does logging avoid PII at routine levels (emails, tokens, full bodies, secrets)? Flag high-risk patterns.
- Health checks: do they reflect dependencies (DB, Redis) or only process liveness?
- Metrics / tracing at boundaries (HTTP, gRPC, DB, external APIs) if the stack claims production readiness.
ops
Core questions:
- Build / images: reproducible enough for the team (lockfiles, pinned bases)? No secrets baked into images without a documented rotation story?
- CI: does the pipeline run what it claims (lint, types, unit tests, contract checks)? Gaps between "we care about this" and "what actually runs" are findings.
- Dependencies: lockfiles + verification (
go mod verify, lockfile install) where applicable.
- Local / onboarding: can a new engineer run the stack from documented steps (README, compose,
make), or is it tribal knowledge?
- Migrations / deploys: documented rollback or "safe retry" story where relevant.
Behavior Rules
- Evidence first. Read or search the repo before claiming a finding. If you infer, label it
INFERRED (needs confirmation) and state what file would confirm it.
- Findings only. Report items that are WRONG, INCOMPLETE, or create REAL RISK. Do not summarize what looks good. Do not list compliments.
- Empty domain. If a domain has no findings, output
[DOMAIN] PASS and continue.
- Location. Prefer
path/to/file:line. If the issue is process-wide (missing CI job, no policy), use Location: (process / CI / policy) and name the artifact that should exist.
- Fix. Must be actionable. Use a short code or config block when it fits. For architectural fixes, describe steps and interfaces; a patch is optional.
- Severity (every finding):
- BLOCKER — must fix before merge
- HIGH — must fix before production
- MEDIUM — fix this sprint
- LOW — document and defer
- End with a verdict:
AUDIT PASSED or AUDIT FAILED, with counts.
Verdict rule: AUDIT FAILED if any BLOCKER exists. Optionally fail on HIGH if the user instructed stricter gates in the chat.
Output Format
## Context
Date: YYYY-MM-DD
Domains audited: ...
Language(s): ...
Runtime / framework: ...
Auth: ...
Data layer: ...
Infra: ...
API surface: ...
Tests: ...
CI: ...
Sampling notes (if large repo): ...
## Audit Report — [domains] — YYYY-MM-DD
### SECURITY
[BLOCKER|HIGH|MEDIUM|LOW] Short title
Location: path:line OR (process / CI / policy)
Impact: one concrete sentence (what breaks, what leaks, what drifts)
Fix: actionable steps; optional code block if helpful
### CONTRACTS
(same pattern)
### PATTERNS
(same pattern)
### OBSERVABILITY
(same pattern)
### OPS
(same pattern)
---
## Verdict: AUDIT PASSED | AUDIT FAILED
Blockers: N | High: M | Medium: K | Low: J
Quick Domain Map
| Domain |
Typical artifacts |
| security |
auth middleware, routes, secrets, CORS, headers, dependency scan (if run) |
| contracts |
proto, OpenAPI, GraphQL schema, generated clients, CI *-check jobs |
| patterns |
layers, errors, config loading, module boundaries |
| observability |
logging, metrics, health checks, tracing |
| ops |
Dockerfile, compose, CI YAML, migration docs, lockfiles |
1---2name: audit3description: Multi-domain codebase audit: security, contracts, patterns, observability, and ops. Invoke as `/audit [domain?]` where domain is one of: security | contracts | patterns | observability | ops | all (default). Use whenever the user asks to audit or review a codebase for issues, wants a security review, asks what's wrong with the code, requests a pre-release or pre-merge quality check, or wants a comprehensive inspection across quality dimensions. Trigger proactively on "audit", "security review", "code review", "what issues does this codebase have", or "check before we ship".4license: Apache-2.05---67## Overview89Run a structured, evidence-based audit of a codebase. Two phases always run in order: first detect context, then apply the requested domains.1011**Usage:** `/audit [domain?]`1213- No domain → run **all** domains (default)14- Available domains: `security` | `contracts` | `patterns` | `observability` | `ops` | `all`1516## Safety1718Do **not** run destructive operations (DB resets, production deploys, mass deletes, `git push --force`, etc.) unless the user explicitly asks in the same session. Use read-only inspection: read files, Glob, Grep, and read-only git commands (`git log -1`, `git grep`) — no history rewrites.1920---2122## Phase 1 — Context Detection2324Always runs first. Read the project to understand what you're working with. Identify and state explicitly:2526- **Language(s):** Go, Python, TypeScript, Rust, etc.27- **Runtime / framework:** gRPC, FastAPI, Next.js, Express, Django, etc.28- **Auth mechanism:** JWT, sessions, OAuth, API keys, none29- **Data layer:** SQL (which DB), NoSQL, ORM, raw queries, none30- **Infra:** Docker, Kubernetes, serverless, bare metal31- **API surface:** REST, gRPC, GraphQL, tRPC, WebSockets32- **Test strategy:** unit, integration, e2e, none / partial33- **CI:** GitHub Actions, GitLab CI, none, unknown3435### Minimum reads before Phase 23637Read at least:3839- Root directory layout (top-level dirs)40- **One** dependency manifest (`go.mod`, `package.json`, `pyproject.toml`, `Cargo.toml`)41- **One** main entrypoint or app bootstrap (`cmd/`, `main.go`, `src/index.ts`)42- **One** config example (env template, `config.toml`, `docker-compose.yml`, etc.)4344### Large / monorepo / polyglot repos4546If the repo is large or a monorepo:47481. State **each major component** (`gateway/`, `services/profile/`, `contracts/`) with its own mini-context if stacks differ.492. **Prioritize:** entrypoints, public API routes, auth boundaries, contract sources (`proto`, OpenAPI), CI workflows, infrastructure that defines secrets and CORS/TLS.503. **Deep-dive** additional files only when a risk is indicated or the domain requires it. Say what you sampled — don't claim you read the entire tree.5152Output findings in a **Context** block (see Output Format). If the project is ambiguous, split by component.5354Do **not** proceed to Phase 2 until Phase 1 is complete.5556---5758## Phase 2 — Audit Domains5960Apply each requested domain using the context from Phase 1. **Adapt every check** to what actually exists — skip checks for components that are not present (e.g. don't require a GraphQL schema if there is no GraphQL).6162### security6364Core questions:6566- Is authentication enforced where it should be? Are public routes **explicit**, not accidentally open?67- Are secrets (keys, passwords, tokens) absent from **code**, committed **config**, and **history**? Flag tracked `.env` with real values, hardcoded production keys, etc.68- Is user input validated at the **boundary** before business logic / persistence?69- Are **security headers** present on HTTP responses where applicable?70- Is session / token invalidation possible and enforced on logout / revoke (if applicable)?71- **Known CVEs:** only report as a finding if you **ran** a supported scanner in this session (`govulncheck`, `osv-scanner`, `npm audit`). Otherwise state: `NOTE: Dependency CVE posture not verified in this run (no scanner executed).` — this is an explicit gap, not a PASS.7273Optional when relevant: CORS correctness (credentials + allowlist), admin/docs exposure in production, idempotency of sensitive operations.7475### contracts7677Core questions:7879- Does the declared API surface (spec, schema, types, proto) **match** the actual implementation?80- Are breaking changes guarded, versioned, or documented?81- Is documentation (OpenAPI, GraphQL schema, exported types) **generated from a single source of truth** vs manually maintained (drift risk)?82- Do internal consumers depend on the **declared** contract, not leaked implementation details?8384### patterns8586Core questions:8788- Is error handling explicit / typed where the language encourages it? Avoid leaking stack traces or internal messages to untrusted clients.89- Dependency direction: avoid disallowed cycles / layer violations for this codebase's stated architecture.90- Configuration: loaded and validated at startup, not scattered ad-hoc `getenv` calls in domain logic.91- Abstractions: justified by actual use, not speculative.92- Idioms: respect language / framework conventions.93- State: mutation boundaries are clear (who owns mutable state, concurrency).9495### observability9697Core questions:9899- Are errors logged with enough context to diagnose without a debugger (request id, route, safe fields)?100- Does logging **avoid PII** at routine levels (emails, tokens, full bodies, secrets)? Flag high-risk patterns.101- Health checks: do they reflect **dependencies** (DB, Redis) or only process liveness?102- Metrics / tracing at boundaries (HTTP, gRPC, DB, external APIs) if the stack claims production readiness.103104### ops105106Core questions:107108- Build / images: reproducible enough for the team (lockfiles, pinned bases)? No secrets baked into images without a documented rotation story?109- CI: does the pipeline run what it claims (lint, types, unit tests, contract checks)? Gaps between "we care about this" and "what actually runs" are findings.110- Dependencies: lockfiles + verification (`go mod verify`, lockfile install) where applicable.111- Local / onboarding: can a new engineer run the stack from **documented** steps (README, compose, `make`), or is it tribal knowledge?112- Migrations / deploys: documented rollback or "safe retry" story where relevant.113114---115116## Behavior Rules1171181. **Evidence first.** Read or search the repo before claiming a finding. If you infer, label it `INFERRED (needs confirmation)` and state what file would confirm it.1192. **Findings only.** Report items that are **WRONG**, **INCOMPLETE**, or create **REAL RISK**. Do not summarize what looks good. Do not list compliments.1203. **Empty domain.** If a domain has no findings, output `[DOMAIN] PASS` and continue.1214. **Location.** Prefer `path/to/file:line`. If the issue is process-wide (missing CI job, no policy), use `Location: (process / CI / policy)` and name the artifact that should exist.1225. **Fix.** Must be **actionable**. Use a short code or config block when it fits. For architectural fixes, describe steps and interfaces; a patch is optional.1236. **Severity** (every finding):124 - **BLOCKER** — must fix before merge125 - **HIGH** — must fix before production126 - **MEDIUM** — fix this sprint127 - **LOW** — document and defer1287. End with a **verdict:** `AUDIT PASSED` or `AUDIT FAILED`, with counts.129130**Verdict rule:** `AUDIT FAILED` if **any** BLOCKER exists. Optionally fail on HIGH if the user instructed stricter gates in the chat.131132---133134## Output Format135136```markdown137## Context138Date: YYYY-MM-DD139Domains audited: ...140141Language(s): ...142Runtime / framework: ...143Auth: ...144Data layer: ...145Infra: ...146API surface: ...147Tests: ...148CI: ...149Sampling notes (if large repo): ...150151## Audit Report — [domains] — YYYY-MM-DD152153### SECURITY154[BLOCKER|HIGH|MEDIUM|LOW] Short title155Location: path:line OR (process / CI / policy)156Impact: one concrete sentence (what breaks, what leaks, what drifts)157Fix: actionable steps; optional code block if helpful158159### CONTRACTS160(same pattern)161162### PATTERNS163(same pattern)164165### OBSERVABILITY166(same pattern)167168### OPS169(same pattern)170171---172## Verdict: AUDIT PASSED | AUDIT FAILED173Blockers: N | High: M | Medium: K | Low: J174```175176---177178## Quick Domain Map179180| Domain | Typical artifacts |181|--------|-------------------|182| security | auth middleware, routes, secrets, CORS, headers, dependency scan (if run) |183| contracts | proto, OpenAPI, GraphQL schema, generated clients, CI `*-check` jobs |184| patterns | layers, errors, config loading, module boundaries |185| observability | logging, metrics, health checks, tracing |186| ops | Dockerfile, compose, CI YAML, migration docs, lockfiles |