An open-source developer tool that gives command-line AI agents natively capable eyes into the Unity Editor. This bridge allows terminal-based AI agents (like Claude Code, Gemini CLI) to query active compilation errors directly from the Unity Editor, establishing a seamless "fix-and-retry" feedback loop.
- The Backend: A lightweight C#
[InitializeOnLoad]script (UnityAgentServer.cs) that spins up an HTTP server on port 5142 inside the Unity Editor. This server uses reflection against Unity'sLogEntriesto aggregate and format any standing errors into an accessible JSON endpoint (/compile-errors). In cases of syntax errors, the domain reload is blocked, but the server retains availability in the prior AppDomain, ready to diagnose issues. - The CLI Wrapper: A globally installed Node.js tool (
unity-agent-cli). AI systems invoke this tool via standard commands (unity-agent-cli check). The tool acts as a translation layer, querying the background Unity connection and relaying feedback formatted neatly with standard0/1UNIX exit codes to steer autonomous fixes.
Open your Unity project and navigate to Window > Package Manager.
Click the + button in the top-left corner, select "Add package from git URL...", and enter the following URL:
https://github.com/ruizhengu/unity-agent-bridge.git?path=/UnityPackage
Once installed, it will compile automatically, starting the HTTP listener silently in the background on localhost:5142.
In your terminal, navigate directly to the inner CLI/ folder, or install from the published package:
# Example from the repository root:
cd CLI
npm install -g .To verify it is working correctly, run:
unity-agent-cli checkPlace the included GEMINI.md or CLAUDE.md into your AI's configuration directory.
- For terminal agents like Gemini CLI or Claude Code, put it at your project root.
- For IDE-based agents like Cursor or Windsurf, rename it to
.cursorrulesor.windsurfrulesand place it in the root.
This bridge allows the AI to autonomously fix its own code. Here are two examples of how it works in practice.
We intentionally ask the agent to write bad code so it has to use the bridge to self-correct.
Prompt: "Please create a new script in
Assets/Scripts/PlayerController.cs. I want the script to move a Game Object forward when I press the 'W' key.Constraint: To demonstrate the compilation checker, you must intentionally leave out the semicolon at the end of the
transform.Translateline."
What Happens:
- Compilation Fails:
unity-agent-cli checkreturns an error:❌ Compilation Errors Found: File: Assets/Scripts/PlayerController.cs:15 Message: error CS1002: ; expected - Autonomous Fix: The agent sees the
exit 1code, reads the error, and autonomously adds the semicolon. - Success: It runs the check again, receives
exit 0, and reports success to you!
To demonstrate the checker's ability to catch deeper structural issues.
Prompt: "Please create a new script called
SceneLoader.csin the Scripts folder. I want it to have a method that loads the 'MainMenu' scene when called.Constraint: Do NOT include the
using UnityEngine.SceneManagement;directive at the top of the file."
What Happens:
- Compilation Fails:
unity-agent-cli checkcatches the missing context:❌ Compilation Errors Found: File: Assets/Scripts/SceneLoader.cs:12 Message: error CS0103: The name 'SceneManager' does not exist in the current context - Autonomous Fix: The agent recognizes the CS0103 error, explicitly adds the
using UnityEngine.SceneManagement;directive, and verifies the fix.
Contributions are always welcome! Whether you have ideas for new features, bug fixes, or improvements to the documentation, feel free to open an issue or submit a pull request. Let's make AI coding in Unity as seamless as possible!