A CLI toolset for building and capturing SwiftUI previews programmatically. Designed to work with Claude Code for visual analysis of UI components.
- Dynamic Preview Injection - Creates minimal PreviewHost targets instead of building full apps
- SPM Package Support - Works with standalone Swift packages
- Xcode Project Support - Works with xcodeproj files (including Tuist-generated projects)
- Fast Builds - Only builds required modules (~3-4 seconds for cached builds)
- Resource Bundle Detection - Automatically includes asset bundles for themes/colors
- macOS with Xcode installed
- iOS Simulator
- Ruby (comes with macOS) with
xcodeprojgem
Install via the Claude Code plugin marketplace:
/plugin marketplace add Iron-Ham/Claude-XcodePreviews
/plugin install preview-build@Claude-XcodePreviews
Then install the Ruby dependency:
gem install xcodeproj --user-installIf you prefer a manual setup:
git clone https://github.com/Iron-Ham/Claude-XcodePreviews.gitgem install xcodeproj --user-installCopy the skill definition to your user-level commands directory:
mkdir -p ~/.claude/commands
cp Claude-XcodePreviews/.claude/commands/preview.md ~/.claude/commands/Note: The manual install expects scripts at
~/Claude-XcodePreviews. If you cloned to a different location, create a symlink:ln -s /path/to/Claude-XcodePreviews ~/Claude-XcodePreviews
The preview script auto-detects the best approach:
# Preview a file in an Xcode project
./scripts/preview path/to/MyView.swift
# Preview a file in an SPM package
./scripts/preview path/to/Package/Sources/Module/MyView.swift
# Specify output path
./scripts/preview MyView.swift --output ~/Desktop/preview.png
# Capture current simulator
./scripts/preview --capture-onlyFor Xcode projects with #Preview blocks:
./scripts/preview-dynamic.sh MyView.swift --project MyApp.xcodeprojFor SPM packages:
./scripts/preview-spm.sh MyView.swift --package /path/to/Package.swiftFor standalone Swift files (system imports only):
./scripts/preview-minimal.sh MyView.swift| Option | Description |
|---|---|
--project <path> |
Xcode project file |
--workspace <path> |
Xcode workspace file |
--package <path> |
SPM Package.swift path |
--module <name> |
Target module (auto-detected) |
--simulator <name> |
Simulator name (default: iPhone 17 Pro) |
--output <path> |
Output screenshot path |
--verbose |
Show detailed build output |
--keep |
Keep temporary files after capture |
- Parses the Swift file to extract
#Preview { }content - Injects a temporary
PreviewHosttarget into the project - Configures dependencies based on imports
- Builds only the required modules
- Launches in simulator and captures screenshot
- Cleans up the injected target
- Creates a temporary Xcode project
- Adds the local SPM package as a dependency
- Generates a PreviewHost app with the preview content
- Builds and captures screenshot
After installation, use the /preview command in Claude Code:
/preview path/to/MyView.swift
Claude will:
- Build the preview using the appropriate method
- Capture a screenshot
- Analyze and describe the visual output
| Script | Purpose |
|---|---|
preview |
Unified entry point |
preview-dynamic.sh |
Xcode project preview injection |
preview-spm.sh |
SPM package preview |
preview-minimal.sh |
Standalone files |
capture-simulator.sh |
Screenshot capture |
sim-manager.sh |
Simulator utilities |
Claude-XcodePreviews/
├── .claude-plugin/
│ ├── marketplace.json # Plugin marketplace catalog
│ └── plugin.json # Plugin manifest
├── .claude/
│ ├── commands/
│ │ └── preview.md # Slash command (manual install)
│ └── settings.json # Project permissions
├── skills/
│ └── preview/
│ └── SKILL.md # Plugin skill definition
├── scripts/
│ ├── preview # Unified entry point
│ ├── preview-dynamic.sh # Xcode project injection
│ ├── preview-spm.sh # SPM package preview
│ ├── preview-minimal.sh # Standalone files
│ ├── capture-simulator.sh
│ └── sim-manager.sh
└── templates/
MIT