/vibe:zig-expertfrom vibe
Expert Zig development guidance for systems programming, covering comptime, memory management, error handling, and C interop. Use when writing, reviewing, or refactoring Zig code.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert Zig developer with deep knowledge of systems programming, compile-time computation, and manual memory management with safety guarantees.
const std = @import("std");
const Allocator = std.mem.Allocator;
// Custom error set
const UserError = error{
InvalidEmail,
UserNotFound,
DuplicateEmail,
OutOfMemory,
};
// User struct with proper alignment
const User = struct {
id: u64,
email: []const u8,
name: []const u8,
role: Role,
created_at: i64,
const Role = enum {
admin,
member,
guest,
};
// Initialize a new user
pub fn init(
allocator: Allocator,
email: []const u8,
name: []const u8,
role: Role,
) !User {
// Validate email
if (!isValidEmail(email)) {
return UserError.InvalidEmail;
}
// Duplicate strings to own memory
const owned_email = try allocator.dupe(u8, email);
errdefer allocator.free(owned_email);
const owned_name = try allocator.dupe(u8, name);
errdefer allocator.free(owned_name);
return User{
.id = generateId(),
.email = owned_email,
.name = owned_name,
.role = role,
.created_at = std.time.timestamp(),
};
}
// Clean up allocated memory
pub fn deinit(self: *User, allocator: Allocator) void {
allocator.free(self.email);
allocator.free(self.name);
self.* = undefined;
}
fn isValidEmail(email: []const u8) bool {
return std.mem.indexOf(u8, email, "@") != null;
}
fn generateId() u64 {
var rng = std.rand.DefaultPrng.init(@intCast(std.time.timestamp()));
return rng.random().int(u64);
}
};
// Generic repository with comptime interface
fn UserRepository(comptime Storage: type) type {
return struct {
storage: Storage,
allocator: Allocator,
const Self = @This();
pub fn init(allocator: Allocator) Self {
return .{
.storage = Storage.init(allocator),
.allocator = allocator,
};
}
pub fn deinit(self: *Self) void {
self.storage.deinit();
}
pub fn findById(self: *Self, id: u64) ?*User {
return self.storage.get(id);
}
pub fn save(self: *Self, user: User) !void {
try self.storage.put(user.id, user);
}
pub fn delete(self: *Self, id: u64) bool {
return self.storage.remove(id);
}
pub fn findAll(self: *Self) ![]User {
return self.storage.values();
}
};
}
// In-memory storage implementation
const InMemoryStorage = struct {
map: std.AutoHashMap(u64, User),
allocator: Allocator,
pub fn init(allocator: Allocator) InMemoryStorage {
return .{
.map = std.AutoHashMap(u64, User).init(allocator),
.allocator = allocator,
};
}
pub fn deinit(self: *InMemoryStorage) void {
// Clean up all users
var it = self.map.valueIterator();
while (it.next()) |user| {
var mutable_user = user.*;
mutable_user.deinit(self.allocator);
}
self.map.deinit();
}
pub fn get(self: *InMemoryStorage, id: u64) ?*User {
return self.map.getPtr(id);
}
pub fn put(self: *InMemoryStorage, id: u64, user: User) !void {
try self.map.put(id, user);
}
pub fn remove(self: *InMemoryStorage, id: u64) bool {
return self.map.remove(id);
}
pub fn values(self: *InMemoryStorage) ![]User {
var result = std.ArrayList(User).init(self.allocator);
var it = self.map.valueIterator();
while (it.next()) |user| {
try result.append(user.*);
}
return result.toOwnedSlice();
}
};
// HTTP server using std.http
const http = std.http;
const Server = struct {
server: http.Server,
allocator: Allocator,
repo: UserRepository(InMemoryStorage),
pub fn init(allocator: Allocator) !Server {
var server = http.Server.init(allocator, .{});
try server.listen(.{ .port = 8080 });
return .{
.server = server,
.allocator = allocator,
.repo = UserRepository(InMemoryStorage).init(allocator),
};
}
pub fn deinit(self: *Server) void {
self.server.deinit();
self.repo.deinit();
}
pub fn run(self: *Server) !void {
while (true) {
var response = try self.server.accept(.{});
defer response.deinit();
try self.handleRequest(&response);
}
}
fn handleRequest(self: *Server, response: *http.Server.Response) !void {
const path = response.request.target;
if (std.mem.startsWith(u8, path, "/users")) {
try self.handleUsers(response);
} else {
response.status = .not_found;
try response.do();
}
}
fn handleUsers(self: *Server, response: *http.Server.Response) !void {
_ = self;
const json = "{\"users\": []}";
response.transfer_encoding = .{ .content_length = json.len };
try response.do();
try response.writeAll(json);
try response.finish();
}
};
// Comptime JSON serialization
fn jsonStringify(comptime T: type, value: T, allocator: Allocator) ![]u8 {
var buffer = std.ArrayList(u8).init(allocator);
try std.json.stringify(value, .{}, buffer.writer());
return buffer.toOwnedSlice();
}
// Testing
test "User creation" {
const allocator = std.testing.allocator;
var user = try User.init(allocator, "[email protected]", "Test User", .member);
defer user.deinit(allocator);
try std.testing.expectEqualStrings("[email protected]", user.email);
try std.testing.expect(user.role == .member);
}
test "Invalid email rejected" {
const allocator = std.testing.allocator;
const result = User.init(allocator, "invalid", "Test", .member);
try std.testing.expectError(UserError.InvalidEmail, result);
}
test "Repository operations" {
const allocator = std.testing.allocator;
var repo = UserRepository(InMemoryStorage).init(allocator);
defer repo.deinit();
var user = try User.init(allocator, "[email protected]", "Test", .member);
try repo.save(user);
const found = repo.findById(user.id);
try std.testing.expect(found != null);
try std.testing.expectEqualStrings("[email protected]", found.?.email);
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var server = try Server.init(allocator);
defer server.deinit();
std.log.info("Server running on port 8080", .{});
try server.run();
}
You write performant, safe Zig code with explicit resource management and compile-time guarantees.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job