Metal AI Skill
Claude Code skill for Metal GPU debugging and profiling on macOS
Ask AI about Metal AI Skill
Powered by Claude Β· Grounded in docs
I know everything about Metal AI Skill. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
metal-ai-skill
A Claude Code skill for GPU debugging and profiling on Apple's Metal ecosystem.
This is the Metal counterpart to renderdoc-skill. While renderdoc-skill provides GPU debugging for Vulkan/D3D/GL via RenderDoc's rdc-cli, metal-ai-skill provides GPU profiling, validation, and shader analysis for Metal apps on macOS via Apple's native toolchain.
What It Does
Teaches Claude Code how to:
- Profile Metal GPU performance using
xctrace(Metal System Trace) on macOS and iOS devices - Export GPU profiling data as parseable XML (driver events, counters, timelines)
- Validate Metal API usage and shader execution with validation layers
- Monitor real-time GPU performance via Metal Performance HUD
- Compile and validate Metal shaders from the command line
- Capture Metal frames to
.gputracefor Xcode debugging - Debug Vulkan apps on macOS via MoltenVK
Quick Setup
1. Prerequisites
- macOS with Metal-capable GPU (Apple Silicon or AMD)
- Full Xcode installed (not just Command Line Tools)
- For Vulkan apps: MoltenVK
- For iOS profiling: physical device connected via USB, device trusted
Verify your setup:
xcode-select -p # Should show Xcode.app path
xcrun xctrace version # Should print version
xcrun -sdk macosx metal --version # Should print Metal compiler version
2. Install the Skill
Copy the .claude/ directory into your project root:
# Clone
git clone https://github.com/rudybear/metal-ai-skill.git
# Copy skill into your project
cp -r metal-ai-skill/.claude /path/to/your/project/
Or add as a git submodule:
cd /path/to/your/project
git submodule add https://github.com/rudybear/metal-ai-skill.git .metal-ai
cp -r .metal-ai/.claude .
3. Customize CLAUDE.md
Edit CLAUDE.md in your project root with your app-specific details (executable path, shader locations, debug markers).
MCP Server (Alternative)
Instead of the Claude Code skill, you can use the MCP server for structured tool access:
pip install -r requirements-mcp.txt
claude mcp add metal-tools -- python /path/to/metal-ai-skill/mcp_server/server.py
This registers 9 tools (metal_doctor, metal_trace, metal_parse_trace, metal_capture, metal_shader, metal_validate, metal_hud, metal_screenshot, metal_command), 2 resources (metal://traces, metal://captures), and 7 debugging prompts.
Usage
Once installed, Claude Code will automatically use this skill when you ask about Metal GPU debugging. Example prompts:
- "Profile my Metal app for 10 seconds and show me what's slow"
- "Check this shader for compilation errors"
- "Run my app with Metal validation and show me any API errors"
- "Capture a frame of my Vulkan app on macOS for debugging"
- "Compare GPU performance before and after my shader change"
- "Monitor real-time FPS and GPU time while I test"
Architecture
metal-ai-skill/
βββ .claude/
β βββ skills/
β βββ metal-gpu-debug/
β βββ SKILL.md # Main skill definition
β βββ references/
β βββ xctrace-quick-ref.md # xctrace command reference
β βββ debugging-recipes.md # Extended debugging workflows
βββ mcp_server/ # MCP server (alternative integration)
β βββ __init__.py
β βββ server.py # FastMCP server β 9 tools, 2 resources, 7 prompts
β βββ metal_runner.py # Async subprocess wrapper
β βββ recipes.py # Debugging recipe strings for prompts
βββ examples/
β βββ buggy-renderer/ # 10-bug compute shader demo
β β βββ main.swift # Headless particle simulation
β β βββ Shaders.metal # 5 shader bugs + 5 host bugs
β β βββ build_and_run.sh
β βββ visual-demo/ # 4-bug rendering demo
β βββ main.swift # Windowed cube renderer with geometry bug
β βββ Shaders.metal # 3 shader bugs (BGR, Y-flip, alpha=0)
β βββ build_and_run.sh
βββ CLAUDE.md # Project context for Claude Code
βββ capture_frame.swift # Example: programmatic frame capture
βββ parse_trace.py # Parse xctrace XML exports to TSV/JSON/CSV
βββ parse_gputrace.py # Inspect .gputrace buffer/texture data from CLI
βββ requirements-mcp.txt # MCP server dependencies
βββ LICENSE
βββ README.md
Key Differences from renderdoc-skill
| Feature | renderdoc-skill | metal-ai-skill |
|---|---|---|
| Primary tool | rdc-cli (66 commands) | xctrace + env vars + xcrun metal |
| APIs | Vulkan, D3D11/12, OpenGL | Metal (+ Vulkan via MoltenVK) |
| Platform | Windows, Linux, Android | macOS, iOS/iPadOS (via USB) |
| Capture format | .rdc (full CLI access) | .gputrace (Xcode GUI + CLI buffer inspection) |
| CLI inspection | Full (draws, pipeline, pixels, shaders) | Profiling + validation + buffer data (via labels) |
| Shader debugging | Step-through from CLI | Compile-time validation only (runtime in Xcode) |
| GPU profiling | GPU counters (limited) | Full xctrace + Metal Counters API |
| Validation | API validation flag | API + Shader validation layers |
| Performance HUD | N/A | Built-in MTL_HUD_ENABLED |
The fundamental difference: RenderDoc gives you full post-mortem capture inspection from CLI. Metal's tooling splits between CLI (profiling, validation, shader compilation) and Xcode GUI (draw call stepping, shader debugging, pixel history). This skill uses an autonomous debugging workflow that gathers signal from multiple sources in parallel (screenshots, .gputrace, shader compilation, source code) and falls back gracefully when buffer data isn't available from programmatic captures.
Examples
Profile GPU performance
# Claude Code will run:
xcrun xctrace record --template 'Metal System Trace' --time-limit 10s \
--output traces/profile.trace --launch -- ./MyApp
xcrun xctrace export --input traces/profile.trace --toc
xcrun xctrace export --input traces/profile.trace --output traces/analysis/events.xml \
--xpath '/trace-toc/run[@number="1"]/data/table[@schema="metal-driver-event-intervals"]'
Validate Metal API usage
# Claude Code will run:
MTL_DEBUG_LAYER=1 MTL_SHADER_VALIDATION=1 ./MyApp 2>&1 | tee validation.log
Compile and check shaders
# Claude Code will run:
xcrun -sdk macosx metal -c -Weverything -Werror Shaders.metal -o /dev/null
Inspect buffer data from .gputrace captures
# Claude Code captures a frame, then reads buffer contents by label:
METAL_CAPTURE_ENABLED=1 ./MyApp
python3 parse_gputrace.py capture.gputrace
# Resources:
# MTLBuffer-10-0 491,520 bytes β Particle Buffer
# MTLBuffer-14-0 163,840 bytes β Color Output Buffer
python3 parse_gputrace.py capture.gputrace --buffer "Color Output" --layout float4 --index 100
# [100] (0.5909, 0.7278, 0.5450, 1.0000)
Visual Demo
The examples/visual-demo/ contains a broken Metal cube renderer with 4 intentional bugs that produce visibly wrong output. It demonstrates Claude Code's autonomous debugging workflow β screenshot, .gputrace capture, shader compilation, source code analysis, and fix/verify loop.
Before (buggy) β distorted geometry, flipped, wrong colors:

How Claude fixes it:
cd examples/visual-demo
./build_and_run.sh --screenshot # Render + save output.png
# Claude gathers signal in parallel:
# A. Reads output.png β sees distorted, wrong-colored cube
# B. Captures .gputrace β lists resources and shader functions
# C. Compiles shaders with -Weverything
# D. Reads source code (.metal + Swift)
# Claude diagnoses 4 bugs:
# Bug 1: Front face vertices collapsed to (0,0,s) instead of (s,s,s)
# Bug 2: Y axis flipped after MVP (out.position.y *= -1.0)
# Bug 3: R/B channels swapped in fragment shader
# Bug 4: Alpha multiplied by 0.0 (transparent)
# Claude fixes all 4, rebuilds, verifies output.png is correct
After (fixed) β properly oriented cube with correct face colors:

See also examples/buggy-renderer/ for a more complex 10-bug compute shader demo.
License
MIT β see LICENSE.
Related Projects
- renderdoc-skill β RenderDoc GPU debugging skill for Vulkan/D3D/GL
- RenderDoc β The underlying graphics debugger
- MoltenVK β Vulkan to Metal translation layer

