Memory Safety Patterns skill for Claude

Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C.

When Claude uses it

Use when writing safe systems code, managing resources, or preventing memory bugs.

Memory Safety Patterns SKILL.md

The full skill file from wshobson/agents (MIT).

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 TypeDescriptionPrevention
Use-after-freeAccess freed memoryOwnership, RAII
Double-freeFree same memory twiceSmart pointers
Memory leakNever free memoryRAII, GC
Buffer overflowWrite past buffer endBounds checking
Dangling pointerPointer to freed memoryLifetime tracking
Data raceConcurrent unsynchronized accessOwnership, 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

# 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

How to install Memory Safety Patterns

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit wshobson/agents/plugins/systems-programming/skills/memory-safety-patterns#main ~/.claude/skills/memory-safety-patterns

Codex

npx degit wshobson/agents/plugins/systems-programming/skills/memory-safety-patterns#main ~/.codex/skills/memory-safety-patterns

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Memory Safety Patterns skill do?

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.

+How do I install Memory Safety Patterns in Claude Code?

Copy the skill folder into ~/.claude/skills/memory-safety-patterns, for example with "npx degit wshobson/agents/plugins/systems-programming/skills/memory-safety-patterns#main ~/.claude/skills/memory-safety-patterns". Claude Code loads it automatically and uses it when a task matches.

+Does Memory Safety Patterns work with ChatGPT or Codex?

Yes. Memory Safety Patterns uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/memory-safety-patterns. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Memory Safety Patterns free?

Memory Safety Patterns is published on GitHub by wshobson under the MIT license, which allows free use.

Related ai agents & skills skills

  1. Grill Me

    A relentless interview to sharpen a plan or design.

    mattpocock/skills★ 327k
  2. Skill Creator

    Official

    Create new skills, modify and improve existing skills, and measure skill performance.

    anthropics/skills★ 197k
  3. Caveman

    Terse caveman voice: answer first, fluff gone, every technical fact kept.

    JuliusBrussee/caveman★ 121k
  4. Prompt Engineering Patterns

    This skill should be used when the user asks to "optimize a prompt", "improve prompt performance", "design a prompt template", "write…

    wshobson/agents★ 43k
  5. Protect Mcp Setup

    Configure Cedar policy enforcement and Ed25519 signed receipts for Claude Code tool calls.

    wshobson/agents★ 43k
  6. Rag Implementation

    Build Retrieval-Augmented Generation (RAG) systems for LLM applications with vector databases and semantic search.

    wshobson/agents★ 43k
  7. Saga Orchestration

    Implement saga patterns for distributed transactions and cross-aggregate workflows.

    wshobson/agents★ 43k
  8. Spark Memory Thermal Ops

    Manage unified memory and thermals during long-running ML jobs on NVIDIA DGX Spark.

    wshobson/agents★ 43k
  9. Superself

    Use when a project keeps its state in Superself (a `<!-- superself:begin` block in AGENTS.md or CLAUDE.md, or `self setup` resolves the…

    wshobson/agents★ 43k

See all ai agents & skills skills →

More skills from wshobson

  1. Microservices Patterns

    Design microservices architectures with service boundaries, event-driven communication, and resilience patterns.

    wshobson/agents★ 43k
  2. Ml Pipeline Workflow

    Build end-to-end MLOps pipelines from data preparation through model training, validation, and production deployment.

    wshobson/agents★ 43k
  3. Mobile Android Design

    Master Material Design 3 and Jetpack Compose patterns for building native Android apps.

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.