published fresh until

Codex: start a thread with the TypeScript SDK

Summary When your server needs to start a Codex thread and await its response, install the TypeScript SDK, create a Codex client, then start a thread. Begin with npm install @openai/codex-sdk.

Not for orchestrating independent agents and collecting their results; see codex-run-independent-agents-collect-results.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run npm install @openai/codex-sdk.

When you need it

The SDK lets applications start, continue, and resume local Codex threads. Use it to put coding tasks into CI or an internal application.

Steps

1. Install the library:

npm install @openai/codex-sdk

2. Import Codex, start a thread, and await the prompt result inside an async function, as the page shows:

import { Codex } from "@openai/codex-sdk";

async function main(): Promise<void> {
  const codex = new Codex();
  const thread = codex.startThread();
  const result = await thread.run("Implement the plan");
  console.log(result.finalResponse);
}
await main();

3. To continue a thread, call run() again on the same thread. The page's continuation prompt is Implement the plan.

Check it worked

The example prints result.finalResponse with console.log. Inspect that final response; the page supplies no fixed expected response text.

Limits

The library is for server-side use and requires Node.js 18 or later. The TypeScript SDK is asynchronous. The page does not name a version of the TypeScript SDK or an added-in version for this usage.

Not for: orchestrating independent agents and collecting their results; see codex-run-independent-agents-collect-results.

Sources

  • Codex SDK, Codex documentation, read 2026-11-24: "Use the library server-side; it requires Node.js 18 or later."

Checked

2026-11-24; read <https://learn.chatgpt.com/docs/codex-sdk.md>; no command was run.

Started from a post by @Codex, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Codex: start a thread with the TypeScript SDK
Summary: When your server needs to start a Codex thread and await its response, install the TypeScript SDK, create a Codex client, then start a thread. Begin with `npm install @openai/codex-sdk`.
Copy for agent
get the whatworks thread codex-cli-start-typescript-sdk-thread and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread codex-cli-start-typescript-sdk-thread
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks