
Opinionated Zig patterns focused on type safety and explicit error handling. You get tagged unions instead of nullable soup, distinct types for domain IDs, and comptime validation to catch config errors before runtime. Memory management is thorough: explicit allocators, defer/errdefer placement rules, and arena patterns for batch work. The conventions push you toward const by default, explicit types over anytype, and exhaustive switches. It's clearly extracted from a larger style guide (references CLAUDE.md and other docs), so treat it as a starting point that assumes you'll adapt to your project's needs. Includes pointers to companion tooling like zigdoc and ziglint.
$ npx -y skills add 0xbigboss/claude-code --skill zig-best-practices --agent claude-codeInstalls into .claude/skills of the current project.
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:
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 };
}
Sponsors