Control Unity Editor from Claude Code
Project description
name: unity description: Execute Unity Editor commands (run tests, compile, get logs, refresh assets) via file-based bridge. Auto-activates for Unity-related tasks. Requires com.managexr.claude-bridge package installed in Unity project.
Unity Bridge Skill
Control Unity Editor operations from Claude Code using a reliable file-based communication protocol.
Overview
The Unity Bridge enables Claude Code to trigger operations in a running Unity Editor instance without network configuration or port conflicts. It uses a simple file-based protocol where commands are written to .unity-bridge/command.json and responses are read from .unity-bridge/response-{id}.json.
Key Features:
- Execute EditMode and PlayMode tests
- Trigger script compilation
- Refresh asset database
- Check editor status (compilation, play mode, etc.)
- Retrieve Unity console logs
Multi-Project Support: Each Unity project has its own .unity-bridge/ directory, allowing multiple projects to be worked on simultaneously.
Requirements
-
Unity Package: Install
com.managexr.claude-bridgein your Unity project- Via Package Manager:
https://github.com/ManageXR/claude-unity-bridge.git - See main package README for installation instructions
- Via Package Manager:
-
Unity Editor: Must be open with your project loaded
-
Python 3: The skill uses a Python script for reliable command execution
How It Works
The skill uses a CLI tool (unity-bridge) that handles:
- UUID generation for command tracking
- Atomic file writes to prevent corruption
- Exponential backoff polling for responses
- File locking handling
- Automatic cleanup of old response files
- Formatted, human-readable output
This approach ensures deterministic, rock-solid execution - the script is tested once and behaves identically every time, handling all edge cases (timeouts, file locking, malformed responses, etc.) without requiring Claude to manage these details in-context.
Usage
Basic Pattern
When you need to interact with Unity, use the CLI directly:
unity-bridge [command] [options]
All commands automatically:
- Generate a unique UUID for tracking
- Write the command atomically
- Poll for response with timeout
- Format output for readability
- Cleanup response files
Command Examples
Run Tests
Execute Unity tests in EditMode or PlayMode:
# Run all EditMode tests
unity-bridge run-tests --mode EditMode
# Run tests with filter
unity-bridge run-tests --mode EditMode --filter "MXR.Tests"
# Run all tests (both modes)
unity-bridge run-tests
Output:
✓ Tests Passed: 410
✗ Tests Failed: 2
○ Tests Skipped: 0
Duration: 1.25s
Failed Tests:
- MXR.Tests.AuthTests.LoginWithInvalidCredentials
Expected: success, Actual: failure
- MXR.Tests.NetworkTests.TimeoutHandling
NullReferenceException: Object reference not set
Parameters:
--mode-EditModeorPlayMode(optional, defaults to both)--filter- Test name filter pattern (optional)--timeout- Override default 30s timeout
Compile Scripts
Trigger Unity script compilation:
unity-bridge compile
Output (Success):
✓ Compilation Successful
Duration: 2.3s
Output (Failure):
✗ Compilation Failed
Assets/Scripts/Player.cs:25: error CS0103: The name 'invalidVar' does not exist
Assets/Scripts/Enemy.cs:67: error CS0246: Type 'MissingClass' could not be found
Get Console Logs
Retrieve Unity console output:
# Get last 20 logs
unity-bridge get-console-logs --limit 20
# Get only errors
unity-bridge get-console-logs --limit 10 --filter Error
# Get warnings
unity-bridge get-console-logs --filter Warning
Output:
Console Logs (last 10, filtered by Error):
[Error] NullReferenceException: Object reference not set
at Player.Update() in Assets/Scripts/Player.cs:34
[Error] Failed to load asset: missing_texture.png
[Error] (x3) Shader compilation failed
See Console for details
Parameters:
--limit- Maximum number of logs (default: 50)--filter- Filter by type:Log,Warning, orError
Get Editor Status
Check Unity Editor state:
unity-bridge get-status
Output:
Unity Editor Status:
- Compilation: ✓ Ready
- Play Mode: ✏ Editing
- Updating: No
Possible States:
- Compilation:
✓ Readyor⏳ Compiling... - Play Mode:
✏ Editing,▶ Playing, or⏸ Paused - Updating:
YesorNo
Refresh Asset Database
Force Unity to refresh assets:
unity-bridge refresh
Output:
✓ Asset Database Refreshed
Duration: 0.5s
Advanced Options
Timeout Configuration
Override the default 30-second timeout:
unity-bridge run-tests --timeout 60
Use longer timeouts for:
- Large test suites
- PlayMode tests (which start/stop Play Mode)
- Full project compilation
Cleanup Old Responses
Automatically remove old response files before executing:
unity-bridge compile --cleanup
This removes response files older than 1 hour. Useful for maintaining a clean workspace.
Verbose Output
See detailed execution progress:
unity-bridge run-tests --verbose
Prints:
- Command ID
- Polling attempts
- Response file detection
- Cleanup operations
Error Handling
The script provides clear error messages for common issues:
Unity Not Running:
Error: Unity Editor not detected. Ensure Unity is open with the project loaded.
Command Timeout:
Error: Command timed out after 30s. Check Unity Console for errors.
Invalid Parameters:
Error: Failed to write command file: Invalid mode 'InvalidMode'
Exit Codes:
0- Success1- Error (Unity not running, invalid params, etc.)2- Timeout
Integration with Claude Code
When you're working in a Unity project directory, you can ask Claude Code to perform Unity operations naturally:
- "Run the Unity tests in EditMode"
- "Check if there are any compilation errors"
- "Show me the last 10 error logs from Unity"
- "Refresh the Unity asset database"
Claude Code will automatically use this skill to execute the commands via the Python script.
File Protocol Details
Command Format
Written to .unity-bridge/command.json:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"action": "run-tests",
"params": {
"testMode": "EditMode",
"filter": "MyTests"
}
}
Response Format
Read from .unity-bridge/response-{id}.json:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "success",
"action": "run-tests",
"duration_ms": 1250,
"result": {
"passed": 410,
"failed": 0,
"skipped": 0,
"failures": []
}
}
Status Values:
running- Command in progress (may see intermediate responses)success- Command completed successfullyfailure- Command completed with failures (e.g., failed tests)error- Command execution error
Project Structure
skill/
├── SKILL.md # This file
├── pyproject.toml # Package configuration
├── src/
│ └── claude_unity_bridge/
│ ├── __init__.py # Package version
│ └── cli.py # CLI implementation
├── tests/
│ └── test_cli.py # Unit tests
└── references/
├── COMMANDS.md # Detailed command specifications
└── EXTENDING.md # Guide for adding custom commands
Detailed Documentation
For more information, see:
- COMMANDS.md - Complete command reference with all parameters, response formats, and edge cases
- EXTENDING.md - Tutorial for adding custom commands to the Unity Bridge for project-specific workflows
Troubleshooting
Unity Not Responding
Symptoms: Commands timeout or "Unity not detected" error
Solutions:
- Ensure Unity Editor is open with the project loaded
- Check that the package is installed (
Window > Package Manager) - Verify
.unity-bridge/directory exists in project root - Check Unity Console for errors from ClaudeBridge package
Response File Issues
Symptoms: "Failed to parse response JSON" error
Solutions:
- Check Unity Console for ClaudeBridge errors
- Manually inspect
.unity-bridge/response-*.jsonfiles - Try cleaning up old responses with
--cleanupflag - Restart Unity Editor if file system is in bad state
Performance Issues
Symptoms: Slow response times, frequent timeouts
Solutions:
- Increase timeout with
--timeout 60or higher - Close unnecessary Unity Editor windows
- Reduce test scope with
--filterparameter - Check system resources (CPU, memory)
File Locking Errors
Symptoms: Intermittent errors reading/writing files
Solutions:
- The CLI handles file locking automatically with retries
- If persistent, check for antivirus interference
- Verify file permissions on
.unity-bridge/directory
Installation
Quick Install
pip install claude-unity-bridge
unity-bridge install-skill
This installs the CLI and the Claude Code skill.
Verify Setup
unity-bridge health-check
Updating
unity-bridge update
This upgrades the pip package and reinstalls the skill.
Uninstalling
unity-bridge uninstall-skill
pip uninstall claude-unity-bridge
Development Installation
cd claude-unity-bridge/skill
pip install -e ".[dev]"
unity-bridge install-skill
Why a CLI Tool?
The skill uses a CLI tool instead of implementing the protocol directly in Claude Code prompts for several critical reasons:
Consistency: UUID generation, polling logic, and error handling work identically every time. Without the CLI, Claude might implement these differently across sessions, leading to subtle bugs.
Reliability: All edge cases are handled once in tested code:
- File locking when Unity writes responses
- Exponential backoff for polling
- Atomic command writes to prevent corruption
- Graceful handling of malformed JSON
- Proper cleanup of stale files
Error Messages: Clear, actionable error messages for all failure modes. Claude doesn't have to figure out what went wrong each time.
Token Efficiency: The CLI handles complexity, so Claude doesn't need to manage low-level details in-context. The SKILL.md stays concise while providing full functionality.
Deterministic Exit Codes: Shell integration works reliably with standard exit codes (0=success, 1=error, 2=timeout).
Rock Solid: Test the CLI once, it works forever. No variability between Claude sessions.
Support
For issues or questions:
- Package Issues: https://github.com/ManageXR/claude-unity-bridge/issues
- Skill Issues: Report in the same repository with
[Skill]prefix
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_unity_bridge-0.1.4.tar.gz.
File metadata
- Download URL: claude_unity_bridge-0.1.4.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cde6ee5d42a049d4efc74fc961ec56c47fb86a711d63c36011a0ac9cddd69c7
|
|
| MD5 |
885a4385c6788a6adf4c11004e90297c
|
|
| BLAKE2b-256 |
0c6fe37139e965e4f9bc9dc5b5bbf55d387b8b841af5e25cedda4afc74fb31de
|
Provenance
The following attestation bundles were made for claude_unity_bridge-0.1.4.tar.gz:
Publisher:
publish.yml on ManageXR/claude-unity-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_unity_bridge-0.1.4.tar.gz -
Subject digest:
2cde6ee5d42a049d4efc74fc961ec56c47fb86a711d63c36011a0ac9cddd69c7 - Sigstore transparency entry: 934998789
- Sigstore integration time:
-
Permalink:
ManageXR/claude-unity-bridge@c2e3ad9c9397e8604a90eb8cd1ba4476f221dae4 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ManageXR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c2e3ad9c9397e8604a90eb8cd1ba4476f221dae4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file claude_unity_bridge-0.1.4-py3-none-any.whl.
File metadata
- Download URL: claude_unity_bridge-0.1.4-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e883c8ed1803570adeabe5590fee77b229abe3e186ac0afca136f70a8cc813d5
|
|
| MD5 |
157e93148b02895407dd1221c28aae56
|
|
| BLAKE2b-256 |
bb4d85d12d6cdef844c96b63c4060fd2f5ab663e23e654be1779ebf4fc8061b7
|
Provenance
The following attestation bundles were made for claude_unity_bridge-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on ManageXR/claude-unity-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_unity_bridge-0.1.4-py3-none-any.whl -
Subject digest:
e883c8ed1803570adeabe5590fee77b229abe3e186ac0afca136f70a8cc813d5 - Sigstore transparency entry: 934998800
- Sigstore integration time:
-
Permalink:
ManageXR/claude-unity-bridge@c2e3ad9c9397e8604a90eb8cd1ba4476f221dae4 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ManageXR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c2e3ad9c9397e8604a90eb8cd1ba4476f221dae4 -
Trigger Event:
push
-
Statement type: