> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/glue-reference/gluecli.md). Agents can also search and read this documentation through its [MCP server](https://docs.flatredball.com/flatredball/~gitbook/mcp).

# GlueCli

### Introduction

**GlueCli** (`GlueCli.exe`) is a command-line tool that makes the same edits the FlatRedBall Editor makes. It runs the editor's own code with no window, so plugins react exactly as they do in the editor and code is generated the same way.

Use GlueCli when:

* You are an AI agent editing a FlatRedBall project. See [GlueCli for AI Agents](https://docs.flatredball.com/flatredball/glue-reference/gluecli/gluecli-for-ai-agents.md).
* You want to script changes to a project, such as adding many objects or setting many variables.
* You hand-edited a `.gluj`, `.glsj` or `.glej` file and want to check it for errors or regenerate code.

GlueCli runs on Windows only, like the editor.

### Getting GlueCli

`GlueCli.exe` ships next to the editor's exe (`GlueFormsCore.exe`). In the FRBDK download it is in the `Xna 4 Tools` folder. In the daily build zip it is in the root folder. Run it from that folder, or add the folder to your `PATH`.

If you build FlatRedBall from source, build the editor solution:

```
dotnet build "FRBDK/Glue/Glue with All.sln"
```

This writes `GlueCli.exe` to `FRBDK/Glue/Glue/bin/Debug/`, next to `GlueFormsCore.exe`. GlueCli loads plugins from the `Plugins` folder next to it, so build the whole solution rather than only `GlueCli.csproj`. Otherwise GlueCli runs with plugins left over from an older build.

### How a Run Works

Every command has the same shape:

```
GlueCli <command> <project> [options]
```

`<project>` is one of these:

* A `.gluj` file. GlueCli opens the `.csproj` with the same name next to it, or the only `.csproj` in that folder.
* A `.csproj` file.
* A folder. GlueCli searches it and all its subfolders for `.gluj` files, skipping `bin` and `obj` folders. The search must find exactly one. If it finds more, the run fails and lists them, so pass one of them instead.

A common layout puts the `.gluj` one folder down from the repository root, such as `MyGame/MyGame/MyGame.gluj`. All of these load it:

```
GlueCli check MyGame/MyGame/MyGame.gluj
GlueCli check MyGame/MyGame
GlueCli check MyGame
```

The last one works because the search includes subfolders. It fails if the repository holds a second `.gluj`, such as a copy of the game for another platform.

Each run does the following:

1. Starts the editor with no window and loads the project. Loading reads the project. Unlike **File > Load Project**, it does not regenerate code or save anything.
2. Runs one command, or several with [batch](https://docs.flatredball.com/flatredball/glue-reference/gluecli/batch.md).
3. Waits for the editor's queued work, such as plugin reactions and code generation.
4. For edit commands, saves the `.gluj`, the changed screen and entity files and the `.csproj`, and regenerates code for every changed screen and entity.
5. Prints a report and exits.

Run [regen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/regen.md) once after cloning or pulling, or whenever generated code is out of date. Edit commands regenerate only what they change, so after a fresh clone, or after project files change outside GlueCli, the game does not build until `regen` runs.

GlueCli reads the editor's settings but never saves them. Plugins load from the `Plugins` folder next to `GlueCli.exe`, plus the project's own `Plugins` folder.

You can leave the project open in the FlatRedBall Editor. The editor sees the changed `.gluj`, `.glsj` and `.glej` files, reloads them, and regenerates code.

Run `GlueCli --help` for the list of commands, and `GlueCli <command> --help` for a command's options and examples.

### Options for Every Command

| Option      | Meaning                                                                                                                          |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `--json`    | Print one JSON object to stdout instead of text. See JSON Output below.                                                          |
| `--dry-run` | Run the command against a temp copy of the project and report what it would change. The project on disk stays exactly as it was. |
| `--help`    | Show the command's options and examples.                                                                                         |

### Previewing an Edit with --dry-run

`--dry-run` works with every command. GlueCli copies the `.csproj` folder (skipping `bin`, `obj`, `.vs` and `.git`) to a temp folder, runs the command there in full, compares the copy with how it started, and deletes it. The edit goes through the same checks and plugin reactions as a real one, and the exit code is the one the real edit would get.

The report lists each file the run would add, change or delete, with a diff of each `.gluj`, `.glsj`, `.glej` and `.json` file:

```
add-object C:\Games\Beefball\Beefball\Beefball.csproj
Glue started in 3.3s, project loaded in 2.4s, 6.7s total.
Added SpriteInstance (FlatRedBall.Sprite) to Screens\GameScreen.
Would change (2):
  modified Screens/GameScreen.Generated.cs
  modified Screens/GameScreen.glsj
    --- a/Screens/GameScreen.glsj
    +++ b/Screens/GameScreen.glsj
    @@ -1065,6 +1065,29 @@
    ...
No new errors.
Dry run: the project on disk was not changed.
```

Art, audio and other large binary files are linked rather than copied, so a dry run stays fast on a game with a lot of content.

### Output

A run prints the command, the project, how long loading took, the files it wrote, and any errors:

```
regen C:\Games\Beefball\Beefball\Beefball.csproj
Glue started in 2.5s, project loaded in 1.5s, 4.4s total.
Files written (14):
  Beefball.csproj
  Entities/Goal.Generated.cs
  ...
No errors.
```

Edit commands report errors the project already had separately, as preexisting errors. These do not fail the run, so you can edit a project that already has problems.

### JSON Output

Pass `--json` to any command to print one JSON object to stdout. Everything else goes to stderr. The object has these properties:

| Property                                          | Meaning                                                                                                                                                                                                                                    |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `command`                                         | The command that ran.                                                                                                                                                                                                                      |
| `project`                                         | The project's `.csproj` path.                                                                                                                                                                                                              |
| `exitCode`                                        | The exit code (see below).                                                                                                                                                                                                                 |
| `failure`                                         | Why the run stopped, for exit code 2.                                                                                                                                                                                                      |
| `editFailures`                                    | Why the edit was not applied.                                                                                                                                                                                                              |
| `edit`                                            | What the edit did. Its shape depends on the command, and each command's page lists it.                                                                                                                                                     |
| `editSummary`                                     | The same as `edit`, as the text a run prints without `--json`.                                                                                                                                                                             |
| `errors`                                          | The editor's error list, each with `type` and `details`.                                                                                                                                                                                   |
| `outputErrors`                                    | Errors the editor printed to its output.                                                                                                                                                                                                   |
| `dialogMessages`                                  | Messages the editor would have shown in a dialog.                                                                                                                                                                                          |
| `preexistingErrors`                               | Edit commands only: errors the project had before the edit. These are not counted.                                                                                                                                                         |
| `filesWritten`                                    | Files the run wrote, relative to the `.csproj` folder.                                                                                                                                                                                     |
| `startupSeconds`, `loadSeconds`, `elapsedSeconds` | How long starting the editor, loading the project, and the whole run took.                                                                                                                                                                 |
| `dryRun`                                          | `--dry-run` only: `true`. `filesWritten` is then empty.                                                                                                                                                                                    |
| `changes`                                         | `--dry-run` only: each file the run would change, with `path` (relative to the `.csproj` folder), `kind` (`modified`, `added` or `deleted`) and `diff` (a unified diff for `.gluj`, `.glsj`, `.glej` and `.json` files, otherwise `null`). |

### Exit Codes

| Code | Meaning                                                                                                                                                         |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0    | Done, and no new errors.                                                                                                                                        |
| 1    | An edit command could not apply the edit, or the edit left errors the project did not have before. For `check`, `regen` and `describe`, the project has errors. |
| 2    | Bad arguments, the project could not be loaded, or a plugin failed to start.                                                                                    |

### Build Errors

GlueCli checks the project, not the game's code. After editing, build the game and read the compiler errors:

```
dotnet build MyGame/MyGame/MyGame.csproj
```

Each error names a file and a line:

```
C:\Games\Beefball\Beefball\Entities\PlayerBall.cs(34,51): error CS0103: The name 'Speed' does not exist in the current context
```

Where the error is tells you where to fix it:

* **A `.Generated.cs` file.** The generated code comes from the project, so fix the project with a GlueCli command, then run [regen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/regen.md). Do not edit the `.Generated.cs` file. The next code generation overwrites it.
* **Any other file.** This is code you wrote. Fix it in the code. A common cause is a [rename](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename.md), which does not change hand-written code.

Build again until there are no errors.

### A Failed Edit Saves Nothing

GlueCli checks an edit before it changes anything. If the name is taken, the element or object does not exist, or a value does not convert to the variable's type, the run exits with code 1 and saves no changes to the project. The message says why and lists close matches:

```
Edit not applied (1):
  'Coin' is not a valid entity name: There is already an entity named Coin
1 problem(s).
```

### Questions Become Flags

The editor sometimes asks a question in the middle of an edit, such as whether to move objects to a new layer or what to do with files a delete leaves behind. GlueCli never shows a dialog. Instead, each question has a flag. For example, [set-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-variable.md) has `--move-objects` and [delete](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete.md) has `--files`.

If a command needs an answer and you did not pass its flag, the run fails and the message names the flag to pass. Any message the editor would have shown in a dialog is reported, and counts as a failure.

### Commands

**Project**

| Command                                                                                 | Description                                                                             |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| [check](https://docs.flatredball.com/flatredball/glue-reference/gluecli/check.md)       | Load the project and report every error.                                                |
| [regen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/regen.md)       | Load the project, regenerate all code, and report errors.                               |
| [describe](https://docs.flatredball.com/flatredball/glue-reference/gluecli/describe.md) | Show what the project or one screen or entity contains.                                 |
| [batch](https://docs.flatredball.com/flatredball/glue-reference/gluecli/batch.md)       | Run several commands, one per line of a file or stdin, against one load of the project. |

**Screens and Entities**

| Command                                                                                     | Description                                              |
| ------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| [add-screen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-screen.md) | Add a screen, optionally inheriting from another screen. |
| [add-entity](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-entity.md) | Add an entity, with the Add Entity dialog's options.     |

**Objects**

| Command                                                                                         | Description                                                     |
| ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [add-object](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-object.md)     | Add an object to a screen or entity.                            |
| [set-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-variable.md) | Set a variable on a screen or entity, or on one of its objects. |

**Files**

| Command                                                                                 | Description                                                    |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [add-file](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-file.md) | Add an existing file to a screen, an entity or Global Content. |

**Variables**

| Command                                                                                                           | Description                                                 |
| ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| [add-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-variable.md)                   | Add a variable to a screen or entity.                       |
| [set-variable-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-variable-property.md) | Set a property of a variable, such as its type or category. |
| [remove-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/remove-variable.md)             | Remove a variable from a screen or entity.                  |

**States**

| Command                                                                                                           | Description                                      |
| ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| [add-state-category](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-state-category.md)       | Add a state category to a screen or entity.      |
| [add-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-state.md)                         | Add a state to a state category.                 |
| [set-state-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-state-variable.md)       | Set or clear the value a state gives a variable. |
| [rename-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename-state.md)                   | Rename a state.                                  |
| [rename-state-category](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename-state-category.md) | Rename a state category.                         |
| [delete-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete-state.md)                   | Delete a state or a whole state category.        |

**Events**

| Command                                                                                         | Description                              |
| ----------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [add-event](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-event.md)       | Add an event to a screen or entity.      |
| [remove-event](https://docs.flatredball.com/flatredball/glue-reference/gluecli/remove-event.md) | Remove an event from a screen or entity. |

**Collision**

| Command                                                                                                                                         | Description                                                                  |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [add-collision-relationship](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-collision-relationship.md)                     | Add a collision relationship between two objects in a screen.                |
| [set-collision-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-collision-relationship.md#changing-settings-later) | Change a setting of a collision relationship, such as its physics or masses. |

**Rename, Delete and Properties**

| Command                                                                                                   | Description                                                                      |
| --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [rename](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename.md)                       | Rename a screen, entity, object or file, and everything that refers to it.       |
| [delete](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete.md)                       | Delete a screen, entity, object or file.                                         |
| [set-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-property.md)           | Set a property of a screen, entity or object, such as `LayerOn` or `BaseEntity`. |
| [set-file-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-file-property.md) | Set a property of a file, such as `LoadedOnlyWhenReferenced` or `RuntimeType`.   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/glue-reference/gluecli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
