Codex app server: what it is, how to start it and when you need it
What the Codex app server is, how to start it over stdio or WebSocket, the initialize handshake, threads and turns, auth warnings, and when to use the SDK instead.
By the Kipt team · Updated 24 November 2026 · 8 min read
What is the Codex app server?
The Codex app server is the interface Codex uses to power rich clients, such as the Codex VS Code extension. You start it with codex app-server, and your program talks to it with JSON-RPC messages. OpenAI's app server documentation says to use it "when you want a deep integration inside your own product: authentication, conversation history, approvals, and streamed agent events."
Most people never need it. If you use Codex in the terminal, the IDE extension or the Codex app, something else already starts and talks to the app server for you. You only meet it directly when you are building a client of your own, or when a remote terminal setup asks for it.
The implementation is open source in the openai/codex repository. This guide was checked against the docs on 24 November 2026.
Do I need the app server, or something simpler?
Probably something simpler. OpenAI's docs say: "If you are automating jobs or running Codex in CI, use the Codex SDK instead." Use this table to decide:
| You want to | Use |
|---|---|
| Run one prompt from a script or CI step | codex exec |
| Call Codex from your own TypeScript or Python code | Codex SDK |
| Build a custom client with its own sign-in, approvals and live events | Codex app server |
| Control Codex running on another machine from your terminal | codex app-server plus codex --remote |
| Trigger Codex from GitHub events | Codex GitHub Action |
The SDK page makes the same split: use the SDK to automate coding tasks, including jobs in CI, and use the app server to build custom clients. It also says the old codex mcp-server command and codex-mcp-server binary have been removed, and that existing integrations should use the app server. The Python SDK itself controls the local app server over JSON-RPC, so it is the app server under the hood.
How do I start the Codex app server?
Pick a transport with the --listen flag. The docs list four:
| Transport | Flag | Notes |
|---|---|---|
| stdio | --listen stdio:// (default) |
Newline-delimited JSON (JSONL) |
| WebSocket | --listen ws://IP:PORT |
One JSON-RPC message per text frame. Labelled experimental and unsupported |
| Unix socket | --listen unix:// or --listen unix://PATH |
WebSocket connections over the default control socket or a custom path |
| Off | --listen off |
Don't expose a local transport |
The three starting commands from the "Getting started" section are:
codex app-server
codex app-server --listen ws://127.0.0.1:4500
codex app-server --listen unix://
When you run with a ws:// listener, the same port answers basic health probes. GET /readyz returns 200 OK once the listener accepts connections, and GET /healthz returns 200 OK when the request has no Origin header. Requests with an Origin header get 403 Forbidden.
Can I connect the terminal UI to a remote app server?
Yes. Remote terminal UI mode runs the app server on one machine and connects the Codex CLI from another. Start a WebSocket listener, then connect:
codex app-server --listen ws://127.0.0.1:4500
codex --remote ws://127.0.0.1:4500
The --remote option accepts ws://, wss://, unix:// and unix://PATH endpoints. For a non-local connection, the docs say to configure WebSocket authentication and put the connection behind TLS, and to pass the token through an environment variable rather than on the command line:
export CODEX_REMOTE_TOKEN="$(cat "$HOME/.codex/app-server-token")"
codex --remote wss://remote-host:4500 \
--remote-auth-token-env CODEX_REMOTE_TOKEN
How does the handshake work?
Every connection starts with two messages, and the server rejects any request before them. The docs say a client "must send a single initialize request per transport connection before invoking any other method on that connection, then acknowledge with an initialized notification." Requests sent too early get a Not initialized error, and a second initialize on the same connection returns Already initialized.
The messages are JSON-RPC 2.0 with the "jsonrpc":"2.0" header left out on the wire. Requests have method, params and id. Responses echo the id with a result or an error. Notifications have no id. The initialize example from the Codex VS Code extension looks like this:
{
"method": "initialize",
"id": 0,
"params": {
"clientInfo": {
"name": "codex_vscode",
"title": "Codex VS Code Extension",
"version": "0.1.0"
}
}
}
Set clientInfo.name to identify your own client. The docs note it is used to identify your client for the OpenAI Compliance Logs Platform, and that enterprise integrations should contact OpenAI to be added to a known clients list.
By default you get the stable API. Some methods and fields are gated behind capabilities.experimentalApi. If you don't set it to true, the server rejects experimental methods with an error saying the method "requires experimentalApi capability".
What are threads, turns and items?
Three building blocks cover the whole protocol. These definitions are the docs' own:
- Thread: a conversation between a user and the Codex agent. Threads contain turns.
- Turn: a single user request and the agent work that follows. Turns contain items and stream incremental updates.
- Item: a unit of input or output, such as a user message, agent message, command run, file change or tool call.
A normal conversation follows these steps:
- Call
thread/startfor a new conversation,thread/resumeto continue one, orthread/forkto branch its history into a new thread id. - Call
turn/startwith thethreadIdand the user input. Optional fields override the model, working directory and sandbox policy. - Keep reading notifications such as
item/started,item/agentMessage/deltaanditem/completed. - The server sends
turn/completedwith a final status ofcompleted,interruptedorfailed.
While a turn is running you can call turn/steer to add more user input to it, or turn/interrupt to cancel it. turn/steer needs an expectedTurnId that matches the active turn. You can also call model/list to find out which models are available before you start a thread.
What does a working example look like?
The docs include a complete stdio client in TypeScript, plus Go and Ruby versions. The shape is always the same: spawn codex app-server, send initialize, wait for the response, send initialized, start a thread, start a turn, and read lines until turn/completed. These are the messages involved, using the docs' example model:
{ "method": "initialize", "id": 0, "params": { "clientInfo": { "name": "my_product", "title": "My Product", "version": "0.1.0" } } }
{ "method": "initialized", "params": {} }
{ "method": "thread/start", "id": 1, "params": { "model": "gpt-6.1-sol" } }
{ "method": "turn/start", "id": 2, "params": { "threadId": "thr_123", "input": [{ "type": "text", "text": "Summarize this repo." }] } }
The threadId comes from the thread/start response. The docs say the example model requires access for the signed-in account or workspace, and suggest model/list to pick an available one. Copy the full program from the app server page, which is kept in step with each Codex release, rather than from a blog post.
Approvals are server-initiated requests. Depending on the user's Codex settings, command runs and file changes can ask the client for a decision. The client replies with accept, acceptForSession, decline or cancel, and the item then ends with item/completed. Your client needs UI for these, which is a large part of why the app server is for products and not for scripts. The approvals and sandbox guide explains the same ideas from the user's side.
How do I generate the schema?
You can generate types for the exact version of Codex you run:
codex app-server generate-ts --out ./schemas
codex app-server generate-json-schema --out ./schemas
The first writes TypeScript types and the second a JSON Schema bundle. The docs say each output is specific to the Codex version you ran, so regenerate it after upgrading Codex.
Is the app server safe to expose?
Only on your own machine unless you set up auth. The docs are direct about this: "WebSocket transport is experimental and unsupported." Local listeners such as ws://127.0.0.1:PORT suit localhost and SSH port-forwarding. They also say: "Non-loopback WebSocket listeners currently allow unauthenticated connections by default during rollout, so configure WebSocket auth before exposing one remotely."
The supported WebSocket auth flags are:
--ws-auth capability-token --ws-token-file /absolute/path
--ws-auth capability-token --ws-token-sha256 HEX
--ws-auth signed-bearer-token --ws-shared-secret-file /absolute/path
Clients present the credential as Authorization: Bearer <token> during the WebSocket handshake, and the server checks it before initialize. Prefer --ws-token-file over passing raw tokens on the command line, and use plain WebSockets only for localhost or an SSH port-forwarded connection.
A separate point on accounts: the docs say app server authentication has never been permitted for commercial or hosted services, and they point those uses to Sign in with ChatGPT instead. If you plan to ship a hosted product, read that section of the docs first.
What do the common app server errors mean?
The docs describe a handful of errors you can handle in a client:
Not initializedorAlready initialized: you skipped the handshake or sentinitializetwice on one connection.-32001with "Server overloaded; retry later.": in WebSocket mode the server uses bounded queues and rejects new requests when they are full. Retry with an exponentially increasing delay and jitter.-32600withdata.reasonset toserverShuttingDown: the server is shutting down gracefully and is refusing new work.model/listreturning-32600and asking the client to restart Codex: the selected model provider no longer satisfies managed requirements.- A turn with
status: "failed": checkcodexErrorInfo, whose common values includecontextWindowExceeded,usageLimitExceeded,badRequest,unauthorizedandsandboxError.
If you searched for a message such as "codex app server is not available" or "process not available", the official app server page does not describe that wording, so this guide doesn't invent a fix for it. Start with the general steps in Codex troubleshooting, and check that codex app-server starts on its own in a terminal.
Where do prompts and skills fit in?
An app server client sends the prompts. Whatever you build, the text in turn/start has to come from somewhere, and teams do better when they keep those prompts in one reviewed place. Kipt keeps prompts and skills as Markdown in a private GitHub repo you own. The app server can also start a turn that invokes a skill: put $<skill-name> in the text input and add a skill input item with the skill's name and path. For how skills are laid out on disk, see Codex skills.
Questions
It is the interface Codex uses to power rich clients, such as the Codex VS Code extension. You start it with codex app-server and talk to it with JSON-RPC messages to handle sign-in, conversation history, approvals and streamed agent events in your own product.
Run codex app-server to use the default stdio transport. For a WebSocket listener run codex app-server --listen ws://127.0.0.1:4500, and for the default Unix socket run codex app-server --listen unix://. Then send an initialize request followed by an initialized notification.
OpenAI's docs say that if you are automating jobs or running Codex in CI, use the Codex SDK instead. Use the app server when you are building a custom client that needs its own authentication, conversation history, approvals and streamed agent events.
Not without setup. The docs call WebSocket transport experimental and unsupported, and say non-loopback listeners currently allow unauthenticated connections by default. Configure WebSocket auth before exposing one, prefer a token file over a raw token, and use plain WebSockets only for localhost or an SSH port-forwarded connection.
Run codex app-server generate-ts --out ./schemas for TypeScript types or codex app-server generate-json-schema --out ./schemas for a JSON Schema bundle. The output matches the Codex version you ran.