> 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/gluecli-for-ai-agents.md). Agents can also search and read this documentation through its [MCP server](https://docs.flatredball.com/flatredball/~gitbook/mcp).

# GlueCli for AI Agents

### Introduction

[GlueCli](https://docs.flatredball.com/flatredball/glue-reference/gluecli.md) is the main way an AI agent should edit a FlatRedBall project. An agent can edit `.gluj`, `.glsj` and `.glej` files by hand, but it does not know the editor's rules, and it cannot tell whether an edit broke something. GlueCli applies each edit through the editor's own code, so plugins react and code is generated exactly as in the editor, and then it reports any new errors.

This page is a recipe for agents. For each command's options, follow the links to the command pages, or run `GlueCli <command> --help`.

### Using GlueCli with AI Agents

FlatRedBall ships a skill for Claude Code that tells an agent to use GlueCli and links back to these pages. Copy the [glue-cli folder](https://github.com/vchelaru/FlatRedBall/tree/NetStandard/frb-skills/glue-cli) from the FlatRedBall repository into your game repository's `.claude/skills/` folder. Other AI tools can read its `SKILL.md` as a plain Markdown file.

### Why It Works Well for Agents

* **JSON output.** Pass `--json` and the run prints one JSON object to stdout. Banners and progress go to stderr.
* **Exit codes.** `0` means the edit applied with no new errors. `1` means the edit was not applied, or it added errors. `2` means bad arguments or a project that would not load. Branch on the exit code instead of reading text.
* **A failed edit saves nothing.** A run that exits with `1` leaves the project as it was, so retrying is safe.
* **Errors name close matches.** A misspelled element, object, variable or type fails with a list of names that do exist, such as `Did you mean: X?`.
* **No dialogs.** Questions the editor would ask become flags. If an answer is needed and the flag is missing, the message names the flag to pass.
* **Existing errors do not block you.** Errors the project had before the edit are reported as `preexistingErrors` and do not fail the run.

### Before You Start

* GlueCli runs on Windows only.
* `GlueCli.exe` is next to the editor's exe (`GlueFormsCore.exe`). See [Getting GlueCli](https://docs.flatredball.com/flatredball/glue-reference/gluecli.md#getting-gluecli).
* The project can stay open in the FlatRedBall Editor. The editor reloads the changed files and regenerates code.
* `<project>` is a `.gluj`, a `.csproj`, or a folder with exactly one `.gluj` in it or its subfolders. See [How a Run Works](https://docs.flatredball.com/flatredball/glue-reference/gluecli.md#how-a-run-works).
* 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, and generated files are usually not in source control, so a fresh clone does not build until `regen` runs.

### The Agent Loop

#### 1. Read the Project with describe

Run [describe](https://docs.flatredball.com/flatredball/glue-reference/gluecli/describe.md) before editing. It lists the project's screens and entities, and for one element it lists the objects, variables, states, events and files, with the exact names other commands take:

```
GlueCli describe MyGame --json
GlueCli describe MyGame --element GameScreen --json
```

Use those names in your edit commands rather than guessing them or reading the JSON files.

#### 2. Edit with One Command per Change

Each change is one GlueCli command. Pick the command that matches what you would do in the editor:

| To do this                                                                | Use                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Add a screen or entity                                                    | [add-screen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-screen.md), [add-entity](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-entity.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| Add an object                                                             | [add-object](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-object.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Set a variable on an element or object                                    | [set-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-variable.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Set a property such as `LayerOn`, `BaseEntity` or `ImplementsICollidable` | [set-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-property.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Add a file                                                                | [add-file](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-file.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Add, change or remove a variable                                          | [add-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-variable.md), [set-variable-property](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-variable-property.md), [remove-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/remove-variable.md)                                                                                                                                                                                                                                                                                                                |
| Work with states                                                          | [add-state-category](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-state-category.md), [add-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-state.md), [set-state-variable](https://docs.flatredball.com/flatredball/glue-reference/gluecli/set-state-variable.md), [rename-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename-state.md), [rename-state-category](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename-state-category.md), [delete-state](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete-state.md) |
| Add or remove an event                                                    | [add-event](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-event.md), [remove-event](https://docs.flatredball.com/flatredball/glue-reference/gluecli/remove-event.md)                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Rename or delete anything                                                 | [rename](https://docs.flatredball.com/flatredball/glue-reference/gluecli/rename.md), [delete](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

Rename with `rename`, `rename-state` or `rename-state-category` rather than deleting and re-adding. A rename updates everything that refers to the old name. Deleting and re-adding loses those references.

Every edit saves the project and regenerates code for the changed screens and entities, so there is no separate save or codegen step.

To make several edits, put them in a file, one command per line, and run [batch](https://docs.flatredball.com/flatredball/glue-reference/gluecli/batch.md). The editor starts and the project loads once, so each edit after the first costs a fraction of a separate run. Each command reports and fails as it would alone, and the batch stops at the first failure:

```
GlueCli batch MyGame --file edits.txt --json
```

To preview an edit before making it, add `--dry-run`. The edit runs the same way, with the same checks, but against a temp copy of the project. The report lists the files it would change, with a diff of each `.gluj`, `.glsj` and `.glej` file, and your project stays as it was. The exit code is the one the real edit would get, so a dry run is also a cheap way to find out whether an edit is allowed:

```
GlueCli rename MyGame --element Entities\Enemy --to Slime --dry-run --json
```

#### 3. Read the Result

With `--json`, check `exitCode` first:

* `0`: the edit applied. `edit` says what it did. `filesWritten` lists the files that changed.
* `1`: read `editFailures` for why the edit was not applied, or `errors` for errors the edit added. Fix the command and run it again.
* `2`: read `failure`. The arguments are wrong or the project did not load.

#### 4. Check Hand Edits

If you edit `.gluj`, `.glsj` or `.glej` files by hand, run [check](https://docs.flatredball.com/flatredball/glue-reference/gluecli/check.md) afterwards, then [regen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/regen.md) to regenerate code. A non-zero exit code means the hand edit has a problem.

#### 5. Build the Game and Fix Errors

GlueCli proves the project is valid for the editor. It does not compile the game. After editing, build the game project:

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

Find the `error CS` lines. Each one 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
```

Fix each error by where it is:

* **In a `.Generated.cs` file:** the cause is in the project data. Fix it with a GlueCli command, then run [regen](https://docs.flatredball.com/flatredball/glue-reference/gluecli/regen.md). Never edit a `.Generated.cs` file. Code generation overwrites it.
* **In any other file:** the cause is hand-written code. Edit the code. The example above is hand-written code that still uses a name a GlueCli edit changed.

Then build again. Repeat until the build has no errors.

### Things to Know

* Hand-written code is never changed. A rename updates generated code and project files, but code you wrote that uses the old name must be updated by you.
* Event handlers go into the element's `.Event.cs` file. [add-event](https://docs.flatredball.com/flatredball/glue-reference/gluecli/add-event.md) adds an empty `On<name>` method there for you to fill in.
* [delete](https://docs.flatredball.com/flatredball/glue-reference/gluecli/delete.md) keeps left-over files on disk by default, unlike the editor. Pass `--files delete` to remove them.
* Element names accept either slash and may leave out the folder when the name is unique: `GameScreen`, `Screens\GameScreen` and `Screens/GameScreen` all work. Property values picked from a list, such as `BaseEntity`, match the same way.


---

# 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/gluecli-for-ai-agents.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.
