A lightweight command-line runner that bridges your shell and AI coding agents with the Unity Editor.
- Trigger Asset Database Refresh: Instantly recompile your C# code and feed any compilation errors or warnings directly back to your terminal or AI coding agent.
- Run Editor & PlayMode Tests: Execute unit and integration tests seamlessly as part of your feature implementation workflow.
- Run Static Methods: Execute any C# static method with support for primitive parameters and JSON deserialization.
- macOS / Linux: A terminal with Bash (pre-installed on almost all distributions).
- Windows: Git Bash (included with Git for Windows).
- Unity: Version 2021.3 or higher.
In the Unity Editor, run the installers from the top menu dropdown:
- Tools > UnityCliRunner > InstallBashScript to copy the runner script (
unitycli.sh) to the root of your Unity project. - Tools > UnityCliRunner > InstallSkill to copy the
.agents/skills/unity-clifolder to the root of your project (required if you use agentic AI tools like Antigravity, Codex, Claude...).
Note: If the root of the unity project is not the root of your repository you may want to move the .agents folder to the root of the repository.
If you use agentic AI tools (like Antigravity, Gemini, Claude, ...), UnityCliRunner includes a pre-packaged Agent Skill under .agents/skills/unity-cli
- Sub-Second Feedback: Agents compile code and run tests instantly, avoiding slow batchmode restarts (~30s delay).
- Background Unity Process: Keeps a headless Unity process open in the background so it can be reused for quick iterations.
- Diagnostics Formatting: Compilation errors and test failures are formatted in standard compiler patterns, making it easy for agents to parse and resolve them autonomously.
To install, select Tools > UnityCliRunner > InstallSkill in the Unity Editor to copy the .agents/ folder to your project root.
Run unitycli.sh from the root directory of your Unity project:
Keep a background Unity instance warm to execute tests and methods in sub-second Online Mode without launching the Unity GUI:
# Start a background Unity instance in headless batchmode
# (If already starting or running, it blocks and waits until it is ready)
bash unitycli.sh start batchmode
# Start a background Unity instance in interactive mode (opens Unity Editor GUI)
bash unitycli.sh start interactive
# Check if the background Unity instance is running and reachable
bash unitycli.sh status
# Safely stop the background Unity instance (falls back to process kill if needed)
bash unitycli.sh stopIf Unity is not running, these commands will automatically start a background Unity instance in batchmode first before proceeding with the execution:
# Trigger AssetDatabase.Refresh() and print compilation diagnostics
bash unitycli.sh refresh
# Force a full C# recompilation (clean build cache) and print compilation diagnostics
bash unitycli.sh recompile
# Run all EditMode and PlayMode tests
bash unitycli.sh test
# Run all EditMode tests
bash unitycli.sh test --editmode
# Run all PlayMode tests
bash unitycli.sh test --playmode
# Run editmode tests matching a specific name filter (regex or substring)
bash unitycli.sh test --editmode --filter "MyNamespace.MyTestClass"
# Run playmode tests matching a specific category filter
bash unitycli.sh test --playmode --category "Smoke"0: Success (all tests passed, compilation succeeded, method executed successfully, or connection succeeded).1: Failure (compilation errors, failed tests, method execution exception, or connection check failed).
The executemethod subcommand executes static methods in the Unity editor AppDomain directly from the shell:
bash unitycli.sh executemethod Namespace.Class.Method 4 3.5 "hello" "{\"Value\":42}"- Primitives:
int,float,double,bool,long,decimal(parsed using invariant culture). - Strings: Standard C# strings.
- Complex Types (JSON): Any other C# class/struct type will be automatically deserialized from its raw string parameter using Unity's
JsonUtility.FromJson.
Overloaded static methods are resolved automatically by matching the number of arguments provided.
- Primitives & Strings: Printed directly to the console.
- Complex Types: Automatically serialized and printed as a JSON payload using
JsonUtility.ToJson. - Void/Null: Prints
Unity Response: SUCCESS(via socket) or no extra payload.
The repository includes a robust automated integration test suite test.sh to verify the CLI runner's correctness
Simply execute:
bash test.sh- Detects if Unity is running for the project. If not, it launches Unity in the background and waits for the TCP server to start.
- Runs a suite of test scenarios (such as compiling errors/warnings, skipped tests, executing successful/failing/missing methods) in Online Mode via TCP sockets.
- Compares the normalized console output against verified outputs located under IntegrationTests//output.online.verified.txt.
- Gracefully terminates the running Unity Editor process.
- Re-runs scenarios in Auto-Start Mode (starting with Unity stopped) to verify that commands automatically trigger the background Unity startup sequence and execute correctly.
- Compares the console output against verified outputs under IntegrationTests//output.autostart.verified.txt.
- Restores any modified test files to their original state upon completion.
If you modify the output format of unitycli.sh and need to update the expected baselines, run the integration tests with the BOOTSTRAP=true environment variable:
BOOTSTRAP=true bash test.shThis automatically overwrites all output.online.verified.txt and output.autostart.verified.txt files with the actual output generated during the test run.