Claude Code for Mojo Language — Workflow Guide
The Setup
You are writing high-performance code with Mojo, the programming language from Modular that combines Python syntax with systems-level performance. Mojo is designed for AI/ML workloads, providing C/C++-level speed while being a superset of Python. Claude Code can write Python, but it generates standard CPython code instead of leveraging Mojo’s performance features.
What Claude Code Gets Wrong By Default
-
Writes pure Python without Mojo types. Claude uses
defand dynamic Python types. Mojo hasfnfor strict functions with typed parameters,structinstead ofclassfor value semantics, andvar/letfor variable declarations with mandatory types. -
Uses Python data structures for performance code. Claude creates
listanddictfor numerical computation. Mojo hasSIMD,Tensor, andBuffertypes for hardware-optimized data structures that map directly to CPU/GPU registers. -
Ignores ownership and borrowing. Claude passes objects freely without considering memory. Mojo has an ownership model with
owned,borrowed, andinoutparameter conventions — these control memory safety and enable zero-copy operations. -
Does not use SIMD vectorization. Claude writes scalar loops for numerical operations. Mojo has first-class SIMD support:
SIMD[DType.float32, 8]processes 8 float32 values in a single instruction.
The CLAUDE.md Configuration
# Mojo Project
## Language
- Language: Mojo (Python superset with systems performance)
- Compiler: Mojo compiler (AOT compilation)
- Interop: Full Python interoperability
- Target: AI/ML and high-performance computing
## Mojo Rules
- fn: strict typed functions (preferred for performance)
- def: Python-compatible dynamic functions
- struct: value types (not class) for performance
- var: mutable variable, let: immutable binding
- SIMD: vectorized operations with SIMD[type, width]
- Ownership: owned, borrowed, inout parameters
- Traits: similar to Rust traits for polymorphism
## Conventions
- Use fn over def for performance-critical code
- struct for data types, not class
- Explicit types on all fn parameters and returns
- Use SIMD for numerical loops
- @parameter for compile-time parameters
- Use Python interop for libraries not yet in Mojo
- Profile with mojo build --profile flag
Workflow Example
You want to optimize a matrix multiplication kernel. Prompt Claude Code:
“Write a high-performance matrix multiplication in Mojo. Use SIMD vectorization, tiling for cache efficiency, and parallelize across cores. Compare the approach with a naive Python implementation to show the performance difference.”
Claude Code should create a fn matmul with typed Tensor parameters, implement tiling with compile-time @parameter for tile size, use SIMD for the inner loop vectorization, add @parallelize for multi-core execution, and include a Python comparison function using def with numpy for benchmarking.
Common Pitfalls
-
Using
defeverywhere instead offn. Claude writesdeffunctions out of Python habit. Mojo’sfnenforces strict typing and enables compiler optimizations —defis for Python compatibility,fnis for performance. -
Missing type annotations on struct fields. Claude defines struct fields without types. Mojo structs require explicit types for every field — the compiler cannot infer struct field types like Python class attributes.
-
Forgetting Python interop imports. Claude tries to use Python libraries directly in Mojo. Python libraries must be imported through
from python import Pythonand called viaPython.import_module("numpy")— direct imports only work for Mojo-native packages.