A CLI toolset for building and capturing SwiftUI previews programmatically. Designed to work with AI coding assistants (Claude Code and Cursor) 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
- Swift toolchain (preview-tool auto-builds on first run)
Install via the Claude Code plugin marketplace:
/plugin marketplace add Iron-Ham/XcodePreviews
/plugin install preview-build@XcodePreviews
git clone https://github.com/Iron-Ham/XcodePreviews.git ~/XcodePreviewsCopy the skill definition to your user-level commands directory:
mkdir -p ~/.claude/commands
cp ~/XcodePreviews/.claude/commands/preview.md ~/.claude/commands/Note: The manual install expects scripts at
~/XcodePreviews. If you cloned to a different location, setPREVIEW_BUILD_PATH:export PREVIEW_BUILD_PATH=/path/to/XcodePreviews
Upgrading from
Claude-XcodePreviews? The old path~/Claude-XcodePreviewsstill works — the skill files fall back to it automatically. You can rename your clone at any time, or just leave it.
git clone https://github.com/Iron-Ham/XcodePreviews.git ~/XcodePreviewsCopy the skill to your user-level skills directory:
mkdir -p ~/.cursor/skills/preview
cp ~/XcodePreviews/.cursor/skills/preview/SKILL.md ~/.cursor/skills/preview/If you want the preview toolkit context always available in a specific project, copy the rule to that project's .cursor/rules/ directory:
mkdir -p /path/to/your/project/.cursor/rules
cp ~/XcodePreviews/.cursor/rules/preview.mdc /path/to/your/project/.cursor/rules/Note: Like the Claude Code install, this expects scripts at
~/XcodePreviews. SetPREVIEW_BUILD_PATHto override:export PREVIEW_BUILD_PATH=/path/to/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 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:
/preview path/to/MyView.swift
After installing the skill, ask the agent to preview a SwiftUI view:
Preview the file path/to/MyView.swift
In both cases, the assistant will:
- Build the preview using the appropriate method
- Capture a screenshot
- Analyze and describe the visual output
Codex can use the same scripts through a Codex skill.
export PREVIEW_BUILD_PATH=/absolute/path/to/XcodePreviews
mkdir -p ~/.codex/skills/public/xcode-preview-capture
cp -R "$PREVIEW_BUILD_PATH"/.codex/skills/xcode-preview-capture/* \
~/.codex/skills/public/xcode-preview-capture/Set PREVIEW_BUILD_PATH in your shell profile so Codex can invoke the scripts from any location.
Ask Codex to preview a SwiftUI file. The skill instructs Codex to:
- Run
scripts/previewwith your target file - Capture
/tmp/preview*.png - Read the screenshot and provide UI analysis
| Path | Purpose |
|---|---|
scripts/preview |
Unified entry point (auto-detects best approach) |
scripts/preview-minimal.sh |
Standalone files (system imports only) |
scripts/capture-simulator.sh |
Screenshot capture |
scripts/sim-manager.sh |
Simulator utilities |
tools/preview-tool |
Swift CLI for dynamic preview injection + SPM preview |
MIT