Asi zig-programming
git clone https://github.com/plurigrid/asi
T=$(mktemp -d) && git clone --depth=1 https://github.com/plurigrid/asi "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/zig-programming" ~/.claude/skills/plurigrid-asi-zig-programming-7bc053 && rm -rf "$T"
skills/zig-programming/SKILL.mdZig Programming Language Skill
This skill provides expertise in Zig, a general-purpose programming language focused on robustness, optimality, and maintainability. The skill includes version-specific documentation (0.2.0 through master), automatic version detection, code templates, and comprehensive reference materials organized for progressive disclosure.
Table of Contents
- Bundled Resources
- References - Progressive disclosure documentation
- Recipes - 223 tested recipes organized by topic
- Templates - Starting points for common tasks
- Examples - Practical code samples
- Scripts - Automation tools
- Workflows
- Version Awareness
- Best Practices
Bundled Resources
References - Progressive Loading Guide
Important: References are version-specific. Use
scripts/get_references.py to get the correct reference path for the detected Zig version, or load from references/latest/ (symlink to current stable: 0.15.2).
Load documentation progressively based on task complexity. Use this decision tree:
New to Zig? Start with fundamentals in order:
→ Basic syntax, types, operatorsreferences/latest/core-language.md
→ If, while, for, switchreferences/latest/control-flow.md
→ Functions and error handlingreferences/latest/functions-errors.md
→ Syntax quick lookupreferences/latest/quick-reference.md
Solving specific problems? Jump directly to:
- Error handling →
+latest/functions-errors.mdlatest/patterns-error-testing.md - Memory/allocators →
+latest/memory-management.mdlatest/patterns-memory-comptime.md - Data structures →
,latest/arrays-slices.md
,latest/structs-methods.md
,latest/enums-unions.mdlatest/pointers-references.md - Struct/array/enum patterns →
latest/patterns-data-structures.md - Stdlib lookup → grep
(large file, 68KB)latest/stdlib-builtins.md - C interop →
+latest/c-interop.mdlatest/patterns-integration.md - Build system →
+latest/build-system.mdlatest/patterns-integration.md
Advanced topics (after mastering fundamentals):
- Compile-time execution and genericsreferences/latest/comptime.md
- Advanced memory and comptime patternsreferences/latest/patterns-memory-comptime.md
- Testing framework and best practicesreferences/latest/testing-quality.md
Version migration →
references/version-differences.md (shared across versions, comprehensive migration guides)
Using version-specific references:
# Get reference path for detected version python scripts/get_references.py # Output: references/v0.15.2 # With specific version python scripts/get_references.py --version 0.13.0 # Output: references/v0.15.2 (with fallback warning) # JSON output for programmatic use python scripts/get_references.py --json
Recipes - Cookbook
The skill includes 223 tested recipes from the Zig BBQ Cookbook, organized by topic. All recipes include complete, compilable code verified against Zig 0.15.2.
Finding recipes by topic:
- Philosophy, basics (19 recipes)recipes/fundamentals.md
- Arrays, hashmaps, sets (20 recipes)recipes/data-structures.md
- String processing (14 recipes)recipes/strings-text.md
- Allocator patterns (6 recipes)recipes/memory-allocators.md
- Compile-time (24 recipes)recipes/comptime-metaprogramming.md
- Structs, unions (22 recipes)recipes/structs-objects.md
- Function patterns (11 recipes)recipes/functions.md
- File operations (19 recipes)recipes/files-io.md
- HTTP, sockets (18 recipes)recipes/networking.md
- Threading, atomics (8 recipes)recipes/concurrency.md
- Build.zig, modules (18 recipes)recipes/build-system.md
- Testing (14 recipes)recipes/testing-debugging.md
- C FFI (7 recipes)recipes/c-interop.md
- JSON, CSV, XML (9 recipes)recipes/data-encoding.md
- Iterator patterns (8 recipes)recipes/iterators.md
- WASM targets (6 recipes)recipes/webassembly.md
Querying recipes programmatically:
# List all topics with counts python scripts/query_recipes.py --list-topics # Find recipes by topic python scripts/query_recipes.py --topic memory-allocators # Find recipes by tag python scripts/query_recipes.py --tag hashmap # Search by keyword python scripts/query_recipes.py --search "error handling" # Get specific recipe details python scripts/query_recipes.py --recipe 1.1 # Filter by difficulty python scripts/query_recipes.py --difficulty beginner # JSON output for programmatic use python scripts/query_recipes.py --topic data-structures --json
Recipe format: Each recipe includes Problem, Solution, Discussion sections plus full tested code.
When to use recipes vs references:
- Recipes: "How do I..." questions, practical tasks, working code examples
- References: "What is..." questions, API lookup, comprehensive documentation
Templates
Copy and customize these starting points:
- Basic program with allocatorassets/templates/basic-program.zig
- Build configurationassets/templates/build.zig
- Test file structureassets/templates/test.zig
- CLI app with arg parsingassets/templates/cli-application.zig
- Library/module structureassets/templates/library-module.zig
- C interop moduleassets/templates/c-interop-module.zig
Examples
Complete, runnable code demonstrating patterns:
- String processingexamples/string_manipulation.zig
- Allocator patternsexamples/memory_management.zig
- Error handlingexamples/error_handling.zig
- C FFIexamples/c_interop.zig
- Compile-time programmingexamples/comptime_example.zig
- Multi-file projectexamples/build_example/
Scripts
Use these Python automation tools for version management, recipe queries, and code generation:
Version Detection & Reference Loading:
- Detect user's Zig version and return correct reference path (use this first)scripts/get_references.py
- Standalone version detection with confidence levelsscripts/detect_version.py
Recipe Queries:
- Search and filter recipes by topic, tag, difficulty, or keywordscripts/query_recipes.py
Code Generation:
- Generate Zig code from JSON specificationsscripts/code_generator.py
When to execute vs reference:
- Execute
at the start of any Zig task to determine the correct reference pathget_references.py - Execute
when searching for practical code examples or solutionsquery_recipes.py - Reference other scripts only when the user explicitly requests code generation or version management tasks
- Most scripts are for skill maintenance, not routine usage
See
scripts/README.md for complete script documentation.
Workflows
Writing New Code
- Start from template - Copy appropriate template from
assets/templates/ - Check version - Default to Zig 0.15.2 unless specified
- Handle errors explicitly - Use
,try
, orcatcherrdefer - Pass allocators - Never use global state, pass allocators as parameters
- Add tests immediately - Write
blocks alongside implementationtest - Document public APIs - Use
doc comments for exported functions///
Debugging Compilation Errors
Zig-specific gotchas:
- Comptime type resolution → Use
inspection or add explicit casts@TypeOf() - Allocator lifetime issues → Verify
cleanup order anddefer
on error pathserrdefer - Optional unwrapping → Use
only when certain; prefer.?
ororelse
unwrap for safetyif
Debug tools:
std.debug.print() for inspection, -Doptimize=Debug for stack traces, zig test to isolate issues
Explaining Concepts
To teach Zig concepts effectively:
- Load relevant reference - Start with the appropriate reference file for the topic
- Show runnable code - Use complete examples from
directoryexamples/ - Highlight uniqueness - Emphasize Zig's distinguishing features (explicit allocators, comptime, no hidden control flow)
- Reference stdlib - Point to specific standard library functions when applicable
Version Awareness
Default to Zig 0.15.2 unless user specifies otherwise or detection determines a different version.
Version Detection Workflow
At the start of any Zig task, determine the user's version using this workflow:
1. Check for explicit specification:
- User stated version in current conversation ("I'm using Zig 0.13")
- CLAUDE.md project file contains Zig version specification
hasbuild.zig.zon
fieldminimum_zig_version
2. Automated detection (recommended):
# Run get_references.py to detect version and get correct reference path python scripts/get_references.py --json
This script:
- Runs
to analyze the projectscripts/detect_version.py - Attempts
command (most reliable)zig version - Scans
andbuild.zig
files for version markers.zig - Returns reference path and version info with confidence level
- Handles fallbacks automatically (e.g., 0.14.1 → use 0.15.2 refs)
3. Manual detection (if automated fails):
- Scan
for API patterns:build.zig
→ 0.11+b.path(...)
→ 0.11+std.Build
→ 0.11+b.addExecutable(.{...})
→ pre-0.11b.addExecutable("name", "file")
- Check
files for syntax markers:.zig
→ 0.13+for (items, 0..) |item, i|
/async
keywords → 0.9-0.10 (removed in 0.11)await
- Load
for full detection markersreferences/version-differences.md
4. Ask user if ambiguous:
- "I detected you might be using Zig 0.13+ based on your build.zig. Can you confirm your version?"
- Offer common versions: 0.15.2 (stable), 0.14.1, 0.13.0, master (development)
5. Default to 0.15.2:
- Use current stable if no detection succeeds
- Inform user: "Assuming Zig 0.15.2. Let me know if you're using a different version."
Loading Version-Specific References
After detecting version:
- Use
to determine correct reference pathscripts/get_references.py - Load references from that version directory (e.g.,
)references/v0.15.2/ - Always load
(shared file) for migration guidancereferences/version-differences.md
Example workflow:
# Detect version and get reference path REF_PATH=$(python scripts/get_references.py) # REF_PATH is now "references/v0.15.2" or "references/latest" # Load version-specific documentation cat $REF_PATH/core-language.md cat $REF_PATH/build-system.md # Version differences is shared across all versions cat references/version-differences.md
Handling fallbacks:
- If exact version not available (e.g., 0.14.1), script returns closest match (0.15.2) with warning
- Warnings indicate major differences (e.g., "for loop syntax differs from 0.13+")
- Always check fallback warnings to understand version compatibility
Critical Breaking Changes
Be aware of these major version differences when writing code:
- 0.11+: Async/await removed, new build.zig API (
,std.Build
)b.path() - 0.13+: Modern for loop syntax (
)for (items, 0..) |item, i| - 0.12-: Different for loop syntax (manual index variables)
- Pre-0.11: Legacy build API (
), different error setsstd.build.Builder
See
for:references/version-differences.md
- Detailed migration guides (0.10→0.11, 0.12→0.13, 0.13→0.15)
- Error message translations
- Before/after code examples
- Breaking changes catalog
Handling Different Versions
When user specifies or detection determines a different version:
- Run
to get correct reference pathscripts/get_references.py --version <VERSION> - Load
for migration detailsreferences/version-differences.md - Use version-specific references from the returned path
- Adapt code patterns to the user's version
- Flag deprecated features if using older version
- Recommend modern alternatives when possible
Best practice for cross-version code:
- Prefer feature detection over version checks:
instead of@hasDecl(std, "Build")if (version >= 0.11) - See
forreferences/latest/patterns-integration.md
/@hasDecl
examples@hasField - Document target version in code comments:
// Target Zig Version: 0.15.2 - For cross-version templates, see
assets/templates/cross-version/
Best Practices
Core Zig idioms:
- Explicit error handling - Use
,try
, or error unions; never ignore errorscatch - Defer cleanup - Use
for cleanup,defer
for error-path cleanuperrdefer - Pass allocators - Never use global state; pass allocators explicitly as parameters
- Leverage comptime - Use compile-time execution for generic programming
- Write tests inline - Use
blocks alongside implementationtest "description" {} - Document public APIs - Add
doc comments for exported functions/// - Handle optionals explicitly - Use
,orelse
, or.?
unwrappingif - No hidden control flow - Zig has no hidden allocations, exceptions, or async