Agent skill
mojo-memory-check
Verify memory safety in Mojo code including ownership, borrowing, and lifetime management. Use when reviewing code or debugging memory issues.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/mojo-memory-check
SKILL.md
Memory Safety Check Skill
Validate Mojo ownership and borrowing rules.
When to Use
- Reviewing code for memory safety
- Debugging memory or segfault issues
- Before merging code
- Performance testing reveals corruption
Quick Reference
# Owned parameter - takes ownership
fn consume(var data: Tensor):
process(data) # data moved here
# Borrowed parameter - read-only reference
fn read_only(data: Tensor):
let value = data[0] # OK: read-only
# Mutable reference - in-place modification
fn modify(mut data: Tensor):
data[0] = 42 # Mutate in caller's variable
Workflow
- Trace ownership - Which function owns each value
- Check borrows - Are references short-lived
- Verify moves - Use
^operator for ownership transfer - Test lifetimes - Compile and run with memory checks
- Debug issues - Identify use-after-move or dangling refs
Mojo-Specific Notes
- Use
^operator ONLY when transferring ownership mut selffor mutating methods (NOTout self)out selfONLY for constructors (__init__)- List/Dict/String are non-copyable - must use
^when returning
Error Handling
| Error | Cause | Solution |
|---|---|---|
Use after move |
Variable used after ownership transfer | Create copy or don't move |
Dangling reference |
Reference to local variable | Return owned value with ^ |
Mutable aliasing |
Multiple mutable refs to same data | Ensure single mutable reference |
Type not copyable |
Missing ^ on non-copyable return |
Add transfer operator ^ |
References
.claude/shared/mojo-anti-patterns.md- Ownership violations section.claude/shared/mojo-guidelines.md- Parameter conventions table
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?