# CLI and Local Emulator

Every glint command: init, preview with the Local Emulator and Multi-Player Room Lab, validate with its full error and warning code table, and upload.

The `glint` command ships in the `@joinfoundry/glint-sdk` package. It scaffolds starters, runs your build in a Local Emulator with Glint's sandbox, and checks a build against Glint's rules before you upload it.

## Install and Update the CLI

The CLI needs Node.js 20 or later. Update to the latest `@joinfoundry/glint-sdk` release before you start a build or upload one:

```bash
# Check latest published version on npm
npm view @joinfoundry/glint-sdk version

# Install or update globally
npm install --global @joinfoundry/glint-sdk@latest
glint help
```

Without a global install, this runs the latest release from any folder and skips any stale `npx` cache:

```bash
npx --yes --prefer-online -p @joinfoundry/glint-sdk@latest glint <command>
```

In a project that has `@joinfoundry/glint-sdk` as a dependency, update it with `npm install @joinfoundry/glint-sdk@latest`, after which `npx glint <command>` runs that local copy. Because `@joinfoundry/glint-sdk` is scoped, bare `npx glint` fails in folders where the package isn't installed.

```text
glint init [template] [dir]
glint preview [dir] [--port <port>] [--players <n>] [--advanced]
glint validate [dir|zip] [--json]
glint games [--token <fdy_...>] [--api <url>] [--json]
glint publish [dir|zip] [--inspect | --interactive | --create | --game <id|slug>] [options]
glint upload [dir|zip] --game <id|slug> [--token <fdy_...>] [--slot build|demo] [--notes <text>] [--content-changed true|false] [--no-wait] [--json]
```

Flags take a value after a space or an equals sign: `--port 5000` or `--port=5000`.

## `init`

```bash
glint init [template] [dir]
```

Copies a starter into `dir` (default: the current folder) and adds `glint.js`, the browser build of the SDK. For `unity`, that file goes into `WebGLTemplate/`. Files with the same names in `dir` are overwritten, so scaffold into a new folder if you're unsure. The template defaults to `vanilla-ts`.

