OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add alleneubank/claude-code --skill zig-best-practices
Use when reading or writing Zig files (.zig, build.zig, build.zig.zon).
npx skills add alleneubank/claude-code --skill zig-best-practices
Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers Zig-specific idioms only.
Tagged unions for mutually exclusive states — prevents invalid combinations that a struct with multiple nullable fields would allow:
Explicit error sets — documents exactly what can fail; anyerror hides failure modes:
Distinct types for domain IDs — compiler prevents mixing up different ID types:
Comptime validation — catch invalid configurations at compile time, not runtime:
defer resource.deinit() immediately after acquisition — keeps cleanup co-located with creation.errdefer for cleanup on error paths; defer for unconditional cleanup.std.testing.allocator in tests — reports leaks with stack traces.const over var; prefer slices over raw pointers.comptime T: type over anytype; explicit types produce clearer errors. Use anytype only for genuinely polymorphic cases (callbacks, std.debug.print-style).switch: include an else returning an error or unreachable for truly impossible cases.std.log.scoped(.module_name) for namespaced logging; define a module-level const log constant.zigdoc — browse std library and dependency docs:
ziglint — static analysis with .ziglint.zon config:
const ParseError = error{ InvalidSyntax, UnexpectedToken, EndOfInput };
fn parse(input: []const u8) ParseError!Ast { ... }const UserId = enum(u64) { _ };
const OrderId = enum(u64) { _ };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 };
}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;
}zigdoc std.mem.Allocator # std lib symbol
zigdoc vaxis.Window # project dependency
zigdoc @init # create AGENTS.md with API patternsziglint # lint current directory
ziglint --ignore Z001 # suppress specific rule