memory-safety-patterns — Claude Code skill: install guide
This skill applies ownership, RAII, smart pointers, and resource management to Rust, C++, and C. Use it for systems code or memory-bug debugging.
/plugin marketplace add wshobson/agents
/plugin install systems-programming@claude-code-workflowsWhat memory-safety-patterns does
memory-safety-patterns covers ownership, object lifetimes, smart pointers, and RAII across Rust, C++, and C. It helps agents reason about use-after-free, double-free errors, leaks, buffer overflows, dangling pointers, and data races. The guidance also compares manual memory control with safer ownership models.
Detailed patterns are stored in references/details.md. The skill includes commands for AddressSanitizer, Valgrind, Rust Miri, and ThreadSanitizer, so you can connect the advice to a concrete debugging pass. In C++, it recommends limiting raw pointers; in Rust, it calls for care with unsafe. Install it when resource lifetime is part of the task; it adds little for code with no memory-management concerns.
What it helps with
- stop use-after-free and double-free errors
- tie file, socket, and memory lifetimes to scope
- choose between manual control, smart pointers, and ownership
- check for buffer overflows and data races
- run AddressSanitizer, Valgrind, or Miri during debugging
Example prompts for the agent
- Review this C++ code for use-after-free and rewrite it with RAII.
- Compare resource ownership in these Rust and C modules.
- Prepare commands to check this program with AddressSanitizer and Valgrind.
How to install memory-safety-patterns
1Plugin marketplace
/plugin marketplace add wshobson/agents/plugin install systems-programming@claude-code-workflowsThis installs the whole systems-programming plugin with all its skills
2Skills CLI (Vercel)
npx skills add wshobson/agents --skill memory-safety-patterns -a claude-code3Manually: put the files in place
~/.claude/skills/memory-safety-patterns/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/memory-safety-patterns/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill memory-safety-patterns -a codex2Manually: put the files in place
.agents/skills/memory-safety-patterns/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill memory-safety-patterns -a cursor2Manually: put the files in place
.cursor/skills/memory-safety-patterns/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshobson/agents memory-safety-patterns2Manually: put the files in place
.github/skills/memory-safety-patterns/SKILL.mdPlatform CLI
gemini skills install https://github.com/wshobson/agents --path plugins/systems-programming/skills/memory-safety-patternsManually: put the files in place
.devin/skills/memory-safety-patterns/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set213
The whole set →Similar
Questions about memory-safety-patterns
How do I install memory-safety-patterns in Claude Code?
Run npx skills add wshobson/agents --skill memory-safety-patterns -a claude-code. The skill file is placed at ~/.claude/skills/memory-safety-patterns/SKILL.md.
What does memory-safety-patterns do?
It guides memory-safe programming with RAII, ownership, and smart pointers in Rust, C++, and C. It also covers ways to diagnose leaks, freed-memory access, and related bugs.
Which languages does memory-safety-patterns cover?
The skill covers Rust, C++, and C. Its debugging examples use AddressSanitizer, Valgrind, Rust Miri, and ThreadSanitizer.
Source text
SKILL.md · MIT
--- name: memory-safety-patterns description: Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs. --- # Memory Safety Patterns Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management. ## When to Use This Skill - Writing memory-safe systems code - Managing resources (files, sockets, memory) - Preventing use-after-free and leaks - Implementing RAII patterns - Choosing between languages for safety - Debugging memory issues ## Core Concepts ### 1. Memory Bug Categories | Bug Type | Description | Prevention | | -------------------- | -------------------------------- | ----------------- | | **Use-after-free** | Access freed memory | Ownership, RAII | | **Double-free** | Free same memory twice | Smart pointers | | **Memory leak** | Never free memory | RAII, GC | | **Buffer overflow** | Write past buffer end | Bounds checking | | **Dangling pointer** | Pointer to freed memory | Lifetime tracking | | **Data race** | Concurrent unsynchronized access | Ownership, Sync | ### 2. Safety Spectrum ``` Manual (C) → Smart Pointers (C++) → Ownership (Rust) → GC (Go, Java) Less safe More safe More control Less control ``` ## Detailed patterns and worked examples Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. ## Best Practices ### Do's - **Prefer RAII** - Tie resource lifetime to scope - **Use smart pointers** - Avoid raw pointers in C++ - **Understand ownership** - Know who owns what - **Check bounds** - Use safe access methods - **Use tools** - AddressSanitizer, Valgrind, Miri ### Don'ts - **Don't use raw pointers** - Unless interfacing with C - **Don't return local references** - Dangling pointer - **Don't ignore compiler warnings** - They catch bugs - **Don't use `unsafe` carelessly** - In Rust, minimize it - **Don't assume thread safety** - Be explicit ## Debugging Tools ```bash # AddressSanitizer (Clang/GCC) clang++ -fsanitize=address -g source.cpp # Valgrind valgrind --leak-check=full ./program # Rust Miri (undefined behavior detector) cargo +nightly miri run # ThreadSanitizer clang++ -fsanitize=thread -g source.cpp ```
© Seth Hobson · MIT · wshobson/agents