---
title: The turnzero command
description: Use turnzero on your computer to deploy files, store a secret, run an application locally, or start a service, and read each command's outcome.
slug: /concepts/turnzero-command
order: 11
visibility: public
redirects_from: [/getting-started/the-provisioning-script, /concepts/the-turnzero-cloud-command, /concepts/turnzero-cloud-command, /concepts/the-turnzero-command, /guides/deploying-unattended]
---

# The turnzero command

Use `turnzero` on your computer to deploy apps, run them locally, store secrets, or start from a template. Read this page for the commands your AI coding agent runs and their results.

The [turnzero command reference](/cloud/reference/turnzero-command/) lists commands, options, and exit statuses.

## The lines your tool runs

| Command | Where it comes from | What it does |
| --- | --- | --- |
| `turnzero deploy --origin https://dev.turnzero.ai` | The `deploy_command` call's `command`, or `command_windows` on Windows | Checks the app, zips and uploads this folder, deploys and waits ([A deploy, from call to outcome](#a-deploy-from-call-to-outcome)). |
| `turnzero check --origin https://dev.turnzero.ai` | The `check_deploy` call's `command` | Checks the application and zip without uploading ([Checking a deploy](#checking-a-deploy)). |
| `turnzero login --origin https://dev.turnzero.ai` | You, once, in your own terminal | Authorizes this computer once you approve it in the browser ([Connect your AI assistant](/cloud/getting-started/connect-your-tool/#authorize-this-computer-for-deploys)). |
| `turnzero login --origin https://dev.turnzero.ai --device` | Your AI coding agent, with no terminal for you | Prints a link you approve on any device. |
| `turnzero authorize --origin https://dev.turnzero.ai` | Your signed-in AI coding agent, which reports the authorization | Authorizes this computer the AI coding agent's way, around one `mint_token` call. |
| `turnzero secret store --origin https://dev.turnzero.ai`, `turnzero secret rotate --origin https://dev.turnzero.ai` | The `store_secret` call that names no value, with `replace: true` for a replacement | Reads a file or hidden prompt on your computer and stores the value. The value never passes through your AI assistant ([Keep a secret value out of chat](/cloud/guides/supply-a-secret-value-without-exposing-it/)). |
| `turnzero provision --origin https://dev.turnzero.ai`, `turnzero run --origin https://dev.turnzero.ai` | Your own terminal. If `provision` prints a call, make that call and run the `--claim` command it returns. | `provision` writes local settings to `.env`. `run` starts the app with them ([Running on your machine](#running-on-your-machine)). |
| `turnzero scaffold --origin https://dev.turnzero.ai` | You write it | Writes a new application from a template; installs dependencies and runs tests where it has `package.json` ([Starting a new service](#starting-a-new-service)). |
| `turnzero library take --origin https://dev.turnzero.ai` | The `read_library` call's `download` | Takes one library entry into your project ([Use the feature package library](/cloud/guides/use-the-library/#3-add-an-entry-to-the-library-folder)). |

Your AI coding agent first runs `command_npx`, or `command_npx_windows` on Windows, once, exactly as returned. No global `turnzero` installation is needed. [Running and writing lines](#running-and-writing-lines) covers other forms and commands you write.

## A deploy, from call to outcome

Call `deploy_command` with the application ID, then run `command_npx`, or `command_npx_windows` on Windows. The installed form of the same command looks like this:

```text
turnzero deploy --origin https://dev.turnzero.ai --application 3f6c2a1e-8d4b-4c7a-9e21-5b0f7d9c4a13
```

That is `command`. `command_windows` is the same command with `turnzero.cmd` for `turnzero`. It contains no credential and reads nothing from standard input. It maps `local_path` to `--path` and another platform address to `--origin`. On an app with one environment, it maps `rotate_database_credential` to `--rotate-database-credential`.

Run the command once from the application folder, or from the base of a relative `local_path`. A successful `server-hello` deployment produces output like this:

```text
turnzero <version> (Node.js <version>)
zip: 8 files from /home/you/hello-world/app, 2731 bytes, sha256: <64 hexadecimal characters>
files: .gitignore, AGENTS.md, manifest.json, package-lock.json, package.json, src/, test/. The hash subcommand with --list names every file the zip holds.
prepared: upload 9b1e4c2a-6f3d-4e8b-a7c5-2d0f8e6b4a19 to production, its grant expiring at 2026-10-10T12:05:00.000Z
uploading: 2731 bytes as upload 9b1e4c2a-6f3d-4e8b-a7c5-2d0f8e6b4a19
uploaded: 2731 bytes as upload 9b1e4c2a-6f3d-4e8b-a7c5-2d0f8e6b4a19
started: {"contract_version":1,"summary":"Production is deploying version 1 (a deploy), in step pending_candidates, 0 seconds since it started; no version serves.","application":"3f6c2a1e-8d4b-4c7a-9e21-5b0f7d9c4a13","environment":"production","version":1,"state":"deploying","hostname":"hello-world-7k2m9q.ai.host","health_path":"/health",...}
step: pending_candidates at 0s
step: image_build at 1s, pending_candidates took 1s
step: slot_guard at 62s, image_build took 61s
step: platform_credential at 63s, slot_guard took 1s
step: declarations at 64s, platform_credential took 1s
step: realm_keys at 64s, declarations took 0s
step: pull_identity at 65s, realm_keys took 1s
step: compute_apply at 66s, pull_identity took 1s
step: shell_assets at 104s, compute_apply took 38s
step: health_gate at 105s, shell_assets took 1s
step: finish at 121s, health_gate took 16s
settled: deployed version 1
checked: the health path and any manifest smoke_paths requested with GET. List GET paths that change nothing in smoke_paths; each deploy or promote stops before switching on 404, 5xx or no answer. Check writes yourself; request other routes, then read read_status's server_errors and read_logs for errors.
read_status with application 3f6c2a1e-8d4b-4c7a-9e21-5b0f7d9c4a13 and environment production shows the deployment outcome. If a health check, smoke check, or build failed, it includes that check's evidence or the build's last lines. read_logs shows the console output.
address: https://hello-world-7k2m9q.ai.host/
```

Read the lines this way:

- `zip:` and `files:` say what went up; [What the deploy zip holds](/cloud/concepts/what-the-deploy-zip-holds/) says what is left out.
- `prepared:` names the target environment before the ZIP is uploaded.
- `started:`, shortened here, is the platform's response to the start, with the hostname and the health path.
- `settled:` gives the outcome. `checked:` reports checks, or says no health or smoke check ran. Request untested pages or routes; read `read_logs` for errors.
- The `read_status` line gives the call for the full record. On a successful deploy, the last deploy line, `address:`, gives the serving address. A `turnzero` update notice may follow.

A failed deploy prints `settled: failed at <step>: <error>`, then a failed health check's likely cause and the failed check's facts. Your AI assistant makes the `read_status` call the last line gives, and reads `read_logs` for the application's own lines ([Deploys](/cloud/troubleshooting/deploys/)).

A deploy typically takes a few minutes. Allow the command fifteen minutes plus upload time, or run it as a background job ([What it prints](/cloud/concepts/what-the-turnzero-command-reads-and-prints/#what-it-prints)).

## How it ends

| Status | Means | Next, after `turnzero deploy --origin https://dev.turnzero.ai` or `turnzero check --origin https://dev.turnzero.ai` |
| --- | --- | --- |
| 0 | Done. | After `turnzero deploy --origin https://dev.turnzero.ai`, the version serves; with `TURNZERO_DEPLOY_NO_WAIT` set, `read_status` shows the outcome. After `turnzero check --origin https://dev.turnzero.ai`, deploy. |
| 1 | It ran and failed. | After `turnzero deploy --origin https://dev.turnzero.ai`, make the `read_status` call the last line gives. After `turnzero check --origin https://dev.turnzero.ai`, clear each `refused:` line and run the check again. |
| 2 | The outcome is unknown. | After `turnzero deploy --origin https://dev.turnzero.ai`, the deploy may still be running: call `read_status` with its wait, as the last line says. |
| 3 | Nothing was started. | Make the call the printed refusal or sentence gives, usually the same command again. With no credential, the routes it prints say how to get one. |

The [turnzero command reference](/cloud/reference/turnzero-command/) gives each status under every subcommand.

## Running and writing lines

Run the returned `command_npx` first, or `command_npx_windows` on Windows. The installed forms are `command` and `command_windows`. The Windows forms use `turnzero.cmd` and `npx.cmd`, which work when PowerShell scripts are disabled.

To create an application, your signed-in AI assistant calls [`tzcloud_create_application`](/cloud/reference/actions/create-application/); to add a development environment, it calls [`tzcloud_create_environment`](/cloud/reference/actions/create-environment/). The `turnzero` command has no subcommand for either.

Other commands include:

| Command | Purpose |
| --- | --- |
| `put` | Upload a file using the command returned by `mint_upload_grant` |
| `export download` | Download an export using the command returned by `request_export` with `download: true` |
| `turnzero db connect` | For production, pass `--grant` with the pending action ID from `open_database_connection` and approve in your browser. For development, pass `--environment development` to use the environment file from `turnzero provision --origin https://dev.turnzero.ai`. Both forms run a PostgreSQL tool. [Connect to your database](/cloud/guides/connect-to-your-database/). |
| `token request`, `token claim` | [Mint a token](/cloud/guides/mint-a-token/) without exposing its value to the AI assistant |
| `logout` | Revoke this computer's authorization |
| `whoami` | Show the account used by this computer's token |
| `hash` | Print the hash of the deploy ZIP without uploading it |
| `session` | [Sign in a test end user](#signing-in-a-test-end-user) and save the session cookie |
| `tzmesh register` | Register a tzMesh standing agent and store its program secret without printing it; with `--rotate`, add a replacement key for an existing agent |
| `tzmesh listen`, `tzmesh status`, `tzmesh capture`, `tzmesh complete`, `tzmesh stop` | Manage an optional local Windows Codex listener without deployment credentials |

Use `turnzero --help` for the command list and exit statuses, or `turnzero deploy --origin https://dev.turnzero.ai --help` for a command's options and example. The [CLI reference](/cloud/reference/turnzero-command/) lists every option.

The command refuses an unknown subcommand, option or value with version, refusal, help and `Read more:` lines, then ends with status 3 without reading standard input or sending requests; see [Command options](/cloud/concepts/what-the-turnzero-command-reads-and-prints/#command-options).

Promote with `turnzero promote --origin https://dev.turnzero.ai` ([Promoting to production](#promoting-to-production)) or the MCP action `promote`. Rollback uses the MCP action `roll_back`. Restart through `restart_application` or a `secret rotate` command's `--restart` option.

### Optional tzMesh listening

`tzmesh register` registers a standing agent and stores its program secret without printing it. With `--rotate`, it adds a replacement key for an existing agent; see [Rotate the key without downtime](https://dev.turnzero.ai/tzmesh/guides/build-a-hosted-agent/#rotate-the-key-without-downtime) for the steps. A register or rotation run ending failed or with nothing started can link here through its `Read more:` line. Local listener actions do not print that page line.

The local listener actions require `turnzero` 0.47.0 or later on Windows Codex. Starting `listen` requires actual background-execution and same-chat queue capability. The local status, capture, complete and stop actions do not require those launch capabilities. None needs a tzCloud deployment credential or tzTeam installation. Shell holds and Claude Code's Monitor remain separate supported routes.

`CODEX_THREAD_ID` must identify the Codex chat that receives the listener's wake messages. Every listener action takes the wake URL returned by tzMesh through `--wake-url`. This address lets the listener wait for messages and contains no secret.

Before starting `listen`, the Codex host verifies that this chat already has one scheduled recovery check, named by `--recovery-check`. The command stays in the foreground. The host may run that exact command in the background only through a permitted facility. A refusal leaves listening unavailable and must not be retried in another form.

`status` reads the saved state and checks which process owns the listener. Each queued wake has a generation: a unique identifier that stays outstanding until the chat completes it.

When the chat is permitted to read its messages, it first runs `capture` to get that identifier, or none. It then reads every tzMesh channel with acknowledgment and handles the deliveries. Only afterward does it run `complete --generation` with the captured identifier. These listener commands never read or acknowledge messages themselves.

If `capture` returns no generation, still read and handle all messages, but run no `complete` command. Never substitute a generation obtained afterward. If the listener has not been initialized, `capture` returns `listener_not_started`. That refusal does not prevent ordinary authenticated message reading.

`stop` saves the request to stop and ends only this listener's work. A call already queuing a wake may still be running when `stop` first responds. Verify that the processes have ended before replacing the listener.

During recovery, keep the saved stop request and any evidence that queuing a wake failed or had an uncertain outcome. A scheduled check inspects failures and reads all messages even when no generation is outstanding. Listener health failures queue no warning wake.

The listener saves its state outside Git, under `TurnZero/tzMesh` in the Windows Local Application Data folder. Later actions must use the same Codex chat and exact recorded URL. Changing directory or chat cannot create fresh state for that listener. `--previous-state` imports the documented shell-loop state only after its old processes have ended.

Use `turnzero tzmesh --help` for each action's form and [Listen from Codex](https://dev.turnzero.ai/tzmesh/guides/listen-for-messages/#listen-from-codex) for the host checks, recovery instructions and refusal handling. An installed listener stays on its version while it runs; changing the installed version does not clear its state.

### Installation and npm

Install with `npm install -g turnzero@next`. An npm global-folder permission failure may say `EPERM` or "rejected by your operating system". For the installation steps, see [Install the turnzero command in What your computer needs](/cloud/getting-started/prerequisites/#install-the-turnzero-command).

An AI coding agent runs `command_npx` first, or `command_npx_windows` on Windows. These work whether or not the command is installed globally.

If npx can't run here, use the installed command when `turnzero --version` responds. Otherwise, for a deploy use `deploy_files` within its limits, then the [upload route](/cloud/getting-started/ways-to-deploy/#upload-a-zip-without-the-turnzero-command) past them. Install the command only if the person wants to keep it. [Ways to deploy to Turn Zero Cloud](/cloud/getting-started/ways-to-deploy/) explains the alternatives.

If `npm install -g turnzero@next` can't run here, try the available alternatives before asking the person for a step. A person or a job may use any of the four returned command forms.

To write an npx command, replace `turnzero` with `npx --no-update-notifier -y turnzero@next`; use `npx.cmd` on Windows. npm may print nothing while downloading. The `turnzero <version> (Node.js <version>)` line means the CLI has started.

If npm returns `404 Not Found` after being given a platform URL instead of a package name, use the command in that error's explanation. If npm returns `notarget` just after a release, retry the same command a minute later; the version named by the tag may not be available yet.

Install or run through npx only in a folder whose npm configuration you trust. A project's `.npmrc` can select a different registry, and the downloaded program can read your credentials. `npm config get registry` shows the selected registry.

The CLI requires Node.js 24 or later. Install Node.js through its installer, Homebrew, or a version manager; do not use `npm install -g node`. See [What your computer needs](/cloud/getting-started/prerequisites/#check-your-node-js-version).

If the platform returns `command_too_old`, run its suggested update command and retry. [Setup troubleshooting](/cloud/troubleshooting/setup/) covers installation and update errors.

### Platform address and credentials

The `turnzero` command defaults to https://turnzero.ai in every build. It cannot read your AI assistant's MCP connection. Commands returned by another platform include `--origin` with that platform's address.

For a command you write yourself, select the platform with `TURNZERO_CLOUD_ORIGIN` or `--origin`, subject to [the credential's address restrictions](/cloud/concepts/how-the-turnzero-command-finds-its-credential/#the-address-a-credential-goes-to). `hash` sends nothing off this computer. Without `--sign-in`, `run` reads no platform credential and makes no platform management request. Its functions migration walk can still connect to the database named by `APP_DATABASE_URL`. With `--sign-in`, `run` uses this address for its credential and hostname checks.

A returned command may pipe a short-lived grant for one action. Account tokens come from the credential file or environment, never command arguments. [The turnzero command's credential](/cloud/concepts/how-the-turnzero-command-finds-its-credential/) explains each source and its origin restrictions.

The CLI verifies HTTPS certificates. Do not set `NODE_TLS_REJECT_UNAUTHORIZED=0`, which disables that verification while still allowing credentials to be sent. Plain HTTP is allowed only for a local platform address.

If the AI assistant cannot run the CLI or reach the platform from its shell, use [deployment through MCP](/cloud/getting-started/deploy-an-application/#deploying-from-a-chat-whose-shell-cannot-reach-the-platform).

To inspect a folder's deployment ZIP without uploading or signing in, run:

```text
turnzero hash --origin https://dev.turnzero.ai
```

Add `--list` to list its files. This is optional before deployment.

To obtain a library entry, use the `download` commands returned by `read_library` with `entry`. If the response has no `download`, run `turnzero library take --origin https://dev.turnzero.ai --entry <name>` at the project root. It uses the same credential sources as `turnzero deploy --origin https://dev.turnzero.ai`.

## Checking a deploy

`check` says what a deploy would refuse, before you make it, and uploads nothing. [Checking a deploy before you make it](/cloud/getting-started/deploy-an-application/#checking-a-deploy-before-you-make-it) gives the call, its answer, and the zip's checks.

Run `turnzero check --origin https://dev.turnzero.ai --application <application id>`, with `--path` where the call named `local_path` and `--origin` where the platform is at another address. It checks the environment the platform would deploy to; there is no environment option. It carries no credential. `check` reads its credential and builds its zip as `turnzero deploy --origin https://dev.turnzero.ai` does. The AI coding agent runs a command returned by its own `check_deploy` call or written for the application it is working on.

Before its zip, `check` reads the folder's `manifest.json` as `turnzero deploy --origin https://dev.turnzero.ai` does: where its `application` member names another application, the command ends with status 3 and nothing is sent. The check leaves the manifest's `application` field as it was.

`check` needs a sign-in, and `hash` does not. Run `turnzero hash --origin https://dev.turnzero.ai` in the folder to read the folder warnings with no sign-in: it builds the same zip, sends nothing, and prints the same warnings. It runs none of the deploy's checks of the zip, which `check` alone runs. Without a credential, `check` suggests this local preview command. Before signing in, check your manifest's shape with a JSON Schema 2020-12 validator and the public schema linked in [Author the manifest](/cloud/guides/author-the-manifest/#what-your-ai-does); `tzcloud_submit_manifest` makes further checks after sign-in.

`check` prints `checking: application <id>: platform readiness, then checks of the files in the zip.` before any request. It then reads the platform's health response and makes one `check_deploy` call under the token, naming the application alone. It builds the zip and prints its `zip:` line only after an admitted answer. A refused application check ends with status 3, without building a zip or printing a `zip:` line.

Every command that sends a platform request except `logout` reads the health response first. The local tzMesh listener makes no platform health request. The `check_deploy` call sends no byte of the zip and no hash. It follows no redirects and gives each attempt sixty seconds. A connection failure before any answer and within that time triggers one retry. `check` prints one `refused:` line per refusal and a last `checked:` line, which [What it prints](/cloud/concepts/what-the-turnzero-command-reads-and-prints/#what-it-prints) lists with the rest.

## Promoting to production

`turnzero promote --origin https://dev.turnzero.ai` requires `turnzero` 0.45.0 or later.

`turnzero promote --origin https://dev.turnzero.ai` promotes a version to production through the platform's own `promote` action, as your AI assistant's `tzcloud_promote` call does. [Turn on development and promote](/cloud/guides/turn-on-development-and-promote/) explains the act and what it reuses.

Run `turnzero promote --origin https://dev.turnzero.ai --application <application id>` to promote the version development serves. To choose a deployed version from the application's history that has not been retired, add `--version-number <number>`. Add `--origin` where the platform is at another address.

It reads its credential as `turnzero deploy --origin https://dev.turnzero.ai` does, and with none it sends nothing and prints the routes to one. After reading the platform's health response, it makes one `promote` call under the token. The call waits up to 45 seconds for the promote's end, follows no redirect, and is never made twice. It never rotates the production database's password, which stays the tool's `tzcloud_promote` call.

It prints the platform's summary and detail, then `reference: <reference>` when supplied. A refused promote also prints this line when its answer carries a reference.

It ends with status 0 where production serves the version, and 1 where the promote failed. It ends with status 3 when nothing started, for example because an option, credential or the call was refused, no credential was available, or the platform was too old. Where the promote is still running, it prints a `next:` line with the `tzcloud_read_status` call that reads its end, and ends with status 2.

If the call gets no answer or an answer the command cannot read as the platform's result, it ends with status 2: the promote may have started. Call `tzcloud_read_status` for the application's production environment. Run the promote command again only if that read shows no promote started after the call.

## Signing in a test end user

`session` signs a test end user of your application in and writes the session's cookie into a file on your machine. Your AI coding agent's requests then carry the cookie with `curl -b` and that file, so the session's value never passes through your AI assistant.

The command is the one the platform's `sign_in_test_end_user` call returns, with `--origin` where the platform is at another address. Its form is `turnzero session --origin https://dev.turnzero.ai --application <application id> --environment <environment> --end-user <end user id or label> --out ../turnzero-session-<end user id or label>.txt --force`. It carries no credential. `session` reads its credential as `turnzero deploy --origin https://dev.turnzero.ai` does, and with none it sends nothing and prints three routes to one.

Run the command once. After reading the platform's health response, it makes one `sign_in_test_end_user` call under the token, which follows no redirect. It writes the cookie into the file `--out` names, in the cookie file form `curl -b` reads. On macOS and Linux the file is readable by your user alone. On Windows it takes its folder's permissions, so name a folder of your own. Then it prints one `session:` line, which never holds the cookie's value.

`--out` names a file whose folder exists. The command refuses a file that already exists unless you add `--force`, and a folder at that path always. The returned command carries `--force`, so running it again after the session's hour replaces the file.

The command also refuses a path inside the folder it runs in where that folder holds `package.json`, since a deploy from there would upload the cookie. Each refusal ends with status 3, with nothing sent and nothing written. Where the end user was signed in but the file could not be written, the command ends with status 1 and says the session was not kept.

## Deploying unattended

An AI coding agent connected by a minted token, not a sign-in, and a job with no AI coding agent, such as a CI job, run the same deploy command under a minted token. A signed-in connection mints that token, so a person signs in once in a browser before any unattended run; after that, the run needs no browser.

The AI coding agent or job loads `TURNZERO_CLOUD_MINTED_TOKEN` from its secret store without writing the value into a command. [A minted token in the environment](/cloud/concepts/how-the-turnzero-command-finds-its-credential/#a-minted-token-in-the-environment) explains how the CLI reads and sends it. [Mint it](/cloud/guides/mint-a-token/#1-mint-it) shows how to save it in GitHub's secret store.

The unattended deploy command is `turnzero deploy --origin https://dev.turnzero.ai --application <application id>`. Add `--env <environment>` to choose the environment, which the platform otherwise chooses. A job runs the command through npx, or installs turnzero with `npm install -g turnzero@next` and runs it directly. A job receives no command from a tool call, so on Windows it replaces `npx` with `npx.cmd`, or `turnzero` with `turnzero.cmd`. The deploy command reads nothing from standard input, so the job need not close standard input.

### Setting the variable for one line

An AI coding agent sets `TURNZERO_CLOUD_MINTED_TOKEN` for one command at a time and unsets it once the command ends. This keeps later commands in the AI coding agent's shell from using that token. A job's variable belongs to its step, so a job needs no such form. An AI coding agent running inside such a job runs the command as given, and neither sets nor unsets the job's value.

The value comes from where the token is kept, such as a variable your AI assistant names or a file read inside the command. The command never writes the value out. A variable that is set but empty, or holds only spaces, is refused: the command ends with status 3 and sends nothing. PowerShell removes a variable given an empty value, so its forms below check the read before the command runs. For a platform at another address, set `TURNZERO_CLOUD_ORIGIN` the same way, beside the token, for the command alone. Once the command ends, it holds what it held before.

In bash and zsh, the assignment stands before the command, on the same shell line, and lasts for that command alone. Here the token is read from a file:

```bash
TURNZERO_CLOUD_MINTED_TOKEN="$(cat <token file>)" turnzero deploy --origin https://dev.turnzero.ai --application <application id>
```

In PowerShell, the assignment, a check that the read found a token, and the command stand in a `try`, and the variable's removal in its `finally`. So an empty token file stops the command before it runs, and the variable is removed even where the command fails:

```powershell
try { $env:TURNZERO_CLOUD_MINTED_TOKEN = Get-Content -Raw -ErrorAction Stop <token file>; if (-not $env:TURNZERO_CLOUD_MINTED_TOKEN) { throw 'The token file is empty, so the line did not run.' }; turnzero.cmd deploy --origin https://dev.turnzero.ai --application <application id> } finally { Remove-Item Env:TURNZERO_CLOUD_MINTED_TOKEN -ErrorAction SilentlyContinue }
```

In cmd.exe, as an AI coding agent passes a command to `cmd.exe /c`, the assignment stands before the command with no quote around it, and `&&` follows the value with no space. The variable lasts for that `cmd.exe` alone, so run this form through `cmd.exe /c`, or run the command from bash or PowerShell. A quote there, passed as an AI coding agent's runtime passes it, sets a variable of another name and leaves `TURNZERO_CLOUD_MINTED_TOKEN` unset. Here the token is read from a variable your AI coding agent names:

```bat
set TURNZERO_CLOUD_MINTED_TOKEN=%<variable your tool names>%&& turnzero.cmd deploy --origin https://dev.turnzero.ai --application <application id>
```

A shell with no form here runs the deploy command from bash, PowerShell, or cmd.exe instead.

## Running on your machine

[Run your app on your computer](/cloud/guides/run-your-application-on-your-machine/) is the procedure for a local run, and [its step 2 (Read the settings the file holds)](/cloud/guides/run-your-application-on-your-machine/#2-read-the-settings-the-file-holds) lists the settings the provision command writes. This section describes the command's part in it: `provision`, which writes the environment file, and `run`, which starts the application with it. [The environment file](/cloud/concepts/what-the-turnzero-command-reads-and-prints/#the-environment-file) gives the forms `run` reads and how `provision` writes the file.

### The provision line

`provision` writes the settings a local run needs into `.env`, the environment file in the folder it runs in. It re-mints the application's development platform credential, and its development database credential where the application has a development database. An existing file keeps every line the command does not set and its permission mode, and `provision` writes no `PORT`. After writing, it prints the `turnzero run --origin https://dev.turnzero.ai` command to start the application.

`--settings-file` names another file in `.env`'s place, `.env` or a `.env.*` name such as `.env.local`, the names every deploy zip leaves out. So the project's own `.env` stays untouched, and `run --settings-file` reads the same file.

`--settings-file` requires `turnzero` 0.35.0 or later.

If the destination folder has neither `package.json` nor `manifest.json`, `provision` still writes the environment file but warns that it may be in the wrong folder. Move it into the application folder or pass its path to `turnzero run --origin https://dev.turnzero.ai --settings-file`.

[Write the environment file](/cloud/guides/run-your-application-on-your-machine/#1-write-the-environment-file) gives the call that returns the command, the command's form, and its [secret grant](/cloud/concepts/glossary/#secret-grant)'s fifteen minutes. The command is `turnzero provision --origin https://dev.turnzero.ai --application <application id> --claim`. The command line contains no credential. To use the grant, the command sends the [verifier](/cloud/concepts/how-the-turnzero-command-finds-its-credential/) it saved on this computer as a bearer token.

`provision` can use that grant once for the platform credential and once for the database credential, if the manifest declares a database. After the command replaces a credential, running it again usually finds that the grant has already been used. The second run changes nothing and prints the challenge and tool call again. That call returns a new grant. `provision` reads nothing on its standard input, so a grant piped to it is left unread.

With a development database, the command writes the database and non-database settings listed in step 2 (Read the settings the file holds) of Run your app on your computer. Without one, the platform returns `not_found` for the database request, which uses nothing of the grant, and the command writes only the non-database settings.

In an unattended run, set `TURNZERO_CLOUD_MINTED_TOKEN` to a token minted for the application and name `--application <application id>`. The platform refuses the application's own `TURNZERO_CLOUD_APP_TOKEN` for this work, and the token goes only where [The address a credential goes to](/cloud/concepts/how-the-turnzero-command-finds-its-credential/#the-address-a-credential-goes-to) allows.

`provision` writes the platform's settings alone, so a setting your manifest binds to a stored secret gets its local value from you, as [Read the settings the file holds](/cloud/guides/run-your-application-on-your-machine/#2-read-the-settings-the-file-holds) says. Run under the command's secret grant, `provision` prints a line naming each one.

Each run revokes the local run's platform credential, and its database credential only where the manifest declares a database. A deployed development environment holds the revoked values until it restarts, so the command's last re-mint restarts it. That redeploy reads the replacement platform credential and any declared database's connection string from the platform's secret store. It does not count toward the day's deploys. Where a deploy of development is still in flight, the re-mint's answer gives `restart_application` on development instead, which you call once that deploy ends.

### The run line

`run` chooses how to serve the app from the files in the current folder or the folder `--path` names. With a readable `package.json` and either a start script or a root `server.js`, it runs `npm start`. With neither server entry point, it can serve `client/` files or `functions/` itself. The application receives your shell's environment with every setting of the environment file laid over it; the file wins where both name one. The command leaves `TURNZERO_CLOUD_MINTED_TOKEN` and `TURNZERO_CLOUD_UPLOAD_GRANT` out of that environment.

Without `--sign-in`, `run` reads no platform credential and makes no platform management request. For a functions folder with migration files, it still connects to the database named by `APP_DATABASE_URL` before serving. When the folder runs as a server, `--sign-in <hostname>` reads the credential `turnzero deploy --origin https://dev.turnzero.ai` uses, checks the platform, and calls `read_status` before starting. It then sends browser sign-in requests to that hostname. The command refuses `--sign-in` when it serves the folder itself. [Test a local run](/cloud/guides/test-sign-in-with-test-end-users/#7-test-a-local-run) gives the browser steps and limits.

`--port` chooses the port you open and takes precedence over `PORT` in `.env` and the shell. For a server, with `--sign-in` or with `client/` and a numeric port, the command listens there and gives the application a free port as `PORT`. Client files are served ahead of the application's routes. Without `--sign-in`, the listener binds on all network interfaces; with it, only to loopback.

An application that normally binds only to loopback can therefore be reached through the listener from elsewhere without `--sign-in`.

Your server must listen on `PORT`. If it ignores that setting and chooses the listener's port, it finds the port in use. If it chooses another port, it may serve there, but the listener responds with 502. [Run your app on your computer](/cloud/guides/run-your-application-on-your-machine/) describes the local run.

The command also leaves out `npm_config_yes` where it holds `true`, which npm sets for a line run through `npx -y`. So an `npx` your application runs asks before it installs, as in your shell. An `npm_config_yes` line in `.env` still reaches the application.

`run` continues until the application stops, so the AI coding agent should start it in the background and collect its output. The startup message gives the process ID and stop command: `kill <id>` on macOS and Linux, or `taskkill /T /F /PID <id>` on Windows.

For a server application, `npm start` passes on your shell's environment alone. Use `run` for a server that needs `.env` and loads no file itself. Without `--port`, `run` uses a numeric `PORT` from `.env` or the shell for its listener. Without one, it serves no client files; `--sign-in` instead refuses to start. For a site served by `run` itself, [The `static-site` template](#the-static-site-template) gives the port.

With neither `--sign-in` nor a client-file listener, `--port` sets the application's `PORT` directly. Without `--port`, it comes from `.env` or the shell; if neither sets it, the application chooses its own port.

A local run reads and writes the development database, where the application has one. For functions, `turnzero run --origin https://dev.turnzero.ai` applies `.sql` files directly under `migrations/` before serving, through the application's own `pg` dependency. It uses `APP_DATABASE_URL` as the functions receive it. A server applies its migrations through its own start code. Files already recorded in that database are skipped at the next migration run. Production's database is separate and needs its own migration run.

`run`'s port line, what it hides in the application's output, and how it ends on an interrupt are in [turnzero command input and output](/cloud/concepts/what-the-turnzero-command-reads-and-prints/#what-it-prints).

## Starting a new service

`turnzero scaffold --origin https://dev.turnzero.ai` creates a new application in `app/`. For a template with `package.json`, it also installs dependencies and runs tests. The [example applications](/cloud/examples/overview/) publish the same source files for browsing or use from a chat. Without a usable shell, follow [Deploy from a chat](/cloud/getting-started/build-an-app-from-a-chat/); using a template is optional.

```text
turnzero scaffold --origin https://dev.turnzero.ai
```

Choose a server to keep an existing server such as Express or Next.js, or when you need a named application size or a process that keeps working between calls. For a new backend, use functions when the work fits within each call and the [function limits](/cloud/guides/deploy-functions/#4-keep-work-within-a-call). Create an app that runs functions with `kind: "serverless"` and omit `size`. If you have only the unedited `server-hello` starter, you can switch templates before choosing the app kind. See [Change templates](#where-you-meant-another-template).

Choose a template with `--template <name>`:

| Template | Kind | Starting application |
| --- | --- | --- |
| `static-site` | Serverless | A static site with a page and stylesheet, served without a server of its own |
| `functions-database` | Serverless | A public notes page with a function and a PostgreSQL database, served without a server of its own; [example](/cloud/examples/functions-database/) |
| `functions-sign-in` | Serverless | A notes app with sign-in. Each user keeps private notes in PostgreSQL. [Example](/cloud/examples/functions-sign-in/) |
| `server-hello` (default) | Server | Health route and a hello-world API route |
| `server-database` | Server | Notes stored in PostgreSQL |
| `server-scheduled-job` | Server | Hello-world service with an hourly handler |
| `server-sign-in` | Server | A notes app with sign-in. Each user keeps private notes in PostgreSQL. |
| `server-ai-chat` | Server | Sign-in and an AI conversation held in the page, with AI charged to the account's balance |

If `--template` names no template the command has, it lists the available templates and exits with status 3. It writes nothing and sends no request. This refusal prints no authorization steps.

For a public gallery with no sign-in, use the [public upload gallery starter](/cloud/guides/build-a-public-upload-gallery/).

`server-hello`, `static-site` and `functions-database` need no platform credential and fetch no library package. The other templates fetch library packages using the same credentials as `library take`. Without a credential, they write nothing, print authorization steps, and exit with status 3. Those steps include the signed-in tool's own route: `authorize` run with nothing piped prints the `mint_token` call a signed-in tool makes to authorize this computer.

If the host refuses `mint_token` or its returned authorization command, ask the person to run the printed `login` command in their own terminal. Or build without `scaffold`, using the signed-in connection's `tzcloud_read_library` and `tzcloud_deploy_files` within its limits.

Run from the project root or supply `--path`. The CLI creates a missing root folder. On Windows, if the path contains `&`, `|`, `<`, `>`, `^`, or `%`, run from that folder without `--path`.

### Existing files and recovery

Scaffolding refuses a nonempty `app/` and never overwrites it. If the project root already has `package.json`, the CLI can create a separate application in `app/` beside it. It reads `system.json` but does not change existing root files.

Scaffolding also refuses where the root holds a `src/` folder or a JavaScript or TypeScript source file, and no `package.json`, since `app/` would sit beside code already started there. `library take` refuses the same way where it would make `app/package.json`. The refusal says what it found and writes nothing. To add a package to that application, add its `package.json` at the root and run `library take` there. To start a new service, use a new folder or `--path`.

Scaffolding first prints a line saying that no `package.json` is at the root or in `app/`, so the application goes in `app/`. Where the root has its own `package.json`, such as a workspace root's, scaffolding writes `app/` beside it, and that line says so instead.

If `app/` already contains an application, the refusal explains how to deploy it. For templates using packages, it also gives `library take` commands and guides for adding those capabilities.

A folder containing only unchanged files from `library take` gets a more specific remedy: remove that generated `app/`, scaffold, then take any additional packages. Any extra files, dependencies, package fields, or edited manifest prevent that classification. Do not remove an application you have started editing.

The CLI checks library files, writes the template into `app.scaffold`, and renames it to `app/`, so `app/` receives the whole template at once. It can resume staging files it recognizes as its own. Unrelated files in `app.scaffold` are refused and left untouched. If neither `system/` nor `system.json` exists, it creates `system/` for library entries.

After writing a template with `package.json`, it runs `npm install` and `npm test` in `app/`. For `static-site`, it prints the next steps without installing dependencies or running tests. These processes receive neither `TURNZERO_CLOUD_MINTED_TOKEN` nor `TURNZERO_CLOUD_UPLOAD_GRANT`. An interrupted install does not start tests. If interrupted during file writes, the CLI finishes those writes, starts no npm process, and prints recovery steps. It then exits with status 128 plus the signal number.

For a template that takes library entries, after `npm install` ends with status 0 the CLI reads each entry's package file through its link. If a link cannot be read, it says so and runs `npm install --install-links` once to copy local packages in place of links. It then reads each entry again. If a link stays unreadable, the run ends failed and starts no tests. A failed first install or a template that takes no entry starts no second install.

The recovery output reflects the files actually written:

- If `app/` was created for `static-site`, nothing remains to install or test; follow `app/AGENTS.md` for the next steps. For another template, follow its printed install or `library take` commands, then run `npm test`.
- If `app/` is absent or empty, retry scaffolding.
- If the destination is unreadable or is not a folder, correct that condition first.
- If tests fail on an untouched template, report the failure with the template and package versions printed by the command.

### Manifest and AI instructions

Scaffolding builds `manifest.json` with the names and versions of entries in the project's library. `--application <application id>` binds it to an application already created on the platform. Otherwise, the first deploy writes the binding. Later `turnzero deploy --origin https://dev.turnzero.ai` or `turnzero check --origin https://dev.turnzero.ai` commands naming another application are refused before zipping or sending files.

`app/AGENTS.md` describes the starting template and links the platform's instructions. Keep it current as the application changes. If no root `AGENTS.md` exists, scaffolding creates one directing the AI coding agent to `app/AGENTS.md`. Existing root instruction files are not read or changed; the output gives the sentence to add, including to `CLAUDE.md` when present.

The CLI creates no `CLAUDE.md`. A `not changed:` or `write failed:` line gives the instruction to add to the root file; the next steps repeat it. [Build a database-backed service](/cloud/getting-started/build-a-database-backed-service/) shows the instruction.

The CLI prints the template's next steps after tests pass, or after writing `static-site`, which has no tests. Skip `create_application` if the application already exists. For `static-site` and the five server templates, start `turnzero run --origin https://dev.turnzero.ai` in the background as the next steps direct. For `functions-database`, follow its printed steps to create a serverless application, submit the manifest, deploy and check that a saved note survives reloading. For `functions-sign-in`, follow its printed steps to deploy the serverless application and sign in at its deployed address. Neither template's printed steps start a local run.

Deployment targets production by default. If optional development exists, deployment targets it and `promote` moves a tested version to production. Call `create_environment` before deploying if you want that workflow.

The five templates with a server use the platform's own `request.signal` in a deployed copy. `static-site` has no request code. In a local server run, use a signal that fires when the response closes unfinished, rather than Node's `request.signal`, which some Node 24 releases abort at a normal request end.

### The server-hello template

`server-hello` writes seven files into `app/`: `package.json`, `manifest.json`, `src/server.mjs`, `src/main.mjs`, `test/hello.test.mjs`, `.gitignore`, and `AGENTS.md`. The server responds to `GET /health` with status 200 and `{"ok":true}`, and to `GET /api/hello` with status 200 and the plain text `hello world`. It responds to any other request with status 404 and `{"error":"not_found"}`, and listens on the port in `PORT`, or on 8080 where `PORT` is not set.

The `/api/` prefix leaves `/` available for a web client. The manifest declares no service, and the package file declares no dependency. A `server-hello` run ends with four next steps: `create_application`; `submit_manifest` with `app/manifest.json`, naming no `local_run`, because the service reads no setting; the `run` command; and `deploy_command` followed by running its returned command.

### The server-database template

`server-database` is the notes service that [Build a database-backed service](/cloud/getting-started/build-a-database-backed-service/) shows file by file, written by the command with `--template server-database`.

It creates `package.json`, `manifest.json`, `migrations/0001_notes.sql`, `src/db.mjs`, `src/server.mjs`, `src/main.mjs`, `test/notes.test.mjs`, `.gitignore`, and `AGENTS.md`.

To keep a resource other than notes, add `--resource` with its plural, the word of the table and the route, such as `--resource orders`. `--singular` names the singular, which is otherwise the plural without its closing `s`, so a plural that does not end in `s` needs it: `--resource people --singular person`. The command then writes the same files with the resource's names in place of notes, note, Notes, and Note. The [turnzero command reference](/cloud/reference/turnzero-command/#scaffold) gives each name's form.

Where a name is outside its form, the plural is `s` alone, `--singular` comes without `--resource`, or the singular, given or derived, is `json`, the command writes nothing and ends with status 3.

To start from your own columns, add `--fields` with a list of fields separated by commas, each a name, a colon, and a kind: `--fields "name:text,message:text"`. The command then writes the migration, the data layer, the routes, and the tests under those columns, in place of the one `title` column. Write the list between double quotes, because PowerShell reads a bare comma as splitting an argument.

A name is a lower-case ASCII letter, then lower-case ASCII letters, digits, and underscores, at most 30 characters, and never `id`, the key the migration writes. The kinds are `text`, which refuses an empty string, `integer`, `boolean`, and `timestamp`. For another type, such as `jsonb`, name the nearest kind, then change the written migration and routes by hand. Every column is required, so `POST` returns status 400 for a body that lacks a field, or whose value the database refuses for its kind. A list holds from one to twenty fields, no two under one name.

Field names may match the resource name, such as `message` with `--resource messages`.

Generated columns have no defaults. Add database-generated values directly to the migration, outside `--fields`: for example `created_at timestamptz NOT NULL DEFAULT now()`. Add it before the service's first start, since a migration file never changes once a start has applied it, and read it in a query of your own.

A `server-database` run ends with five next steps: `create_application`; the provision step; the `run` command; a step to shape the service; and `deploy_command` followed by running its returned command. The provision step submits `app/manifest.json` naming no `local_run`, then runs the bare `provision` command and any call it prints. The shaping step comes before the first deploy and makes the service your own: the table and its migration, the routes, and the tests.

### The server-scheduled-job template

`server-scheduled-job` is written by the command with `--template server-scheduled-job`. It writes eight files into `app/`: `package.json`, `manifest.json`, `src/server.mjs`, `src/main.mjs`, `src/jobs.mjs`, `test/job.test.mjs`, `.gitignore`, and `AGENTS.md`. The run copies the Schedule package's compiled code into `app/lib/schedule/`, which the package file declares as `file:lib/schedule`.

The server responds to `GET /health` and `GET /api/hello` as `server-hello`'s does. Ahead of those routes, the Schedule package's router handles the schedule's path, `/jobs/heartbeat`, and passes each [scheduled run](/cloud/concepts/glossary/#scheduled-run-and-due-instant) to the handler in `src/jobs.mjs`. A request to that path without the platform's headers gets status 404 and the error `scheduled_handler_only`. Where the manifest and the handlers do not match, the router stops the service as it starts.

The manifest declares one schedule, `heartbeat`, due once an hour, at the minute of the hour, in UTC, at which you ran the command. So services written from this template are not all due at the same moment. You can change the cron expression to any schedule with at least one minute between runs. The same minimum applies to Shared 0.5 GB and Shared 1 GB.

The handler prints one line naming the schedule and the run's key, such as `schedule heartbeat ran, key heartbeat@2026-01-01T09:00:00.000Z`, which is safe to repeat. A handler whose effect must not repeat records the key first, as [Schedule](/cloud/backend-packages/schedule/) describes. The tests fire the handler through the package's [test double](/cloud/concepts/glossary/#test-double), since no schedule fires on your machine.

A `server-scheduled-job` run ends with five next steps: the four of `server-hello`, whose `run` step also says that no schedule fires on your machine, and a fifth, `run_schedule`. That call fires the handler now and returns how the run ended. [Confirm it runs](/cloud/guides/add-a-scheduled-job/#4-confirm-it-runs) says how to read that answer and its lines.

### The functions-sign-in template

Choose `functions-sign-in` for a notes app with sign-in and private notes in PostgreSQL when the app can run as functions. Use [the server-sign-in template](#the-server-sign-in-template) for the same app on a server. Choose `functions-database` for a public notes page.

`turnzero scaffold --origin https://dev.turnzero.ai --template functions-sign-in` writes the app under `app/`, takes the [Account](/cloud/backend-packages/account/) package, installs dependencies, and runs the tests. The manifest declares the database and accounts services. The web page is in `client/`, the notes function is in `functions/api/notes.js`, and each request uses the signed-in user's ID to read or change that user's notes.

The scaffold runs the template’s tests as its local check and prints four steps. Create the app with `kind: "serverless"` and no `size`, then submit `app/manifest.json` without `local_run`. Call `tzcloud_deploy_command` and run the returned command in `app/`. Open the deployed address and sign in. Add a note, reload the page and check that the note still appears. The [functions-sign-in example](/cloud/examples/functions-sign-in/) includes the files and the route from a chat.

### The server-sign-in template

Choose `server-sign-in` when the app needs a server and signed-in users keep their own data. For an app that can run as functions, start with [`functions-sign-in`](#the-functions-sign-in-template). For a conversation with an AI, choose [`server-ai-chat`](#the-server-ai-chat-template). For a public service with a database and no user sign-in, choose [`server-database`](#the-server-database-template).

`turnzero scaffold --origin https://dev.turnzero.ai --template server-sign-in` writes a web app in plain HTML, CSS, and script, with no front-end framework. Its page lets users sign in and keep their own notes in PostgreSQL. The run takes the Database and [Account](/cloud/backend-packages/account/) packages and copies each into `app/lib/`.

It writes thirteen files into `app/`: `package.json`, `manifest.json`, `migrations/0001_notes.sql`, `src/db.mjs`, `src/session.mjs`, `src/server.mjs`, `src/main.mjs`, `client/index.html`, `client/app.js`, `client/styles.css`, `test/app.test.mjs`, `.gitignore`, and `AGENTS.md`. The manifest declares a database and the `accounts` service, which turns on sign-in.

- The page links to `/__account/signin` and `/__account/signout`. It reads the signed-in user from `/__account/me` and lists that user's notes newest first, with each note's first line and date. Select a note to read its full text or confirm its deletion; **New note** opens the composer.
- The server's `GET /health` checks the database. `GET /api/notes`, `POST /api/notes`, and `DELETE /api/notes/<id>` require a verified user; a request without one receives 401 `sign_in_required`. Deleting your own note returns 204; a missing note or another user's note returns 404 `not_found`.
- `src/session.mjs` verifies the session as [Add sign-in to your app](/cloud/guides/add-sign-in-to-your-app/#3-tell-which-user-sent-a-request) shows. Each row keeps the verified user's id as its owner, so each user lists and deletes their own notes alone.
- The tests run the routes over the Database and Account packages' test doubles.

The platform serves the three files in `client/` ahead of your routes, as [Serve a web client](/cloud/guides/serve-a-web-client/) describes. With `turnzero` 0.35.0 or later and a numeric port, the command does the same locally. The example's server also returns them for its tests and a run without that listener.

Start `turnzero run --origin https://dev.turnzero.ai --port 3000 --sign-in <hostname>` for browser sign-in on this computer, using the application's hostname. Without `--sign-in`, sign in on the hosted hostname and hand a session to the API as a Bearer. [Test a local run](/cloud/guides/test-sign-in-with-test-end-users/#7-test-a-local-run) describes both routes.

Without `--fields`, `server-sign-in` keeps one text column, `body`; `server-database` keeps `title`. The notes app trims `body` and accepts 1 to 20,000 characters. Its rows also hold `created_at`, set by the database.

`--resource`, `--singular`, and `--fields` work under `server-sign-in` as under `server-database`. The template name remains `server-sign-in` when the resource changes. A field cannot be named `id`, `owner`, or `created_at`, since the migration supplies those columns; the resource's plural cannot be `health`.

With `--fields`, the composer has an input for each field, with a text area for the first text field. The list shows that field's first line. The reader shows its full text and each other field as `name: value`. Without a text field, the list shows every field as `name: value`.

A `server-sign-in` run ends with six next steps: the five of `server-database`, followed by opening the deployed address in a browser, signing in, and listing, adding, and deleting the user's own rows. Its `run` step names the page at `/` and the session Bearer for the API routes. Its shaping step names the page, table and migration, routes, and tests. [Build a notes app with sign-in and a database](/cloud/guides/build-a-notes-app-with-sign-in-and-a-database/) follows the complete example.

### The server-ai-chat template

Choose `server-ai-chat` for a web app where people sign in and have a conversation with an AI model. Calls on the platform's AI route draw the account's balance at the provider's published price plus the markup shown on the [pricing page](https://dev.turnzero.ai/pricing). It needs no provider key. The page keeps its turns in memory until it reloads; the server keeps no conversation history.

`turnzero scaffold --origin https://dev.turnzero.ai --template server-ai-chat` writes twelve files into `app/`: `package.json`, `manifest.json`, `src/session.mjs`, `src/ai.mjs`, `src/server.mjs`, `src/main.mjs`, `client/index.html`, `client/app.js`, `client/styles.css`, `test/app.test.mjs`, `.gitignore`, and `AGENTS.md`. It takes the Account and [AI Generation](/cloud/backend-packages/ai-generation/) packages into `app/lib/`. Its manifest declares the `accounts` service alone; it has no database or migration.

The page provides sign-in and sign-out links, reads the user from `/__account/me`, and posts each new message with the earlier turns to `POST /api/ask`. `src/session.mjs` verifies the user. An unverified request receives 401 `sign_in_required`, and `GET /health` answers 200 without a store to reach.

The request body holds a `messages` array of `{ role, content }` turns. They must alternate between `user` and `assistant`, starting and ending with `user`, with no blank turn and no turn over 4,000 characters. A malformed history receives 400 `invalid_messages`; a body that is not JSON receives 400 `invalid_json`.

`src/ai.mjs` sends at most the most recent eleven turns in one model call, starting on a user turn. A successful response holds `answer`. Where no answer is available, status 503 names `allowance_unavailable`, `account_paused`, or `upstream_quota`. The page leaves an unanswered user turn out of the next request, including when an answer has no text. Reloading the page clears the conversation.

The model call receives the request's abort signal and stops when it fires. On the platform, that signal fires when the execution window ends, not when the visitor closes the tab. An aborted request logs no error.

The tests use the Account and AI Generation doubles. The client-file serving and local sign-in options are the same as for [`server-sign-in`](#the-server-sign-in-template). `server-ai-chat` refuses `--resource`, `--singular`, and `--fields`, since it keeps no database resource.

A `server-ai-chat` run ends with six next steps. The first four are `create_application`; the provision step described under `server-database`; the `run` command; and shaping the page, routes and tests. The last two are `deploy_command` followed by running its returned command, and opening the deployed address to sign in and have a conversation. Its `run` step names the page at `/` and the session Bearer for the API route. Its shaping step names no table. [Build an app with sign-in and AI](/cloud/guides/build-an-app-with-sign-in-and-ai/) follows the complete example.

### The `static-site` template

Choose `static-site` for pages, styles and other files served without a server of the application's own. `turnzero scaffold --origin https://dev.turnzero.ai --template static-site` works before sign-in: it reads no credential, sends no request and takes no library package.

It writes five files into `app/`: `manifest.json`, `client/index.html`, `client/styles.css`, `.gitignore`, and `AGENTS.md`. The page links to the stylesheet beside it, with no script or request to another origin. There is no `package.json`, server or test file.

The manifest declares `manifest_version: 1`, `services: []`, `region: "usa"`, `egress: []`, `audience: { "kind": "public" }`, and `packages: []`. It declares no health path.

You can create the serverless application before or after scaffolding. With the application already created, `--application <application id>` binds the manifest while scaffolding. Without that option, the first deploy writes the binding.

The command installs nothing and runs no tests. It prints the next steps and ends with status 0, without an `installed:` or `tested:` line:

1. Call `create_application` with kind set to `serverless` and no size, unless this serverless application already exists.
2. Call `submit_manifest` with the application and `app/manifest.json`, naming no `local_run`.
3. Run `npx --no-update-notifier -y turnzero@next run --origin https://dev.turnzero.ai` in `app/`, or `turnzero run --origin https://dev.turnzero.ai` with the installed command.
4. Call `deploy_command`, then run its returned command in `app/`.
5. Open the deployed address in a browser and check the page and stylesheet.

Use the run line the scaffold prints: it keeps the platform's package tag and the command form you used. On Windows it uses `npx.cmd` or `turnzero.cmd`. Keep any `--origin` it includes.

In `app/`, `turnzero run --origin https://dev.turnzero.ai` starts no application: the command serves `client/` itself. It uses port 3000 unless `--port`, `.env` or the shell sets a numeric port, and runs until stopped. Start it in the background and read its lines. A missing file with no page fallback answers 404.

Your AI coding agent's report names `static-site`, the application, the environment, the deployed hostname and version. It states that this template has no npm tests. It lists the local checks and the checks made on the deployed site, including whether the page and stylesheet were checked in a browser.

A successful HTTP request shows that a file was served; it does not show how the page looks in a browser. The report names each check left unfinished and why, including a browser check the tool could not make.

`static-site` refuses `--resource`, `--singular`, and `--fields`, since it keeps no database resource. [Publish a static site](/cloud/guides/publish-a-static-site/) explains file paths, manifest submission and deploy choices.

### Where you meant another template

Without `--template`, scaffolding creates `server-hello`. If you meant another template and have not edited the generated files, remove that `app/` and the root `AGENTS.md` only if this run created it. Keep `system/`, then rerun with the intended `--template`. Adding packages to the existing `server-hello` app does not replace it with another template.

## Related

- [Deploy from your computer](/cloud/getting-started/deploy-an-application/) runs the deploy command from its call to the release check.
- [turnzero command input and output](/cloud/concepts/what-the-turnzero-command-reads-and-prints/) gives what each line reads and prints, beyond the common case.
- [turnzero command reference](/cloud/reference/turnzero-command/) gives each subcommand's usage line, its options, and the statuses it ends with.
- [The turnzero command's credential](/cloud/concepts/how-the-turnzero-command-finds-its-credential/) says where each command's credential comes from.
- [Run your app on your computer](/cloud/guides/run-your-application-on-your-machine/) runs `provision` and `run`.
- [Connect your AI assistant](/cloud/getting-started/connect-your-tool/) authorizes this computer.
- [Keep a secret value out of chat](/cloud/guides/supply-a-secret-value-without-exposing-it/) runs the `secret` command.
- [Mint a token](/cloud/guides/mint-a-token/) mints a CI job's token.
- [Store files](/cloud/guides/store-files/) runs the `put` command, and [Export or delete your account](https://dev.turnzero.ai/turnzero/guides/export-or-delete-your-account/) the `export download` command.
- [Use the feature package library](/cloud/guides/use-the-library/) runs the `library take` command.
- [What your computer needs](/cloud/getting-started/prerequisites/) checks Node.js and Windows PowerShell.
- [Deploys](/cloud/troubleshooting/deploys/) starts from a command that was refused or ended early.
