zig-best-practices

zig-best-practices is a skill for Claude Code, Codex from alleneubank/claude-code. It costs 26 tokens per session (811 once invoked), scanned A, original, Apache-2.0.

A set of guidelines for writing Zig code, including how to model data, handle errors, manage memory, and validate settings.

In plain words
What is it for?
Use it when reading or writing Zig source files, build files, and package configuration files.
Why use it?
It helps avoid invalid program states and makes failures, resource cleanup, and memory allocation clearer in Zig projects.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/alleneubank/claude-code/zig-best-practices
Any agent
npx skills add alleneubank/claude-code --skill zig-best-practices
Clone the repo
git clone --depth 1 https://github.com/alleneubank/claude-code

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for zig-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/alleneubank/claude-code/zig-best-practices.svg)](https://agentmods.dev/skills/alleneubank/claude-code/zig-best-practices)
Your own site
<a href="https://agentmods.dev/skills/alleneubank/claude-code/zig-best-practices"><img src="https://agentmods.dev/badge/skills/alleneubank/claude-code/zig-best-practices.svg" alt="Measured on agentmods" height="20"></a>
Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 811 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00026 $0.00811
Opus 5 $0.00013 $0.00405
Sonnet 5 $0.00005 $0.00162
Haiku 4.5 $0.00003 $0.00081

Measured 3d ago against content hash b44bbabb0c66, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

zig-best-practices scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- **C library interop** (raylib, SDL, curl): See [C-INTEROP.md](C-INTEROP.md)
.claude/skills/zig-best-practices/SKILL.md · 93 lines

How it starts

The opening of the file, as written. The whole thing — 93 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Zig Best Practices

Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers Zig-specific idioms only.

Type System Patterns

Tagged unions for mutually exclusive states — prevents invalid combinations that a struct with multiple nullable fields would allow:

const RequestState = union(enum) {
    idle,
    loading,
    success: []const u8,
    failure: anyerror,
};

Explicit error sets — documents exactly what can fail; anyerror hides failure modes:

const ParseError = error{ InvalidSyntax, UnexpectedToken, EndOfInput };
fn parse(input: []const u8) ParseError!Ast { ... }

Distinct types for domain IDs — compiler prevents mixing up different ID types:

const UserId = enum(u64) { _ };
const OrderId = enum(u64) { _ };

Comptime validation — catch invalid configurations at compile time, not runtime:

fn Buffer(comptime size: usize) type {
    if (size == 0) @compileError("buffer size must be greater than 0");
    return struct { data: [size]u8 = undefined, len: usize = 0 };
}

Memory Management

  • Pass allocators explicitly to every function that allocates; no global allocator state.
  • Place defer resource.deinit() immediately after acquisition — keeps cleanup co-located with creation.
  • Use errdefer for cleanup on error paths; defer for unconditional cleanup.
  • Use arena allocators for batch/temporary work; they free everything at once.
  • Use std.testing.allocator in tests — reports leaks with stack traces.
fn createResource(allocator: std.mem.Allocator) !*Resource {
    const resource = try allocator.create(Resource);
    errdefer allocator.destroy(resource);  // runs only on error
    resource.* = try initializeResource();
    return resource;
}

Key Conventions

  • Prefer const over var; prefer slices over raw pointers.
  • Prefer comptime T: type over anytype; explicit types produce clearer errors. Use anytype only for genuinely polymorphic cases (callbacks, std.debug.print-style).
  • Exhaustive switch: include an else returning an error or unreachable for truly impossible cases.
  • Use std.log.scoped(.module_name) for namespaced logging; define a module-level const log constant.
  • Larger cohesive files are idiomatic — tests alongside implementation, comptime generics at file scope.

Read the full file on GitHub · 93 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 93 lines · 26 tokens per session scan A b44bbabb0c66

Subscribe to this mod's changes

zig-best-practices is a skill published in the GitHub repository alleneubank/claude-code (52 stars, last pushed 2mo ago), licensed Apache-2.0. It adds 26 tokens to every session and 811 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

development

开发语言能力索引。Python、Go、Rust、TypeScript、Java、C++、Shell。当用户提到编程、开发、代码、语言时路由到此。.

fengshao1227/ccg-workflow · 41 tokens

rust-pro

Master modern Rust (2024 edition) with async patterns, advanced type system features, and production-ready systems programming. Expert in the current Rust ecosystem including Tokio, axum, and modern crates. Use PROACTIVELY for Rust development, performance optimization, or systems programming.

vudovn/ag-kit · 58 tokens

ax-python-agent

Use when writing Python code with axllm for agents, child delegation, tools, MCP, citations, persistent playbook learning, stage instructions, runtime state, final typed responses, and direct-respond executor skipping.

ax-llm/ax · 49 tokens

migrate-better-result-3

Migrate a TypeScript codebase from better-result 2.x to 3.0. Use when upgrading better-result across the TaggedError syntax, removed Result serialization helpers, recovery inference, matching, or retry APIs.

dmmulroy/better-result · 52 tokens

mps-aspect-actions

Use when defining or editing MPS node factories (the "actions" aspect) — NodeFactories roots, per-concept NodeFactory setup functions that initialize a freshly created node and optionally copy data from a replaced sampleNode, plus the actions aspect's CopyPasteHandlers and PasteWrappers roots. Reach for this skill…

JetBrains/MPS · 115 tokens

product-marketing

Build product marketing strategy including positioning, messaging, and go-to-market. Use when the user says "positioning", "messaging framework", "go-to-market", "GTM strategy", "product marketing", "competitive positioning", "battlecard", "sales enablement", "launch plan", or asks about how to position or message…

OpenClaudia/openclaudia-skills · 77 tokens