Skip to content

Add CLAUDE.md coding standards for gold-standard Zig#47

Open
koko1123 wants to merge 1 commit intomainfrom
claude-md
Open

Add CLAUDE.md coding standards for gold-standard Zig#47
koko1123 wants to merge 1 commit intomainfrom
claude-md

Conversation

@koko1123
Copy link
Contributor

@koko1123 koko1123 commented Mar 13, 2026

Summary

  • Adds comprehensive CLAUDE.md encoding eth.zig's coding standards: 10-layer architecture, naming conventions, comptime discipline, memory management, error handling, testing, performance, crypto safety
  • Documents known LLVM aarch64 traps (@intFromFloat/@floatFromInt with u256, u512 division) with workarounds
  • Establishes hard rules: no external deps, no emojis, no layer violations, no hidden allocations, never push to main

Test plan

  • make ci passes (build + fmt + test)
  • Review CLAUDE.md for accuracy against actual codebase patterns

Summary by CodeRabbit

  • Documentation
    • Added comprehensive architecture and development guidelines for the Ethereum client library, including design standards, coding conventions, and best practices.

Codifies eth.zig's architecture (10-layer dependency hierarchy),
naming conventions, comptime discipline, memory management, crypto
safety patterns, and known LLVM aarch64 traps so that contributors
and AI assistants produce idiomatic, high-quality Zig code.
@vercel
Copy link

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eth-zig Ready Ready Preview, Comment Mar 13, 2026 8:33pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

A new documentation file eth.zig is added, defining the architecture, coding standards, and development guidelines for a Pure Zig Ethereum client library. The document outlines layered architecture patterns, Zig style conventions, memory management, error handling, testing practices, cryptographic safety, and project rules. No functional code implementation is present.

Changes

Cohort / File(s) Summary
Zig Ethereum Client Library Design Documentation
eth.zig
New comprehensive design and coding standards document (302 lines) covering architecture layers, naming and formatting conventions, struct organization, comptime discipline, memory management contracts, error propagation, testing guidance, performance practices, cryptographic safety, and project rules for the Ethereum client library.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A carrot of code in Zig so bright,
Ethereum's path now defined just right,
With layers of guidance, safe and sound,
This library's blueprint is solid, I've found!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add CLAUDE.md coding standards for gold-standard Zig' accurately describes the main change: adding a new documentation file that establishes coding standards for the Zig Ethereum client library.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude-md
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
CLAUDE.md (1)

21-51: Add language specifier to fenced code block.

The architecture diagram is in a fenced code block without a language specifier. Add ```text to improve rendering and satisfy linters.

📝 Proposed fix
-```
+```text
 Layer 1:  Primitives     (zero deps, no allocator needed)
           primitives.zig, uint256.zig, hex.zig
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CLAUDE.md` around lines 21 - 51, Change the fenced code block that begins
with "Layer 1:  Primitives     (zero deps, no allocator needed)" to include a
language specifier by replacing the opening ``` with ```text so the architecture
diagram renders as plain text and satisfies linters; the change should be made
around the triple-backtick block containing the Layer 1..Layer 10 diagram.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CLAUDE.md`:
- Line 15: The line "Do NOT use Zig 0.16.0-dev (breaks std.Thread.Mutex)" is
misleading—update that sentence to clarify that the problem is not a stdlib bug
but unsafe user code patterns: change it to state that Zig 0.16.x may trigger
runtime safety checks when user code copies or moves structs containing
std.Thread.Mutex (e.g., storing mutex-containing values without stable
addresses), and recommend using Zig >= 0.15.2 or ensuring mutex-containing types
are not copied/moved (use pointers or arena allocation) instead of claiming the
stdlib is broken.

---

Nitpick comments:
In `@CLAUDE.md`:
- Around line 21-51: Change the fenced code block that begins with "Layer 1: 
Primitives     (zero deps, no allocator needed)" to include a language specifier
by replacing the opening ``` with ```text so the architecture diagram renders as
plain text and satisfies linters; the change should be made around the
triple-backtick block containing the Layer 1..Layer 10 diagram.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31d81086-9924-41e3-bc83-ceeb9d02d8ff

📥 Commits

Reviewing files that changed from the base of the PR and between d369bd0 and 5b11a20.

📒 Files selected for processing (1)
  • CLAUDE.md

make bench # full benchmark suite (ReleaseFast)
```

Requires Zig >= 0.15.2. Do NOT use Zig 0.16.0-dev (breaks std.Thread.Mutex).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

What is the latest stable version of Zig as of March 2026, and are there any known issues with std.Thread.Mutex in Zig 0.16.x?

💡 Result:

Latest stable Zig (as of March 2026)

The latest stable release is Zig 0.15.2 (the official download page lists zig-0.15.2.tar.xz under “Source”). [1]
Zig 0.16.x is not stable yet (it’s still in the 0.16.0 development/release cycle per the 2026 devlog). [2]

Known issues with std.Thread.Mutex in Zig 0.16.x

I couldn’t find a confirmed, general stdlib bug specific to std.Thread.Mutex in Zig 0.16.x. A commonly hit “looks-like-a-bug” failure is actually user code accidentally copying/moving a mutex-containing struct, which can trigger the runtime safety check panic/message like “unfair double lock” (e.g., storing mutex-containing values in a hash map that relocates/copies entries). The reported fix is to store pointers (stable addresses) rather than copying the struct containing the mutex. [3]

Sources: [1] Zig download page (stable version listing) • [2] Zig devlog 2026 (0.16 still in release cycle) • [3] Ziggit thread diagnosing “unfair double lock” caused by copying a mutex-containing struct


Clarify or correct the Zig 0.16.0-dev warning on line 15.

The warning "breaks std.Thread.Mutex" is misleading. Web search reveals no confirmed stdlib bug in std.Thread.Mutex for Zig 0.16.x. The actual issue reported is user code copying/moving structs containing mutexes, which triggers a runtime safety check—not a stdlib bug. Either remove the vague warning or clarify that the issue is a user-code pattern (storing mutex-containing values without stable addresses), not a stdlib defect.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CLAUDE.md` at line 15, The line "Do NOT use Zig 0.16.0-dev (breaks
std.Thread.Mutex)" is misleading—update that sentence to clarify that the
problem is not a stdlib bug but unsafe user code patterns: change it to state
that Zig 0.16.x may trigger runtime safety checks when user code copies or moves
structs containing std.Thread.Mutex (e.g., storing mutex-containing values
without stable addresses), and recommend using Zig >= 0.15.2 or ensuring
mutex-containing types are not copied/moved (use pointers or arena allocation)
instead of claiming the stdlib is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant