idiomatic-zig

Provides production Zig coding patterns from Ghostty and TigerBeetle for memory, safety, and performance.

Updated Nov 10, 2013
One-click install
npx skills add https://github.com/bnferguson/dotfiles --skill idiomatic-zig-bnferguson
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: idiomatic-zig
Source: https://github.com/bnferguson/dotfiles/tree/main/.agents/skills/idiomatic-zig
Command: npx skills add https://github.com/bnferguson/dotfiles --skill idiomatic-zig-bnferguson

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing fast, safe, maintainable Zig requires knowing idioms that are scattered across flagship projects like Ghostty and TigerBeetle, and Zig 0.16 changed enough APIs (std.Io, @Struct/@Enum, std.process.Init) that older advice silently breaks. ## Core Features & Use Cases - Design philosophy and style rules: Tiger Style principles, naming conventions, 70-line function limits, and assertion discipline distilled into actionable guidance. - Deep reference material: Six reference files covering memory patterns, performance (SIMD, cache lines, branch hints), safety and assertions, testing strategies (VOPR, fuzzing, tripwires), API design, and Tiger Style principles. - Compilable examples: Eight example Zig files verified against Zig 0.16 via check.sh, covering packed structs, static allocators, options structs, comptime type generation, and concurrency. - Use Case: When writing a new Zig module, load this skill to apply assertion density rules, choose the right allocator strategy, structure APIs with options structs, and avoid 0.16 migration pitfalls. ## Quick Start Ask the assistant to review or write Zig code using the idiomatic-zig patterns, for example to design a cache-friendly packed struct with proper assertions for a hot data path.

Frequently Asked Questions about idiomatic-zig

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write idiomatic Zig code for production systems?▼

Follow patterns from Ghostty and TigerBeetle: use options structs for configuration, pass Allocator and Io explicitly, maintain at least two assertions per function, and prefer packed structs with meaningful zero values for hot data. This skill packages those rules with compilable examples.

What changed in Zig 0.16 for concurrency and I/O?▼

Zig 0.16 moved blocking primitives from std.Thread into std.Io (Mutex, RwLock, Condition, Semaphore, Group), made std.Io an interface value passed like an Allocator, and split @Type into @Struct/@Enum/@Int/@Union/@Pointer. Blocking calls now return Cancelable!T.

How does TigerBeetle approach testing in Zig?▼

TigerBeetle uses deterministic simulation (VOPR) that stubs clock, network, and disk so a seed plus commit reproduces any failure, plus dedicated fuzzers per data structure, swarm testing, and coverage marks proving tests hit intended paths. Zig 0.16's std.Io interface makes stubbing non-determinism compiler-enforceable.

Does this skill work with Zig versions other than 0.16?▼

The examples are verified against Zig 0.16.0 via the included check.sh script, and 0.16-specific changes are called out inline. For other versions, pair it with a version-detection skill since APIs like std.Io and @Struct differ across releases.

When should I use static allocation versus arena allocators in Zig?▼

Use static allocation when memory needs are known at startup to eliminate OOM and latency spikes, as TigerBeetle does with its three-phase StaticAllocator. Use ArenaAllocator for temporary work and init.gpa as the top-level allocator in Zig 0.16, which is already leak-checking in Debug builds.