zapcode
CLAUDE.md92 starsChanged 9 months agoMITView on GitHub
AI coding assistant instructions for the zapcode project. See AGENTS.md for the full architecture reference. This file adds Claude-Code-specific guidance on top of it. Do not add Co-Authored-By trailers to git commits. Before writing any code in this repository, read AGENTS.md in full. It defines: - What Zapcode is and what it must never do - The full architecture (parser → IR → bytecode → VM → snapshot) - The five sandbox invariants that must never be violated - The…
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
18 rules. About 0 are common, 9 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 11
Do not add Co-Authored-By trailers to git commits.
- Distinctive: line 17
Before writing any code in this repository, read AGENTS.md in full.
- Distinctive: line 23
Do not skip this. The sandbox invariants in particular will save you from introducing security vulnerabilities that are hard to detect and …
- Distinctive: line 30
Start here when working on a new area:
- Very specific: line 48
When in doubt about where something belongs: zapcode-core is pure Rust with zero I/O.
- Distinctive: line 56
Check the supported subset table in AGENTS.md first: If the feature is explicitly listed as unsupported, do not add it without opening a …
- Very specific: line 71
Use push_call_frame() helper for any function call setup
- Distinctive: line 73
Write tests: before considering the feature done.
- Distinctive: line 75
Update JS, Python, and WASM bindings: if the feature affects the public API surface.
- Very specific: line 81
Before submitting any code to zapcode-core, verify:
- Very specific: line 90
If you are implementing an external function bridge: the bridge must validate that the function name exists in the registered set before …
- Distinctive: line 115
When walking the AST:
- Very specific: line 116
Use match exhaustively — never _ wildcard on statement or expression nodes.
- Very specific: line 119
Do not use oxc_transformer or oxc_semantic — they add weight we don't need.
- Very specific: line 147
Run benchmarks with cargo bench.
- Distinctive: line 154
Sandbox boundary question: if in doubt, block it.
- Very specific: line 155
API design question: follow @pydantic/monty's API shape.
- Distinctive: line 156
Performance vs correctness: always choose correctness.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
AI coding assistant instructions for the
zapcodeproject. See AGENTS.md for the full architecture reference. This file adds Claude-Code-specific guidance on top of it.
Git
Do not add Co-Authored-By trailers to git commits.
Read AGENTS.md first
Before writing any code in this repository, read AGENTS.md in full. It defines:
- What Zapcode is and what it must never do
- The full architecture (parser → IR → bytecode → VM → snapshot)
- The five sandbox invariants that must never be violated
- The definition of "done" for any feature
Do not skip this. The sandbox invariants in particular will save you from introducing security vulnerabilities that are hard to detect and easy to ship.
Codebase orientation
Start here when working on a new area:
| Area | Entry point |
| Parsing TypeScript | crates/zapcode-core/src/parser/mod.rs |
| IR definition | crates/zapcode-core/src/parser/ir.rs |
| Bytecode instructions | crates/zapcode-core/src/compiler/instruction.rs |
| Compiler (IR → bytecode) | crates/zapcode-core/src/compiler/mod.rs |
| VM main loop + dispatch | crates/zapcode-core/src/vm/mod.rs |
| Built-in functions | crates/zapcode-core/src/vm/builtins.rs |
| Value / type system | crates/zapcode-core/src/value.rs |
| Snapshot / resume | crates/zapcode-core/src/snapshot.rs |
| Resource limits | crates/zapcode-core/src/sandbox.rs |
| Error types | crates/zapcode-core/src/error.rs |
| JS bindings API | crates/zapcode-js/src/lib.rs |
| Python bindings API | crates/zapcode-py/src/lib.rs |
| WASM bindings API | crates/zapcode-wasm/src/lib.rs |
When in doubt about where something belongs: zapcode-core is pure Rust with zero I/O.
Bindings crates only translate types and marshal calls into zapcode-core. Never put
business logic in binding crates.
How to add a new language feature
- Check the supported subset table in AGENTS.md first. If the feature is explicitly listed as unsupported, do not add it without opening a discussion. Features are excluded intentionally.
- Add parser support in
crates/zapcode-core/src/parser/. The parser walks theoxcAST and emitsZapcodeIR. Unsupported nodes must emitZapcodeError::UnsupportedSyntaxwith the node's span information. - Add compiler support in
crates/zapcode-core/src/compiler/. The compiler lowersZapcodeIRto bytecode instructions. Add newInstructionvariants only when necessary — prefer reusing existing instructions. - Add VM dispatch in
crates/zapcode-core/src/vm/mod.rs. The maindispatch()function matches onInstruction. Every new instruction needs:- Correct stack discipline (verify push/pop balance)
- Resource limit check before any allocation
- Use
push_call_frame()helper for any function call setup
- Write tests before considering the feature done. See AGENTS.md testing philosophy.
- Update JS, Python, and WASM bindings if the feature affects the public API surface.
Sandbox invariant checklist
Before submitting any code to zapcode-core, verify:
- No
std::fs::*usage - No
std::env::*usage - No
std::net::*ortokio::net::*usage - No
unsafeblock without a// SAFETY:comment - No way for guest code to call any function not in the registered
externalFunctionsmap - No way for guest code to read or write to any memory outside the VM
If you are implementing an external function bridge: the bridge must validate that the
function name exists in the registered set before suspending. An unregistered name must
produce ZapcodeError::UnknownExternalFunction, not a panic or a silent no-op.
oxc usage patterns
Zapcode uses oxc_parser for parsing and oxc_ast for AST traversal:
use oxc_parser::{Parser, ParserReturn};
use oxc_span::SourceType;
use oxc_allocator::Allocator;
// Always use SourceType::tsx() — it handles both TS and TSX
let allocator = Allocator::default();
let source_type = SourceType::tsx();
let ret: ParserReturn = Parser::new(&allocator, source, source_type).parse();
if !ret.errors.is_empty() {
return Err(ZapcodeError::ParseError(format_oxc_errors(&ret.errors, source)));
}When walking the AST:
- Use
matchexhaustively — never_wildcard on statement or expression nodes. An unhandled node should produceZapcodeError::UnsupportedSyntax, not be silently ignored. - Preserve span information in IR nodes for error messages.
- Do not use
oxc_transformeroroxc_semantic— they add weight we don't need.
Async / await implementation notes
Key invariants:
The VM is single-threaded. There is no Tokio runtime inside the VM.
await on a host function suspends the VM and returns VmState::Suspended. The caller
resolves the function externally and calls resume().
await on an internal Promise (e.g., Promise.resolve(42)) is handled entirely
inside the VM without suspending.
Do not try to integrate tokio::spawn or async_std into the VM executor.
Performance targets
| Metric | Target |
| First execution latency (simple expression) | < 5 µs |
| Snapshot size (typical agent code) | < 2 KB |
| Snapshot + resume round-trip | < 2 ms |
Run benchmarks with cargo bench. The benchmark suite is in crates/zapcode-core/benches/.
What to do when you're unsure
- Unsupported syntax: emit
ZapcodeError::UnsupportedSyntaxwith the span. Do not silently skip. - Sandbox boundary question: if in doubt, block it.
- API design question: follow
@pydantic/monty's API shape. - Performance vs correctness: always choose correctness.
Quick reference: public API
Rust
use zapcode_core::{ZapcodeRun, Value, ResourceLimits, VmState, ZapcodeSnapshot};
let runner = ZapcodeRun::new(
code.to_string(),
vec!["url".to_string()],
vec!["fetch".to_string()],
ResourceLimits::default(),
)?;
// Start — pauses at first external call
let state = runner.start(vec![
("url".to_string(), Value::String("https://...".into())),
])?;
match state {
VmState::Suspended { function_name, args, snapshot } => {
let bytes = snapshot.dump()?;
let restored = ZapcodeSnapshot::load(&bytes)?;
let final_state = restored.resume(Value::String("result".into()))?;
}
VmState::Complete(value) => println!("Result: {:?}", value),
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

