Zig Code Review
Capability Boundaries
✅ Strong Suits
- Reviewing Zig code style and consistency
- Checking correctness and safety (error handling, memory, lifetimes)
- Checking code structure and logic clarity
- Zig version compatibility checks
⚠️ Requirements
- Requires code to review (diff, file list, or code snippet)
- Requires a target Zig version
❌ Out of Scope
- Writing new code → use zig-0.16 skill
- Non-Zig code review → use the appropriate language review skill
When to use
Use this skill when the user needs to review a Zig PR/commit/diff, audit coding conventions, or check code quality.
Data Privacy
This skill does not collect, store, or transmit any user data. All reviews happen entirely within the local conversation.
This skill reviews Zig project code for:
- Code style and consistency (project conventions + Zig style guide)
- Correctness and safety (errors, memory, lifetimes, resource cleanup)
- Code-structure and logic clarity (functions/modules responsibilities, control flow)
- Zig version compatibility pitfalls (build system, I/O, container init, removed features)
Quick Start
Example invocations:
Review this Zig code: <paste code>
Check this diff for Zig version compatibility issues
Review this commit's Zig code quality
Workflow
Step 1. Determine review scope — Get diff, file list, or modules to review
Step 2. Confirm Zig version — Check via zig version or project config. When reviewing code, load the matching reference file from references/.
Step 3. Run mechanical checks — Check formatting zig fmt, removed APIs, build config
Step 4. Review logic & correctness — Control flow, boundary checks, error propagation
Step 5. Review resources & memory — Allocator choice, defer/errdefer, lifetimes
Step 6. Output structured feedback — Use the Output Template
When to Invoke
Invoke when the user asks to:
- Review a Zig PR / commit / diff
- Audit a Zig codebase’s coding conventions and module structure
- Review a code snippet’s logic and error-handling correctness
- Prepare code before merge or release (quality gate)
Inputs to Ask For (if missing)
- Review scope: a diff, file list, or specific modules/functions
- Target Zig version (or confirm repo’s version; do not assume)
- Expected behavior / invariants (what must be true after the change)
- Build entry points:
build.zig, build.zig.zon, main/root file locations
- Any project-specific conventions (naming, layering, error taxonomy, allocators)
Review Workflow (Project-Level)
- Identify the repository’s conventions
- Directory structure:
src/, src/main.zig (exe) / src/root.zig (lib), module layout, naming patterns
- Error types strategy, allocator strategy, logging strategy
- Run mechanical checks
- Formatting (
zig fmt expectations)
- Compile-breaking API mismatches and removed features for the repo’s Zig version
- Review logic and correctness
- Control flow clarity, invariants, boundary checks, error propagation correctness
- Review memory and resource management
- Allocator choice,
defer / errdefer, ownership, lifetime safety
- Review public API and maintainability
- Module boundaries, dependency direction, duplication, naming, docs/tests
- Produce structured output (see Output Template)
Checklist
A. Style & Consistency (Should Be Deterministic)
- Naming matches project conventions and Zig Style Guide (types, functions, files, constants)
- Imports grouped consistently (std → third-party → local), unused imports removed
- Public symbols are intentionally exported (avoid accidental
pub)
- Avoid “magic numbers”; encode invariants as constants or types
- No overly long functions without clear sections; extract helpers if needed
B. Module & Responsibility Boundaries (Project Quality)
- Each module has a single responsibility and clear API surface
- No cyclic dependencies between modules; dependencies flow one way
- Shared utilities are in a well-known location, not copied across modules
- Error types are defined at appropriate boundary (library vs application)
- Configuration/schema types are centralized and reused
C. Logic & Correctness (Most Important)
- Inputs validated at module boundaries (index bounds, nullability, ranges)
- Optional unwrapping is guarded (
if (opt) |v| ... else ... or orelse)
@intCast/@floatCast/@ptrCast usage is justified and safe
switch is exhaustive where it must be; non-exhaustive enums handled intentionally
- No unreachable states without proof (
unreachable must be justified)
D. Error Handling & Resource Safety
- Error propagation is correct:
try used where failure must bubble up
catch does not hide important failures; avoid catch unreachable on allocs
- Partial construction uses
errdefer to prevent leaks on mid-function failure
- Every allocation has a corresponding cleanup path
- Container lifecycle is correct (
.empty/.init + proper deinit(allocator) where applicable)
E. Zig Version Compatibility (Common Review Gate)
- Build system uses modern APIs (avoid outdated build fields/patterns)
- I/O uses
std.Io patterns (avoid old std.io examples that no longer compile)
- Removed language features are not used (
async/await, usingnamespace, etc.)
- Formatting follows modern formatter conventions (e.g.
{f} where required)
F. Concurrency (If Applicable)
- Shared mutable state guarded (mutex/atomics) with clear ownership rules
- Thread spawning/joining is paired; failure paths handled
- Atomics use appropriate orderings; avoid “default to strongest ordering” without reason
G. C Interop (If Applicable)
- ABI is correct:
extern, calling convention, alignment, packed-field pointer hazards avoided
@cImport boundaries are controlled; headers and -I paths are explicit in build
- Strings and buffers respect C conventions (NUL-termination, lifetimes)
H. Tests & Tooling
- Tests cover success + failure paths (especially parsing, IO, state transitions)
- Use the right assertions for slices/strings
- CI/build steps compile on target platforms (if cross-compiling is a goal)
Output Template
Provide review feedback in this structure:
- Summary
- What the change does and overall health (1–3 sentences)
- Blocking Issues (must fix)
- Each item: Location → Symptom → Why it is risky → Suggested fix
- Non-blocking Improvements
- Refactors, naming, structure, doc improvements
- Zig Version Notes (if relevant)
- Any outdated patterns found and the modern replacement
- Suggested Patch (optional)
- Minimal change proposal for the most important item
Local References (Vendored)
These files are copied into this skill so reviews remain useful when external sites are unavailable:
references/code-review.md
references/style-guide.md
Embedded Reference Cards
Use these quick checks when you need fast feedback or when you don’t have access to external references.
High-confidence “always flag” patterns
return &local_var (dangling pointer)
.? without a guarding if / orelse path (panic risk)
catch unreachable on allocation / fallible ops (panic risk)
- Pointer to packed field (undefined behavior)
- Unpaired resource cleanup (
defer missing on success path or missing errdefer on partial construction)
Readability and logic structure checks
- Each function has a single responsibility and an obvious precondition/validation section
- Error paths do not bypass cleanup; early returns do not leak resources
- Branching is explicit; avoid deeply nested conditionals when a guard clause is clearer
- Boundary checks are near the boundary; do not assume inputs are valid unless enforced by types
Audience
| User Type |
Usage |
| Zig developers |
Self-check before commit, or review team PRs |
| Project maintainers |
Unify team coding conventions |
| CI pipeline |
Reference as code quality gate |
Customization:
- Specify review strictness (strict / standard / light)
- Specify focus area (security / style / full)
- Specify output format (full report / blocking only / suggestions only)
Gotchas
- Confirm version before review — Different Zig versions have significant API differences; always check the target
- Don't over-suggest — Some patterns (e.g.
catch unreachable) may be intentional design choices
- Project conventions first — Always prioritize the project's existing conventions over external standards
- Consistent output — Use the same output template for every review so readers find issues quickly
FAQ
Q: What information is needed for a review?
A: At minimum, a Zig code snippet or diff, plus the target version.
Q: How does this skill relate to zig-0.16?
A: zig-code-review focuses on the review process and standards. zig-0.16 provides language reference and API details. They complement each other.
Q: Can you auto-fix found issues?
A: Suggestions are provided but not applied directly. The user can confirm before applying.
1---2name: zig-code-review3description: Review Zig project code for style, correctness, and logic. Invoke when reviewing PRs/diffs, assessing project conventions, or requesting a Zig-focused code quality audit.4---56# Zig Code Review78## Capability Boundaries910### ✅ Strong Suits111. Reviewing Zig code style and consistency122. Checking correctness and safety (error handling, memory, lifetimes)133. Checking code structure and logic clarity144. Zig version compatibility checks1516### ⚠️ Requirements171. Requires code to review (diff, file list, or code snippet)182. Requires a target Zig version1920### ❌ Out of Scope211. Writing new code → use zig-0.16 skill222. Non-Zig code review → use the appropriate language review skill2324## When to use2526Use this skill when the user needs to review a Zig PR/commit/diff, audit coding conventions, or check code quality.2728## Data Privacy2930This skill does not collect, store, or transmit any user data. All reviews happen entirely within the local conversation.3132This skill reviews Zig project code for:3334- Code style and consistency (project conventions + Zig style guide)35- Correctness and safety (errors, memory, lifetimes, resource cleanup)36- Code-structure and logic clarity (functions/modules responsibilities, control flow)37- Zig version compatibility pitfalls (build system, I/O, container init, removed features)3839## Quick Start4041**Example invocations:**42```43Review this Zig code: <paste code>44Check this diff for Zig version compatibility issues45Review this commit's Zig code quality46```4748## Workflow4950Step 1. **Determine review scope** — Get diff, file list, or modules to review51Step 2. **Confirm Zig version** — Check via `zig version` or project config. When reviewing code, load the matching reference file from references/.52Step 3. **Run mechanical checks** — Check formatting `zig fmt`, removed APIs, build config53Step 4. **Review logic & correctness** — Control flow, boundary checks, error propagation54Step 5. **Review resources & memory** — Allocator choice, defer/errdefer, lifetimes55Step 6. **Output structured feedback** — Use the Output Template5657## When to Invoke5859Invoke when the user asks to:6061- Review a Zig PR / commit / diff62- Audit a Zig codebase’s coding conventions and module structure63- Review a code snippet’s logic and error-handling correctness64- Prepare code before merge or release (quality gate)6566## Inputs to Ask For (if missing)6768- Review scope: a diff, file list, or specific modules/functions69- Target Zig version (or confirm repo’s version; do not assume)70- Expected behavior / invariants (what must be true after the change)71- Build entry points: `build.zig`, `build.zig.zon`, main/root file locations72- Any project-specific conventions (naming, layering, error taxonomy, allocators)7374## Review Workflow (Project-Level)75761. Identify the repository’s conventions77 - Directory structure: `src/`, `src/main.zig` (exe) / `src/root.zig` (lib), module layout, naming patterns78 - Error types strategy, allocator strategy, logging strategy792. Run mechanical checks80 - Formatting (`zig fmt` expectations)81 - Compile-breaking API mismatches and removed features for the repo’s Zig version823. Review logic and correctness83 - Control flow clarity, invariants, boundary checks, error propagation correctness844. Review memory and resource management85 - Allocator choice, `defer` / `errdefer`, ownership, lifetime safety865. Review public API and maintainability87 - Module boundaries, dependency direction, duplication, naming, docs/tests886. Produce structured output (see Output Template)8990## Checklist9192### A. Style & Consistency (Should Be Deterministic)9394- Naming matches project conventions and Zig Style Guide (types, functions, files, constants)95- Imports grouped consistently (std → third-party → local), unused imports removed96- Public symbols are intentionally exported (avoid accidental `pub`)97- Avoid “magic numbers”; encode invariants as constants or types98- No overly long functions without clear sections; extract helpers if needed99100### B. Module & Responsibility Boundaries (Project Quality)101102- Each module has a single responsibility and clear API surface103- No cyclic dependencies between modules; dependencies flow one way104- Shared utilities are in a well-known location, not copied across modules105- Error types are defined at appropriate boundary (library vs application)106- Configuration/schema types are centralized and reused107108### C. Logic & Correctness (Most Important)109110- Inputs validated at module boundaries (index bounds, nullability, ranges)111- Optional unwrapping is guarded (`if (opt) |v| ... else ...` or `orelse`)112- `@intCast`/`@floatCast`/`@ptrCast` usage is justified and safe113- `switch` is exhaustive where it must be; non-exhaustive enums handled intentionally114- No unreachable states without proof (`unreachable` must be justified)115116### D. Error Handling & Resource Safety117118- Error propagation is correct: `try` used where failure must bubble up119- `catch` does not hide important failures; avoid `catch unreachable` on allocs120- Partial construction uses `errdefer` to prevent leaks on mid-function failure121- Every allocation has a corresponding cleanup path122- Container lifecycle is correct (`.empty`/`.init` + proper `deinit(allocator)` where applicable)123124### E. Zig Version Compatibility (Common Review Gate)125126- Build system uses modern APIs (avoid outdated build fields/patterns)127- I/O uses `std.Io` patterns (avoid old `std.io` examples that no longer compile)128- Removed language features are not used (`async`/`await`, `usingnamespace`, etc.)129- Formatting follows modern formatter conventions (e.g. `{f}` where required)130131### F. Concurrency (If Applicable)132133- Shared mutable state guarded (mutex/atomics) with clear ownership rules134- Thread spawning/joining is paired; failure paths handled135- Atomics use appropriate orderings; avoid “default to strongest ordering” without reason136137### G. C Interop (If Applicable)138139- ABI is correct: `extern`, calling convention, alignment, packed-field pointer hazards avoided140- `@cImport` boundaries are controlled; headers and `-I` paths are explicit in build141- Strings and buffers respect C conventions (NUL-termination, lifetimes)142143### H. Tests & Tooling144145- Tests cover success + failure paths (especially parsing, IO, state transitions)146- Use the right assertions for slices/strings147- CI/build steps compile on target platforms (if cross-compiling is a goal)148149## Output Template150151Provide review feedback in this structure:1521531. Summary154 - What the change does and overall health (1–3 sentences)1552. Blocking Issues (must fix)156 - Each item: Location → Symptom → Why it is risky → Suggested fix1573. Non-blocking Improvements158 - Refactors, naming, structure, doc improvements1594. Zig Version Notes (if relevant)160 - Any outdated patterns found and the modern replacement1615. Suggested Patch (optional)162 - Minimal change proposal for the most important item163164## Local References (Vendored)165166These files are copied into this skill so reviews remain useful when external sites are unavailable:167168- `references/code-review.md`169- `references/style-guide.md`170171## Embedded Reference Cards172173Use these quick checks when you need fast feedback or when you don’t have access to external references.174175### High-confidence “always flag” patterns176177- `return &local_var` (dangling pointer)178- `.?` without a guarding `if` / `orelse` path (panic risk)179- `catch unreachable` on allocation / fallible ops (panic risk)180- Pointer to packed field (undefined behavior)181- Unpaired resource cleanup (`defer` missing on success path or missing `errdefer` on partial construction)182183### Readability and logic structure checks184185- Each function has a single responsibility and an obvious precondition/validation section186- Error paths do not bypass cleanup; early returns do not leak resources187- Branching is explicit; avoid deeply nested conditionals when a guard clause is clearer188- Boundary checks are near the boundary; do not assume inputs are valid unless enforced by types189190## Audience191192| User Type | Usage |193|-----------|-------|194| **Zig developers** | Self-check before commit, or review team PRs |195| **Project maintainers** | Unify team coding conventions |196| **CI pipeline** | Reference as code quality gate |197198Customization:199- Specify review strictness (strict / standard / light)200- Specify focus area (security / style / full)201- Specify output format (full report / blocking only / suggestions only)202203## Gotchas2042051. **Confirm version before review** — Different Zig versions have significant API differences; always check the target2062. **Don't over-suggest** — Some patterns (e.g. `catch unreachable`) may be intentional design choices2073. **Project conventions first** — Always prioritize the project's existing conventions over external standards2084. **Consistent output** — Use the same output template for every review so readers find issues quickly209210## FAQ211212**Q: What information is needed for a review?**213A: At minimum, a Zig code snippet or diff, plus the target version.214215**Q: How does this skill relate to `zig-0.16`?**216A: `zig-code-review` focuses on the review process and standards. `zig-0.16` provides language reference and API details. They complement each other.217218**Q: Can you auto-fix found issues?**219A: Suggestions are provided but not applied directly. The user can confirm before applying.220