# CLI and headless usage

> The command line, headless runs, exit codes, and sub-agents.

Run `openmax` in a project directory for the terminal interface. Use `-p` to run a prompt and exit.

## Run from a script

Configure a model and [trust the project](https://useopenmax.dev/docs/permissions) before running a prompt.

```sh
openmax -p "Summarize the public API in this repository"
openmax -p --json "List the integration tests"
```

In plain print mode, Open Max writes the answer to stdout and tool progress and errors to stderr. With `--json`, it writes one event per line to stdout.

A headless run declines approval requests. For unattended changes, use a trusted project in `auto` mode. If an authorized CI setup must grant trust without a terminal, set `OPENMAX_HUMAN_ATTEST=1` on the command that grants trust. A new grant via `--trust-project` records `auto`. Open Max retains the saved mode of an already trusted project.

```sh
OPENMAX_HUMAN_ATTEST=1 openmax --trust-project -p "Summarize the test results"
```

| Exit code | Result |
| --- | --- |
| 0 | Every turn completed. |
| 1 | A turn or session failed. |
| 2 | Usage or configuration error, or no session to continue. |
| 3 | The project lacks trust or the process cannot grant it. |
| 4 | The turn stopped before completion. |

## Run a sub-agent in a worktree

```sh
openmax --subagent "Fix the flaky retry test" --worktree
```

Open Max gives the child a separate session and a Git worktree at the current HEAD. If the child makes changes, Open Max commits them to a separate branch and reports the branch when the child exits.

See the [CLI reference](https://github.com/Max17190/open-max/blob/main/docs/usage.md) for flags, timeouts, exit codes, key bindings, and slash commands. For applications that need a two-way connection, use the [stdio protocol](https://useopenmax.dev/docs/stdio-protocol).