| Template | Files | Next step |
| --- | --- | --- |
| `vanilla-ts` | `index.html`, `main.js`, `glint.json` | `glint preview <dir>` |
| `multiplayer-ts` | `index.html`, `main.js`, `glint.json` | `glint preview <dir> --players 2` |
| `phaser` | `package.json`, `vite.config.ts`, `index.html`, `src/main.ts`, `glint.json` | `npm install`, `npm run build`, then preview `dist` |
| `threejs` | Same layout as `phaser` | Same as `phaser` |
| `kaplay` | Same layout as `phaser` | Same as `phaser` |
| `godot` | `Glint.gd`, `export_presets.cfg`, `foundry-shell.html`, `glint.json` | See [Godot 4.3+](https://joinfoundry.xyz/help/developers/glint-sdk-godot) |
| `unity` | `Glint.jslib`, `Glint.cs`, `WebGLTemplate/index.html`, `glint.json` | See [Unity WebGL](https://joinfoundry.xyz/help/developers/glint-sdk-unity) |

The Vite starters need a build before you preview them, because their `index.html` loads TypeScript source. See [Web Engines](https://joinfoundry.xyz/help/developers/glint-sdk-web-engines).

## `preview`

```bash
glint preview [dir] [--port <port>] [--players <n>] [--advanced]
```

Starts the Local Emulator for the build in `dir` (default: the current folder) and prints its addresses. Open the Emulator address in your browser.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--port <port>` | `4173` | Port for the Emulator page. Your game is served from the next port up, as a separate origin. |
| `--players <n>` | `1` | How many player panes to open at the start, 1 to 4. |
| `--advanced` | Off | Serves the game and the Emulator with `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy`, as Glint does for [advanced mode](https://joinfoundry.xyz/help/developers/glint-sdk-platform-rules#advanced-mode-for-threads). It's also on when `capabilities.threads` is `true` in `glint.json`. |

With the defaults, the Emulator is at `http://127.0.0.1:4173` and your game at `http://127.0.0.1:4174`. Your files are served with Glint's production Content Security Policy and caching turned off, so reload after each change. The entry page comes from `entry` in `glint.json`, or `index.html`.

If the build folder has no `glint.js`, the Emulator serves the package's own copy. Glint doesn't, so make sure the file is in your build if `index.html` loads it.

### Multi-Player Room Lab

Each pane is a separate player (Player 1, Player 2 and so on) with its own SDK connection. The toolbar works on every pane at once:

| Control | What it does |
| --- | --- |
| Mute | Toggles master mute, firing `sdk.system.onMuteChange`. |
| Pause / Resume | Pauses with reason `host_overlay`, then resumes. |
| + Spawn Player | Opens another pane. Its `getPendingInviteCode()` returns the most recent room code, so a game that joins pending invites joins that room. |
| Drop Room Host | Closes the current host's connection to test host migration. |
| Mode | Switches the meter between Free (5h/mo), Demo (15m), Owned and Glint Pass, firing `sdk.meter.onUpdate`. |
| Latency | Adds 0, 60 or 150 ms to room messages. |
| Signed-in | Whether panes opened from now on start signed in. |
| Clear Saves | Empties the Emulator's saves. |

The side panel shows the sandbox status, the current saves and unlocked achievements, and a log of SDK events such as `ready()`, saves, unlocks, score submissions and room changes. `openInviteDialog()` shows the room code in a toast.

### What the Emulator Simulates

- **Same as Glint:** the Content Security Policy, the frame's sandbox and permissions, a separate origin for your game, the SDK handshake, pause, mute and meter events, and the room message format, including binary frames and host migration.
- **Simplified:** saves, achievements and leaderboards live in memory, are shared by all panes and are cleared when the Emulator stops. Any achievement or leaderboard key works, defined in Glint Studio or not. `demo.isDemo()` is `true` for panes that start while Demo mode is selected. Meter times don't count down. `openPurchaseModal()` resolves with `{ purchased: false }`.
- **Not enforced:** the 15-second `ready()` limit, save slot and size limits, and the relay's rate and state size limits (the SDK's own 20-per-second and 4 KB checks on `send()` still apply). Locked rooms still accept joins, and `invite_only` rooms show up in quick join.
- **Different:** room codes are 6 characters instead of 4, and a message sent to `"all"` also comes back to its sender. On Glint, `"all"` reaches everyone except the sender.

## `validate`

```bash
glint validate [dir|zip] [--json]
```

Checks a build folder or ZIP (default: the current folder) without running it. Point it at the build output, such as `dist`, not your source folder: source files like `.ts` fail the file type check. When validating a folder, `node_modules` and `.git` are skipped.

The command exits with code 1 if there are errors, so you can use it in scripts and CI.

### Report

```text
Glint Build Validation: PASS
Target: /home/me/my-game
Files: 4 / 10000 | Est. Initial Boot: 0.01 MB | Est. Total: 0.01 MB
Performance Score: 100/100 | Loads Fast Badge: YES (<= 2 MB)
```

Errors (blocking) and Warnings (recommended) follow, one per line, with the code, the message and the file when there is one.

- **Est. Initial Boot** and **Est. Total** are compressed size estimates. How they're measured is in [Budgets](https://joinfoundry.xyz/help/developers/glint-sdk-platform-rules#budgets).
- **Performance Score** starts at 100 and loses 20 points per error, 5 per warning, 15 if the initial boot estimate is over 1.6 MB and 5 for more than 500 files.
- **Loads Fast Badge** is YES when there are no errors and the initial boot estimate is 2 MB or less.

Glint works out its own score and badge when you upload. See [Loads Fast and Performance Score](https://joinfoundry.xyz/help/developers/glint-sdk-platform-rules#loads-fast-and-performance-score).

### JSON Output

`--json` prints the full report as JSON instead, which suits scripts and AI agents.

```json
{
  "ok": true,
  "target": "/home/me/my-game",
  "fileCount": 5,
  "totalRawBytes": 41984,
  "estimatedTransferBytes": 9216,
  "estimatedInitialBootBytes": 6144,
  "loadsFast": true,
  "performanceScore": 95,
  "manifest": { "schemaVersion": 1, "name": "My Game", "version": "1.0.0" },
  "errors": [],
  "warnings": [
    { "severity": "warn", "code": "GL104", "message": "Found 1 .map source map file(s). Strip source maps from production builds to reduce size.", "file": null }
  ]
}
```

| Field | Meaning |
| --- | --- |
| `ok` | `true` when there are no errors. |
| `target` | The absolute path checked. |
| `fileCount` | Files counted, not including OS junk. |
| `totalRawBytes` | Uncompressed size of those files. |
| `estimatedTransferBytes` | Estimated compressed size of the whole build. |
| `estimatedInitialBootBytes` | Estimated compressed size of the initial boot payload. |
| `loadsFast` | The validator's Loads Fast result. |
| `performanceScore` | 0 to 100. |
| `manifest` | The parsed `glint.json`, or `null`. |
| `errors`, `warnings` | Findings, each with `severity` (`"error"` or `"warn"`), `code`, `message` and `file` (a path, or `null`). |

### Error and Warning Codes

Codes from GL001 to GL014 are mostly errors; codes from GL101 to GL104 are always warnings. GL003, GL004, GL005, GL012, GL013, GL014, GL102 and GL103 come from scanning `.html`, `.htm`, `.js`, `.mjs` and `.css` files up to 4 MB.

| Code | Severity | Meaning | How to fix it |
| --- | --- | --- | --- |
| GL001 | Error | The entry page (`index.html`, or the manifest's `entry`) isn't at the top level of the build. | Put `index.html` at the top level of the folder or ZIP, not inside a subfolder. |
| GL002 | Warning when `glint.json` is missing; error when it isn't valid JSON or a field is wrong | The manifest is missing or invalid. The message names the problem, such as an unknown property, `schemaVersion must be 1 or 2.` or `version must use semver format like "1.0.0".` | Add `glint.json` next to `index.html` and fix the field named. See the [Manifest Reference](https://joinfoundry.xyz/help/developers/glint-sdk-manifest). |
| GL003 | Error | A file loads something from an `http://` or `https://` address: a `src` or `href` attribute, `fetch()`, CSS `url()` or `importScripts()`. | Bundle the script, font or asset into the build and use a relative path such as `./assets/font.woff2`. |
| GL004 | Error | Code creates a `WebSocket`, `RTCPeerConnection` or `EventSource` directly. The sandbox blocks them. | Use `sdk.multiplayer` rooms for online play. |
| GL005 | Error | An HTML file uses a root-absolute path, such as `src="/main.js"` or `href="/style.css"`. It breaks under the build's path on Glint. | Use relative paths like `./main.js`. In Vite, set `base: "./"`. |
| GL006 | Warning over 1.6 MB; error over 30 MB | The estimated compressed initial boot payload is too large. | Load later levels, music and video after `ready()`, compress textures and audio, and strip unused engine modules. Aim for 2 MB or less. |
| GL007 | Error | The estimated compressed size of the whole build is over 500 MB. | Remove unused assets and compress textures, audio and video. |
| GL008 | Error | A single file is over 30 MB. | Split the file, or compress the asset inside it. |
| GL009 | Error | The build has more than 10,000 files. | Pack sprites into atlases and combine small data files. |
| GL010 | Error | A file has an unsupported extension, or none. | Remove source and tool files such as `.ts`, `.psd` or `.blend` from the build output. See [Supported File Types](https://joinfoundry.xyz/help/developers/glint-sdk-platform-rules#supported-file-types). |
| GL011 | Warning | OS archive junk was found: `.DS_Store`, `__MACOSX`, `Thumbs.db` or `._` files. | Delete them before zipping. Glint ignores them, but they waste upload size. |
| GL012 | Error when `SharedArrayBuffer` or `Atomics.wait` is used without `"capabilities": { "threads": true }`; warning when `threads` is `true` but nothing uses them | The build's thread use and its manifest don't match. | Use a single-threaded export (recommended), or set `capabilities.threads` to `true` only if the game needs threads. |
| GL013 | Error when `multiplayer.online.enabled` is `true`; otherwise warning | No SDK integration was found: no `Glint.init`, `@joinfoundry/glint-sdk` or SDK handshake in any scanned file. | Load `./glint.js` or import `@joinfoundry/glint-sdk`, call `Glint.init()` and call `sdk.lifecycle.ready()`. |
| GL014 | Warning | Online multiplayer is enabled, but no `room.onHostChange` handler was found. | Register `room.onHostChange((newHostId, isSelfHost) => ...)` so matches survive a host leaving. See [Host Migration](https://joinfoundry.xyz/help/developers/glint-sdk-api#host-migration). |
| GL101 | Warning | A `.wav` file (or `.bmp` image) is larger than 256 KB. | Convert audio to OGG or MP3, and images to WebP. |
| GL102 | Warning | A file reads `window.devicePixelRatio` without `Math.min(` or `maxDpr` anywhere in the same file. | Clamp the pixel ratio to `Math.min(2, sdk.system.getHints().maxDpr)`. |
| GL103 | Warning | A file calls `localStorage.getItem` or `localStorage.setItem`. Every game on Glint shares the same origin, so other games can read it. | Keep progress in `sdk.saves`. A build that bundles the SDK from npm into its own script also shows this warning, because the SDK's standalone fallback uses `localStorage`; you can ignore it then. |
| GL104 | Warning | The build contains `.map` source map files. | Turn off source maps for production builds. In Vite, set `build.sourcemap: false`. |

## `games`

```bash
glint games [--token <fdy_...>] [--api <url>] [--json]
```

Lists the games you own or manage in Glint Studio, drafts and published, with each game's ID, slug, state, build status and Glint Studio URL. You need a Foundry personal token (`fdy_...`) with `marketplace:read` or `marketplace:write` access. Pass it with `--token` or set `FOUNDRY_API_TOKEN`. Create a token in [AI Agents settings](https://joinfoundry.xyz/workspace/agents).

## `publish`

```bash
glint publish [dir|zip] [options]
```

Creates a new Glint Studio draft or updates an existing game, uploads a 16:10 cover image and up to 8 screenshots if you give them, packages and uploads the build ZIP, and waits for Package X-Ray and Brotli repackaging. In a terminal, use `--interactive` to answer prompts. A coding agent runs `--inspect --json` first, then `publish` with flags and `--json`.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--inspect` | Off | Inspects the project's `glint.json`, build output, candidate cover/screenshot images (with pixel dimensions and 16:10 eligibility), and existing Glint Studio games without modifying anything. |
| `--interactive` | On in a terminal when you pass no `--create`, `--game`, `--inspect` or `--json` | Prompts step by step for a new or existing game, title, version, description, genres, controls, price, and whether to use a project image or upload one later in Glint Studio. |
| `--create` | Off | Creates a new Glint Studio draft game. |
| `--game <id\|slug>` | None | Updates an existing Glint Studio game by ID or slug. |
| `--title <title>` | Manifest name | Sets the game title and syncs `glint.json` when packaging a folder. |
| `--version <semver>` | Manifest version | Sets the semver version (such as `1.0.0`) in `glint.json` before zipping. |
| `--slug <slug>` | Auto from title | Sets the game's URL slug before first publish. |
| `--description <text>` | None | Sets the About text (at least 20 characters required to publish). |
| `--genres <g1,g2>` | None | Comma-separated list of 1 to 3 Glint genres. |
| `--controls <c1,c2>` | Manifest inputs | Comma-separated subset of `keyboard`, `gamepad`, `touch`. |
| `--orientation <mode>` | Manifest display | `landscape`, `portrait`, or `any`. |
| `--mobile-optimized <bool>` | `false` | Set `true` to add the **Optimized for Mobile** tag (the game stays playable on desktop). Also synced to `inputs.mobileOptimized` in `glint.json`. |
| `--price <value>` | `free` | `free`, a dollar price such as `4.99` (minimum `$0.50`), or integer cents. |
| `--cover <file>` | None | Local PNG, JPEG, WebP, or GIF image (must be 16:10, at least `640x400`, up to 10 MB). Checked locally before uploading. |
| `--skip-cover` | Off | Skips uploading a cover image so you can upload it manually in Glint Studio. |
| `--screenshots <f1,f2>` | None | Comma-separated list of up to 8 screenshot image files. |
| `--notes <text>` | None | Patch notes shown under "What's new" on the game page. |
| `--content-changed <bool>` | None | Required (`true` or `false`) when replacing a build on an already-rated game. |
| `--slot <build\|demo>` | `build` | Uploads to the main build or paid-game demo slot. |
| `--no-wait` | Wait enabled | Returns as soon as the upload finishes instead of waiting for inspection. |
| `--token <fdy_...>` | `FOUNDRY_API_TOKEN` | Personal token with `marketplace:write` scope from [AI Agents settings](https://joinfoundry.xyz/workspace/agents). |
| `--api <url>` | `https://api.joinfoundry.xyz` | API base URL. |
| `--json` | Off | Prints structured JSON output including `studioUrl` and `publishChecklist`. |

New games are created as drafts. Confirm your rights, answer the content rating questions, add any missing cover art and set up seller details for a paid game in Glint Studio. When you update a published game with `--content-changed false`, the new build goes live once inspection and Brotli repackaging pass.

## `upload`

```bash
glint upload [dir|zip] --game <id|slug> [--token <fdy_...>] [--slot build|demo] [--notes <text>] [--content-changed true|false] [--no-wait] [--api <url>] [--json]
```

Validates the build and stops if there are errors. It then zips a folder with standard compression, skipping `node_modules`, `.git` and OS junk, and uploads it in parts to an existing game's `build` or `demo` slot with a personal token that has `marketplace:write` access. It waits until Package X-Ray and Brotli repackaging finish, unless you pass `--no-wait`.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--game <id\|slug>` | Required | The game's ID or slug in Glint Studio. |
| `--token <fdy_...>` | `FOUNDRY_API_TOKEN` | A Foundry personal token with `marketplace:write` access. |
| `--slot` | `build` | `build` or `demo`. |
| `--notes <text>` | None | Optional patch notes published with the build. |
| `--content-changed <bool>` | None | Required when replacing a build on a rated game (`true` or `false`). |
| `--no-wait` | Wait enabled | Skip waiting for background inspection to complete. |
| `--api <url>` | `https://api.joinfoundry.xyz` | The API address. |
| `--json` | Off | Print structured JSON output. |
