internal/skills/content/zig-guide/SKILL.md
Zig language guardrails, patterns, and best practices for AI-assisted development. Use when working with Zig files (.zig), build.zig, or when the user mentions Zig. Provides comptime patterns, allocator conventions, C interop guidelines, and testing standards specific to this project's coding standards.
npx skillsauth add ar4mirez/samuel zig-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Applies to: Zig 0.13+, Systems Programming, CLIs, Embedded, Game Engines, C/C++ Replacement
std.mem.Allocator as a parameter; never use a global allocator!) with try, catch, and errdefer; never silently discard errorscomptime; use it for generics, validation, and code generationzig fmt before every commit (non-negotiable)camelCase functions/variables, PascalCase types/structs/enums, SCREAMING_SNAKE_CASE module constantssnake_case for file names (my_module.zig)_ = value; (no _ prefix naming)const over var everywhere; mutability requires justificationpub fn, pub const) must have a doc comment (///)std.mem.Allocator parameteralloc/free with defer or errdefer at the call sitestd.heap.ArenaAllocator for batch allocations freed togetherstd.heap.GeneralPurposeAllocator in debug builds (detects leaks, double-free)var buf: [256]u8 = undefined;) for small, bounded buffers[]T, []const T) over raw pointers ([*]T) whenever possible!T) for all fallible operationstry to propagate; use catch only where you can handle or log meaningfullyerrdefer to clean up resources on error pathsanyerror except at top-level boundaries_ = fallibleFn(); is forbidden outside testsconst ConfigError = error{ FileNotFound, InvalidFormat, MissingField };
fn loadConfig(allocator: std.mem.Allocator, path: []const u8) ConfigError!Config {
const file = std.fs.cwd().openFile(path, .{}) catch return error.FileNotFound;
defer file.close();
// parse and return ...
}
comptime parameters for generics instead of runtime polymorphism@typeInfo and @Type for type introspection at compile time@compileError to produce clear messages for invalid type combinationsinline for only when the loop count is comptime-known and smallfn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
fn ensureUnsigned(comptime T: type) void {
if (@typeInfo(T) != .int or @typeInfo(T).int.signedness == .signed)
@compileError("expected unsigned integer type");
}
std.math.add / std.math.mul for checked arithmetic; sentinel slices ([:0]const u8) for C strings@ptrCast and @intFromPtr unless interfacing with C; justify each usefn findUser(users: []const User, id: u64) ?*const User {
for (users) |*user| {
if (user.id == id) return user;
}
return null;
}
const user = findUser(users, 42) orelse return error.UserNotFound;
if (findUser(users, 42)) |u| {
std.debug.print("Found: {s}\n", .{u.name});
}
fn createConnection(allocator: std.mem.Allocator, host: []const u8) !*Connection {
const conn = try allocator.create(Connection);
errdefer allocator.destroy(conn); // only runs on error return
conn.* = .{ .socket = try std.net.tcpConnectToHost(allocator, host, 8080), .allocator = allocator };
errdefer conn.socket.close();
try conn.performHandshake();
return conn;
}
const fixed: [4]u8 = .{ 1, 2, 3, 4 }; // fixed-size array (stack)
const c_str: [:0]const u8 = "hello"; // sentinel-terminated (C compat)
fn sum(values: []const u32) u64 { // slice (preferred for params)
var total: u64 = 0;
for (values) |v| total += v;
return total;
}
const StatusRegister = packed struct {
carry: u1, zero: u1, irq_disable: u1, decimal: u1,
brk: u1, _reserved: u1, overflow: u1, negative: u1,
};
const CFileHeader = extern struct { magic: u32, version: u16, flags: u16, size: u64 };
const testing = @import("std").testing;
test "add returns correct sum" {
try testing.expectEqual(@as(i32, 5), add(2, 3));
}
test "string list detects leaks via testing allocator" {
var list = StringList.init(testing.allocator); // leak detection built-in
defer list.deinit();
try list.add("hello");
try testing.expectEqual(@as(usize, 1), list.items.items.len);
}
test "readFileContents returns error for missing file" {
try testing.expectError(error.FileNotFound, readFileContents(testing.allocator, "/nonexistent"));
}
test "user creation fails with empty name"test blocks inside the same .zig filetests/ directorystd.testing.allocator -- it detects memory leaks automaticallyexpectEqual, expectError, expectEqualStrings, expectEqualSliceszig build # Build (uses build.zig)
zig build test # Run all tests
zig build run # Build and run
zig fmt src/ # Format all source files
zig test src/main.zig # Test a single file
zig build -Doptimize=ReleaseSafe # Optimized with safety
zig build -Doptimize=ReleaseFast # Maximum performance
See patterns.md for a build.zig template.
@cImport / @cInclude for C headers (not manual extern declarations)[*c]T only at FFI boundary; convert to []T or ?*T immediatelystd.mem.span to convert [*:0]const u8 (C string) to Zig sliceexe.linkLibC() in build.zig when using libcFor full implementation examples, see:
tools
WordPress framework guardrails, patterns, and best practices for AI-assisted development. Use when working with WordPress projects, or when the user mentions WordPress. Provides theme development, plugin architecture, REST API, blocks, and security guidelines.
tools
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs. Use when testing web apps, automating browser interactions, or debugging frontend issues.
tools
Suite of tools for creating elaborate, multi-component web applications using modern frontend technologies (React, Tailwind CSS, shadcn/ui). Use for complex projects requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX pages.
development
Vapor framework guardrails, patterns, and best practices for AI-assisted development. Use when working with Vapor projects, or when the user mentions Vapor. Provides Fluent ORM, async Swift, routing, middleware, and server-side Swift guidelines.