Skill and Scripts
Give Claude Code or another agent the Mode 8 skill, and drive the CLI from scripts and agents with JSON reports, stable exit codes and error types.
An agent can drive Mode 8 two ways: through the MCP server, or by running mode8 commands in a shell and reading their JSON reports. Either way it does better with the skill, a short guide written for agents: when to use Mode 8, the order of the pipeline, and what to do after each result. This page installs the skill, then covers what a script or an agent needs to know about the CLI.
Install the skill#
The skill is SKILL.md at the root of the Mode 8 repository, plus the reference files in skill/ that it tells the agent to open when a task needs them. For Claude Code, copy both into your skills folder:
mkdir -p ~/.claude/skills/mode8
cp -r ~/mode8/SKILL.md ~/mode8/skill ~/.claude/skills/mode8/Other agents that read skill files (Codex and others) take the same files; put them wherever that agent looks for skills. Copy them again after you update Mode 8, so the agent's knowledge matches the installed version.
JSON for programs, a summary for people#
On a terminal every command prints a short summary. When its output goes to a pipe or a file, which is what an agent's shell is, the same command prints exactly one JSON object on stdout instead. --json and --human force one or the other, anywhere on the command line, and MODE8_FORMAT=json changes the default. The examples on this page pass --json so you see what an agent sees.
$ mode8 draft knight_right --out hero.png --json
{"ok": true, "out": "hero.png", "archetype": "knight_right", "size": [64, 72]}A report always starts with "ok": true, followed by the command's own keys. The only commands that print no report are the two servers, mode8 mcp and mode8 studio (which prints one ready line).
Exit codes#
Every command ends with one of four exit codes. They never change meaning:
| Exit | Meaning | What to do |
|---|---|---|
0 | Done, and every check it ran passed. | Carry on. |
1 | It ran, but a check failed: the report says "pass": false. | Read the report's errors, fix the art or the setup, run it again. |
2 | Your input is wrong: an unknown flag, a bad value, a missing file. Nothing was written. | Fix the command. Never retry it unchanged. |
3 | Something outside your input failed: ComfyUI, the disk, a file someone else just changed. | Read error.type; retry only a backend that was busy or restarting. |
A check that fails still prints a full report with "ok": true, because the command itself worked. Here the sprite is 64x72 and the check expects 48x48:
$ mode8 lint hero.png --size 48x48 --json
{
"ok": true,
"file": "hero.png",
"size": [64, 72],
"pass": false,
"errors": [{"rule": "size", "msg": "image is 64x72, expected 48x48"}],
"warnings": [],
"metrics": {"opaque_pixels": 1507, "colors": 15, "components": 1}
}The commands that can exit 1 are the ones that check something: lint, verify, doctor, gen, inpaint and cast (when no candidate passes), autotile and ui (their own checks), init --template and setup. The full wording is in the schema:
$ mode8 schema --section exit_codes
{
"exit_codes": {
"CHECK_FAILED": {
"code": 1,
"description": "The command ran but a check it reports failed (lint, quality-strict, verify, doctor, gen, inpaint, cast, autotile, ui lint, starter lint, setup download); stdout holds the full JSON report, whose top-level \"pass\" is false."
},
"OK": {
"code": 0,
"description": "The command succeeded (and every check it reports passed); stdout holds its JSON report with \"ok\": true."
},
"RUNTIME": {
"code": 3,Show 14 more lines
"description": "A runtime or backend error (IO, ComfyUI, ConflictError, ProjectVersionError, LayeredAssetError, unexpected exceptions); stdout holds {\"ok\": false, \"error\": {\"type\", \"msg\", ...}}. Also used when stdout is closed early (e.g. `mode8 ... | head`): output stops silently, with no traceback."
},
"USAGE": {
"code": 2,
"description": "Bad input. Either an invalid command line (argparse usage error; nothing ran): stdout holds {\"ok\": false, \"error\": {\"type\": \"UsageError\", \"msg\", \"usage\"}} and the human message goes to stderr; or an invalid user-supplied value (format, palette, name, size, margins, color, scale, pixels_per_unit, emissive token, template, kind / style, fps, conflicting options, init config conflict, malformed JSON input file): stdout holds {\"ok\": false, \"error\": {\"type\": \"InputError\", \"msg\", ...}}; a missing input path, project, asset or layer is the InputError subclass NotFoundError ({\"type\": \"NotFoundError\", \"msg\", \"path\"?})."
}
},
"mode8_version": "1.0.0",
"ok": true,
"schema_version": 1,
"sections": [
"exit_codes"
]
}Errors#
When a command cannot do its job, it prints the error envelope instead of a report: "ok": false and an error with a type and a msg. On a terminal a person gets the short form on stderr; a program reads the envelope on stdout. This command asks for an archetype that does not exist (2>/dev/null hides the usage text a terminal would also show):
$ mode8 draft knight --out hero.png --json 2>/dev/null
{
"ok": false,
"error": {
"type": "UsageError",
"msg": "argument ARCHETYPE: invalid choice: 'knight' (choose from 'humanoid_right', 'humanoid_left', 'quadruped_left', 'quadruped_right', 'boss_quadruped_left', 'boss_quadruped_right', 'flyer', 'shrine', 'slime', 'knight_right', 'knight_left', 'adventurer_right', 'adventurer_left', 'topdown_hero', 'portrait_bust', 'isometric_block', 'isometric_tower', 'mech_right', 'mech_left', 'starfighter')",
"usage": "usage: mode8 draft [-h] [--pose POSE] [--source IMAGE] [--palette PALETTE]\n [--size WxH] [--colors N] [--key-color #RRGGBB] --out PNG\n [--json | --human] [-q]\n [ARCHETYPE]",
"suggestions": ["knight_right", "knight_left"]
}
}Branch on error.type, never on the wording of msg, which is written for people and may change. The types, with their exit codes:
error.type | Exit | What to do |
|---|---|---|
UsageError | 2 | The command line does not parse. error.usage has the right shape and error.suggestions the closest names. |
InputError | 2 | A value is wrong or over a limit; error.param names it when it can. |
NotFoundError | 2 | A file, project, asset, layer or palette is missing (error.path, error.asset). |
AssetExistsError | 2 | The asset name is taken. Choose another name or edit the asset. |
NothingToUndoError, NothingToRedoError | 2 | Check can_undo and can_redo first. |
ConflictError | 3 | The file changed since you read it. Read it again and redo your edit on the new version. |
LayeredAssetError | 3 | The asset has layers: edit one layer, not the master. |
ProjectVersionError | 3 | A newer Mode 8 wrote this project. Update Mode 8. |
BackendError | 3 | ComfyUI is not reachable or failed. error.hint and error.start_command say what to do. |
Many errors also carry a hint: one sentence on what to do next. Troubleshooting shows each error and its fix, and Output envelope lists every extra key.
The schema is the source of truth#
mode8 schema prints the whole surface of the installed version as one JSON document: every command and flag with its type, default and choices, every MCP tool and parameter, the exit codes, the export formats, the project format, the Studio routes and the limits. --section picks one of cli, mcp, exit_codes, formats, project, http or limits. An agent that reads the schema instead of remembering flags never calls a flag that is not there, and the reference pages of this manual are generated from it.
Habits that keep scripts reliable#
- Pass
--jsonin scripts, even though a pipe already gets JSON. A script run from a terminal with its output on screen would otherwise get the summary. - Read keys, not text. A report gains keys in new releases and never loses a documented one, so ignore keys you do not know.
- Re-run freely. Drafts, tiles, rigs, palette swaps, effects, UI kits, fonts and exports give the same pixels for the same input, so a script can rebuild everything and diff it. Only generation depends on a seed: pass
--seedto repeat agenrun. - Write into projects through Mode 8.
mode8 layers,mode8 importand the MCP project tools record every edit in the journal and refuse to overwrite a file that changed; writing PNGs intoassets/with another program skips both. See Co-editing. - Check the version when you need a feature:
mode8 --version, ormode8_versionin the schema.
Next#
- MCP server: the same tools without a shell.
- Co-editing: an agent and a person on the same files.
- Troubleshooting: every error, as you will see it.