> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/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/gum/cli/cli/edit.md). Agents can also search and read this documentation through its [MCP server](https://docs.flatredball.com/gum/~gitbook/mcp).

# edit

```
gumcli edit <project.gumj> <operations.json> [--json]
gumcli edit --schema [--json]
```

Applies a list of changes from a JSON file to a project and saves it in the same format the **Gum** tool writes. Each change goes through the same code the tool runs when you make that change by hand, so a misspelled variable name fails instead of writing a file Gum cannot use.

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

## Options

* `<project.gumj>`: Path to the `.gumj` or `.gumx` project file
* `<operations.json>`: Path to the operations file
* `--json`: Report new errors as a JSON array, in the same format as [check](https://docs.flatredball.com/gum/cli/cli/check.md)
* `--schema`: Print every operation with its required and optional fields and the JSON type each field takes (`string`, `bool`, or `any` for a field such as `value` that takes any JSON value) instead of editing. It takes no project or operations file. The text output marks operations that accept a standard element with `*`. It also lists the names `setProjectProperty` sets, with their value type and allowed values. With `--json` it prints `{ "version": 1, "projectProperties": [ { "name": "FontGenerator", "type": "string", "allowed": ["BmFont", "KernSmith"], "description": "..." } ], "operations": [ { "op": "setVariable", "standardElements": true, "required": [ { "name": "element", "type": "string" }, ... ], "optional": [ ... ] } ] }`.

## The Operations File

```json
{
  "version": 1,
  "operations": [
    { "op": "addComponent", "name": "Hud" },
    { "op": "addInstance", "element": "Hud", "name": "Score", "type": "Text" }
  ]
}
```

`version` is the file format version, which is `1`. Each entry in `operations` names its operation in `op` and runs in order. An unknown `version`, `op` or field is an error.

`element` names a Screen, Component or standard element, including its folder, such as `Controls/Counter` or `Text`.

## Standard Elements

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

`addState`, `addCategory`, `setVariable`, `clearVariable`, `removeState` and `removeCategory` also edit a standard element such as `Text` or `Sprite`, like editing it in the tool. A new project's `Text` has no categories, so the example first adds a `ColorCategory`, then a `Gold` state in it.

```json
{ "op": "addCategory", "element": "Text", "name": "ColorCategory" }
{ "op": "addState", "element": "Text", "name": "Gold", "category": "ColorCategory" }
{ "op": "setVariable", "element": "Text", "name": "Red", "value": 255, "state": "Gold", "category": "ColorCategory" }
```

A standard element has no instances, custom variables or variable references, so the other operations that take an `element` fail on one and name the Screen or Component to use instead. A standard element cannot be added or removed.

### addScreen and addComponent

```json
{ "op": "addScreen", "name": "GameScreen" }
{ "op": "addComponent", "name": "Controls/Counter", "baseType": "Text" }
```

`baseType` applies only to `addComponent`. It is optional and defaults to `Container`.

When `baseType` is a component, the new component gets a copy of each of its instances marked as defined by the base, as the tool does when you pick a base type. You can then `setVariable` and `clearVariable` on those instances.

### addInstance

```json
{ "op": "addInstance", "element": "Hud", "name": "Counter1", "type": "Controls/Counter", "parent": "Stack" }
```

`parent` is optional and names another instance in the same element.

Components that derive from `element` get a copy of the new instance.

### addVariable

```json
{ "op": "addVariable", "element": "Hud", "name": "Score", "type": "int", "value": 0 }
```

Adds a new variable to a Screen or Component, like **Add Variable** in the **Variables** tab. `type` is `float`, `int`, `string` or `bool`. `value` is optional.

### setVariable

```json
{ "op": "setVariable", "element": "Hud", "name": "Counter1.Text", "value": "0" }
{ "op": "setVariable", "element": "Hud", "category": "Size", "state": "Big", "name": "Width", "value": 200 }
```

Sets a variable the element already has. [describe](https://docs.flatredball.com/gum/cli/cli/describe.md) lists the names it accepts. An instance's variable is written `InstanceName.VariableName`. A path through nested instances, such as `HudInstance.Bar.Visible`, fails, because an element stores values only for its own instances. Set `Bar.Visible` on the `Hud` component instead, which changes it in every `Hud`. Without `state`, the value goes in the default state. `state` alone names an uncategorized state, and `category` with `state` names a state in a category. A reference that reads the changed variable is updated too, in the element's other states and in other elements, as in the tool.

A Forms control's behavior properties, such as a Slider's `Minimum`, `Maximum` and `Value` or a CheckBox's `IsChecked`, are the rows in the tool's **Behavior** category, and `setVariable` sets them the same way: `VolumeSlider.Maximum` with `10`, or `Maximum` on a component derived from the Slider. The value takes the property's type, such as a number, `true` or `false`, or an enum's name. A property the element's behaviors do not declare fails.

Enum values such as `ChildrenLayout` take the value's name, for example `"TopToBottomStack"`. A category's state variable, such as `SizeState`, takes the state's name.

{% hint style="warning" %}
`setVariable` only sets variables the element's type defines. To create a new variable, use `addVariable`.
{% endhint %}

### addCategory and addState

```json
{ "op": "addCategory", "element": "Hud", "name": "Size" }
{ "op": "addState", "element": "Hud", "category": "Size", "name": "Big" }
```

`category` is optional on `addState`. Without it, the state is uncategorized.

A derived component edits only its own categories, as in the tool's State tab. Naming a category that comes from the base type fails and names the base; make the edit on the base.

### exposeVariable

```json
{ "op": "exposeVariable", "element": "Hud", "instance": "Counter1", "variable": "Text", "name": "Counter1Text" }
```

Exposes `Counter1.Text` on `Hud` as `Counter1Text`, so instances of `Hud` can set it. The op fails if `name` is already a variable or property of `Hud`, such as `Width` or `Name`, ignoring case.

### addBehavior

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

```json
{ "op": "addBehavior", "element": "MyButton", "behavior": "ButtonBehavior" }
```

Makes a Component implement a behavior, like checking it in the **Behaviors** tab: it adds the reference and copies the behavior's categories and their states into the component, creating the ones it lacks. The behavior must already be in the project (for example after `add-forms`). The op fails if the project has no behavior of that name (the message lists the project's behaviors), if `element` is a Screen, or if the component already has the behavior. Required instances are not added, the same as in the tool, so a behavior that requires instances needs its own `addInstance` ops; `check` reports any that are missing.

## Reordering

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

Instance order is draw order: the last instance draws in front. State order is the order the tool lists the states in.

```json
{ "op": "moveInstance", "element": "Hud", "name": "Panel", "toFront": true }
{ "op": "moveInstance", "element": "Hud", "name": "Panel", "before": "Label" }
{ "op": "moveState", "element": "Hud", "category": "Size", "name": "Big", "after": "Small" }
{ "op": "moveState", "element": "Hud", "category": "Size", "name": "Big", "toCategory": "Mood" }
```

Give exactly one position: `before` or `after` naming a sibling, or `toFront` / `toBack` for an instance and `toStart` / `toEnd` for a state. `moveInstance` orders against siblings that share a parent, and an instance defined in a base element cannot be moved; components that derive from `element` follow the new order. A variable reference that reads `Index` is not recalculated, so open the project in the tool after reordering.

`moveState` takes `category` for the category the state is in (leave it out for an uncategorized state). With `toCategory` the state moves to that category's end, or to the `before` / `after` position, and the category's variables are added to it as in the tool. Uncategorized states can be reordered but not moved into a category, the default state stays first, and a state a behavior needs cannot change category.

## Removing

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

The remove operations take out what the tool's delete commands take out, including the values other elements set for what is removed. A remove the tool refuses fails the edit with the tool's message.

### removeScreen and removeComponent

```json
{ "op": "removeScreen", "name": "Game" }
{ "op": "removeComponent", "name": "Controls/Hud" }
```

Removes the element from the project and deletes its file, like the tool's delete with **Delete file** checked. A removed component is also dropped from the project's favorites. `name` includes the folder. A component that another element still uses, as an instance or as its base type, cannot be removed: the edit fails and reports what uses it.

### removeBehavior

```json
{ "op": "removeBehavior", "element": "MyButton", "behavior": "ButtonBehavior" }
```

Takes the behavior off a Component. Like unchecking it in the **Behaviors** tab, it leaves the categories and states the behavior added, which the component may now use for itself. The op fails if the component does not have the behavior.

### removeInstance

```json
{ "op": "removeInstance", "element": "Hud", "name": "Panel" }
```

Removes the instance and every variable that sets or names it. Its children move to the instance's own parent, like the tool's default **Delete only parent(s)**. An instance defined in a base element cannot be removed.

The copy in each component that derives from `element` is removed too.

### removeState and removeCategory

```json
{ "op": "removeState", "element": "Hud", "category": "Size", "name": "Big" }
{ "op": "removeCategory", "element": "Hud", "name": "Mood" }
```

`category` is optional on `removeState`. Variables that set the removed state, in this element or others, are removed so they fall back to their inherited value. The default state, and a state or category a behavior needs, cannot be removed.

### removeVariable

```json
{ "op": "removeVariable", "element": "Hud", "name": "Score" }
```

Removes a variable added with `addVariable`, and the values instances set for it. A variable used by a variable reference cannot be removed.

### unexposeVariable

```json
{ "op": "unexposeVariable", "element": "Hud", "name": "Counter1Text" }
```

Un-exposes the variable `Hud` exposes as `Counter1Text`, like the tool's **Un-expose Variable** with **Un-expose and clear values**. Gum removes the values other elements set for `Counter1Text`, and `Counter1.Text` keeps its own value. The op fails if a variable reference uses `Counter1Text`.

### clearVariable

```json
{ "op": "clearVariable", "element": "Hud", "name": "Width" }
{ "op": "clearVariable", "element": "Hud", "category": "Size", "state": "Big", "name": "Width" }
```

Removes a set value so the variable falls back to its inherited value, like **Make Default** in the **Variables** tab. `name`, `state` and `category` work as in `setVariable`. An exposed variable stays exposed. A variable added with `addVariable` goes back to its type's zero value, such as `0` or `false`. In a category state the variable takes the default state's value instead, since every state in a category sets it. References that read the variable are updated like they are after `setVariable`.

## Renaming

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

The rename operations run the tool's rename, so everything that names the old name follows: base types, instance types, `Parent` values, variables set on the renamed thing, state selectors on other elements, [variable references](#variable-references) lines, exposed variables, favorite components, and the element's animation (`.ganx`) and code settings (`.codsj`) files. Generated code is not moved; run [codegen](https://docs.flatredball.com/gum/cli/cli/codegen.md) with `--prune` afterward. A rename the tool refuses, or that leaves a reference dangling, fails the edit.

```json
{ "op": "renameElement", "name": "Card", "newName": "Controls/Panel" }
{ "op": "renameInstance", "element": "Hud", "name": "Title", "newName": "Heading" }
{ "op": "renameState", "element": "Toggle", "category": "OnOff", "name": "On", "newName": "Enabled" }
{ "op": "renameCategory", "element": "Toggle", "name": "OnOff", "newName": "Power" }
{ "op": "renameVariable", "element": "Hud", "name": "Score", "newName": "Points" }
{ "op": "renameBehavior", "name": "Selectable", "newName": "Pickable" }
```

* `renameElement` renames a Screen or Component. A `/` in `newName` moves it to that folder, and its file moves with it. A rename that changes only letter case is refused, because file systems that ignore case cannot do it in one step.
* `renameInstance` renames the instance in its element and in the elements that inherit it. An inherited instance is renamed on the element that defines it.
* `renameState` and `renameCategory` work on Screens and Components; standard elements are refused. `category` is omitted for an uncategorized state. The default state cannot be renamed, and a category that one of the component's behaviors requires cannot be renamed.
* `renameVariable` renames a custom variable everywhere it is set, or, for an exposed variable, its exposed name.
* `renameBehavior` renames a behavior and its file. A standard Forms behavior, and a behavior stored outside the project's `Behaviors` folder, are refused.
* A file cannot mix `renameElement`, `renameInstance`, `renameState` or `renameCategory` with the animation operations, because both change the element's animation file. Run the renames in one `edit` and the animation operations in another.

## Creating a Component From an Instance

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

### extractToComponent

```json
{ "op": "extractToComponent", "element": "Hud", "instance": "Panel", "name": "Controls/PanelComponent", "replace": true }
```

Makes a new component from `Panel`, like **Create Component** in the tool's right-click menu. The component's base type is `Panel`'s type, the instances attached to `Panel` become its instances, and the variables `Panel` sets, other than its position, become the component's. The attached instances keep their positions, which were already relative to `Panel`.

`replace` is the tool's checkbox. With `true`, `Panel` and the instances attached to it leave `Hud`, and an instance of the new component named `Panel` takes its place, with the same position and draw order. Values other states set on `Panel` stay on the new instance. Values, variable references and exposed variables that named one of the attached instances are removed, and a removed variable reference leaves its last value behind. With `false`, `Hud` does not change.

## Variable References

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

### setVariableReferences

```json
{ "op": "setVariableReferences", "element": "SegmentBar", "instance": "Total", "lines": [ "Width = TotalHealth * 4" ] }
{ "op": "setVariableReferences", "element": "SegmentBar", "lines": [ "Height = Total.Width" ] }
```

Replaces the variable references of `Total`, or of `SegmentBar` itself when `instance` is left out, like typing them in the **Variable References** box. Gum checks each line the way the tool does and writes the values the lines set, so `Total.Width` becomes `40` when `TotalHealth` is `10`. Gum also updates other states and elements whose references read a changed value. On a Forms control instance, the control's own values win over a line that sets its visual state, as in the tool: on a button whose `IsEnabled` is at its default, a line that sets `ButtonCategoryState` stores no value. A line that does not parse, names a variable that does not exist, or has a right side of the wrong type fails the edit with the line and the reason. `state` and `category` work as in `setVariable`. An empty `lines` list removes the references and leaves the values they set.

## Base Types and Instance Flags

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

### setBaseType

```json
{ "op": "setBaseType", "element": "Controls/Counter", "baseType": "Container" }
{ "op": "setBaseType", "element": "Hud", "instance": "Score", "baseType": "Sprite" }
```

Changes the base type of `element`, or the type of its instance `instance`, like picking another **Base Type** in the **Variables** tab. Gum removes the variables, variable lists and variable reference lines the new type does not define, in every state, and the values other elements set for an exposed variable that goes. Variables on elements that inherit from `element` stay as hidden leftovers, as in the tool. A Component that changes base type swaps its inherited instances for the new base's. An instance whose type changes changes the same way in every component that inherits it.

The op fails, naming what to change, when `baseType` is not a Screen, Component or standard element in the project, would create a circular reference, or is empty for a Component or an instance. A Screen can derive only from another Screen, and `""` clears its base. A Component cannot derive from a Screen, and an instance cannot be a Screen. An instance that `element` inherits from its base cannot change type here; change it in the base. A standard element has no base type. The op does not apply a project's engine profile restrictions, so it can pick a type the tool's picker hides.

### setInstanceProperty

```json
{ "op": "setInstanceProperty", "element": "Controls/Panel", "instance": "Body", "property": "IsSlot", "value": true }
{ "op": "setInstanceProperty", "element": "Hud", "instance": "Background", "property": "Locked", "value": true }
```

Sets the **Locked** or **Is Slot** flag of an instance, like the same rows in the **Variables** tab. `Locked` keeps the instance from being selected by clicking in the editor. `IsSlot` marks a place that holds children when the component is used, and only an instance in a Component can have it. An instance the component inherits from its base cannot change here, like its type; change it in the base. Any other `property` fails the edit.

## Project Properties

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

### setProjectProperty

```json
{ "op": "setProjectProperty", "name": "DefaultCanvasWidth", "value": 256 }
{ "op": "setProjectProperty", "name": "TextureFilter", "value": "Point" }
{ "op": "setProjectProperty", "name": "LocalizationFiles", "value": ["Localization/strings.csv"] }
{ "op": "setProjectProperty", "name": "FontRanges", "value": "32-126,160-255,1024-1279" }
{ "op": "setProjectProperty", "name": "FontGenerator", "value": "KernSmith" }
```

Sets a project property, like the **Canvas**, **General**, **Localization** and **Fonts** pages of the tool's **Project Properties**. `edit --schema` lists every name with its value type and, for a fixed set, the allowed values. Any other name fails the edit, and the message lists the names it accepts.

| Name                                                                                                     | Value                                                                                                               |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `DefaultCanvasWidth`, `DefaultCanvasHeight`                                                              | Positive whole number.                                                                                              |
| `TextureFilter`                                                                                          | `"Point"` or `"Linear"`.                                                                                            |
| `RestrictToUnitValues`, `RestrictFileNamesForAndroid`                                                    | `true` or `false`.                                                                                                  |
| `EngineProfile`                                                                                          | Path of the `.gumengine` profile, or `""` for none.                                                                 |
| `LocalizationFiles`                                                                                      | Array of CSV or RESX paths. It replaces the list, and `[]` clears it.                                               |
| `CurrentLanguageIndex`                                                                                   | Whole number from 0, the language to start in.                                                                      |
| `ShowLocalizationInGum`                                                                                  | `true` or `false`.                                                                                                  |
| `FontRanges`                                                                                             | Project-wide character ranges such as `"32-126,160-255"`. Spaces are removed, and a malformed range fails the edit. |
| `FontGenerator`                                                                                          | `"BmFont"` or `"KernSmith"`.                                                                                        |
| `FontSpacingHorizontal`, `FontSpacingVertical`                                                           | Whole number from 0.                                                                                                |
| `AutoSizeFontOutputs`                                                                                    | `true` or `false`.                                                                                                  |
| `SinglePixelTextureFile`                                                                                 | Path of an image, or `""` for none.                                                                                 |
| `SinglePixelTextureLeft`, `SinglePixelTextureTop`, `SinglePixelTextureRight`, `SinglePixelTextureBottom` | Whole number from 0, or `null` for the whole image.                                                                 |

Paths are stored relative to the project file with forward slashes, so an absolute path works. A path is not checked to exist, so create the file first or run [check](https://docs.flatredball.com/gum/cli/cli/check.md) afterward. Set `FontRanges` before running [fonts](https://docs.flatredball.com/gum/cli/cli/fonts.md), which bakes with the new ranges. `SinglePixelTexture*` is read only by the tool's canvas, but [pack](https://docs.flatredball.com/gum/cli/cli/pack.md) bundles the texture file. The edit writes forward slashes in path lists, so a list the tool wrote with backslashes can end up with mixed separators when only some entries are replaced.

`UseFontCharacterFile` (it reads a `.gumfcs` file in the tool) and `FontRangeEntries` (per-font ranges, edited on the tool's **Fonts** page) are refused with a message naming `FontRanges` instead. Editor-only view settings such as outlines and the checkerboard are not set.

## Animations

{% hint style="info" %}
Available in December 2026, or now if building Gum from source.
{% endhint %}

Animations are saved beside the element in its animations file (`HudAnimations.ganx`, or `.ganj` in a `.gumj` project), the same file the **Animations** tab writes. These operations change that file and leave the element file alone. A file left with no animations is deleted, as in the tool.

### addAnimation and removeAnimation

```json
{ "op": "addAnimation", "element": "Popup", "name": "FadeIn", "loops": false }
{ "op": "removeAnimation", "element": "Popup", "name": "FadeIn" }
```

Adds an empty animation, like **Add Animation**. `loops` is optional and defaults to `false`. The name follows the tool's rules: it cannot be empty, contain spaces, repeat another animation's name, or match an instance, category or exposed variable on the element. `removeAnimation` fails when the element has no animation with that name.

### setAnimationLoops

```json
{ "op": "setAnimationLoops", "element": "Popup", "animation": "FadeIn", "loops": true }
```

Turns looping on or off for an existing animation.

### addKeyframe and removeKeyframe

```json
{ "op": "addKeyframe", "element": "Popup", "animation": "FadeIn", "state": "Visibility/Hidden", "time": 0 }
{ "op": "addKeyframe", "element": "Popup", "animation": "FadeIn", "state": "Visibility/Shown", "time": 0.5, "interpolation": "Exponential", "easing": "In" }
{ "op": "removeKeyframe", "element": "Popup", "animation": "FadeIn", "state": "Visibility/Hidden", "time": 0 }
```

Adds a keyframe that moves the element to a state at `time` seconds. `state` is `Category/State` for a state in a category, or the bare name for an uncategorized state. The state must exist, so add it first with `addState`, in the same file if you like. `time` is 0 or more. `interpolation` and `easing` are optional and default to `Linear` and `Out`, the tool's defaults; any other name fails the edit and the message lists the valid names. Keyframes stay in time order whatever order you add them in. A second keyframe for the same state at the same time fails. `removeKeyframe` finds the keyframe by its `state` and `time`.

Removing a state that a keyframe uses fails the edit with the same error [check](https://docs.flatredball.com/gum/cli/cli/check.md) reports. Sub-animation keyframes and named events are not available in `edit`; add them in the **Animations** tab.

## All or Nothing

`edit` writes nothing unless every operation applies and the edit adds no errors. It runs the same check as [check](https://docs.flatredball.com/gum/cli/cli/check.md) before and after the operations. Errors the project already had do not block the edit, and only errors the edit adds are reported, in the same format as `check`.

## Examples

```
gumcli edit MyProject/MyProject.gumj changes.json
gumcli edit MyProject/MyProject.gumj changes.json --json
```

Output on success:

```
No errors found.
Saved /full/path/to/MyProject/MyProject.gumj
```

An operation that cannot apply prints its position in the list to stderr:

```
error: operations[3] (setVariable): Hud has no variable named Widht.
```

## Exit Codes

| Code | Meaning                                                               |
| ---- | --------------------------------------------------------------------- |
| 0    | The project was saved                                                 |
| 1    | An operation could not apply, the edit added errors, or saving failed |
| 2    | The project could not be loaded, or the operations file is not valid  |


---

# 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/gum/cli/cli/edit.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.
