npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@raylin01/codex-client

v0.2.3

Published

Node.js client for controlling Codex CLI app-server over JSON-RPC.

Readme

@raylin01/codex-client

Node.js client for controlling Codex CLI app-server over JSON-RPC, with both the raw transport API and a structured thread/turn wrapper.

Install

npm install @raylin01/codex-client

Requirements

  • Node.js 18+
  • Codex CLI available on your PATH (or pass codexPath)

Quickstart

import { CodexClient } from '@raylin01/codex-client';

const client = await CodexClient.init({
  cwd: process.cwd(),
  approvalPolicy: 'on-request'
});

const turn = client.send('Summarize this repository and mention the riskiest area.');

for await (const update of turn.updates()) {
  if (update.kind === 'output' && update.snapshot.currentOutputKind === 'text') {
    process.stdout.write(update.snapshot.text);
  }

  if (update.kind === 'request') {
    console.log('\nRequest:', update.snapshot.currentMessage.content);
  }
}

await turn.done;
await client.close();

Structured API

  • CodexClient.init(options) starts the app-server and initializes or resumes a thread
  • client.send(input, options?) returns a turn handle immediately
  • turn.current(), turn.history(), turn.updates(), and turn.done expose normalized turn state
  • client.getOpenRequests() returns pending approvals, questions, and tool calls
  • client.getOpenRequest(id) returns one pending request by id
  • client.approveRequest(...), client.answerQuestion(...), and client.respondToToolCall(...) respond to Codex RPC requests without handling raw JSON-RPC directly
  • client.createQuestionSession(id) incrementally collects multi-question answers before submit()

For approvals, the structured helper now only exposes Codex capabilities that actually exist in the app-server protocol:

  • scope: 'once' | 'session' for plain allow decisions
  • execPolicyAmendment for command approvals that should return acceptWithExecpolicyAmendment
const [request] = client.getOpenRequests();
if (request?.kind === 'question') {
  const session = client.createQuestionSession(request.id);

  session.setCurrentAnswer('A');
  session.next();
  session.setCurrentAnswer(['B', 'C']);

  await session.submit();
}

Session Browser Examples

Codex thread history is available through the read-only helpers in the sessions subpath.

import { CodexClient } from '@raylin01/codex-client';
import {
  listCodexSessionSummaries,
  readCodexSessionRecord
} from '@raylin01/codex-client/sessions';

const client = new CodexClient({ cwd: process.cwd() });
await client.start();

const summaries = await listCodexSessionSummaries(client, { limit: 10 });
const latest = summaries[0];

if (latest) {
  const record = await readCodexSessionRecord(client, latest.id);
  console.log('Thread:', record.summary.id);
  console.log('Transcript blocks:', record.transcript.length);
  console.log('Raw messages:', record.rawMessages.length);
}

await client.shutdown();

record.transcript normalizes prior Codex history, while record.rawSession and record.rawMessages keep the original thread data.

Raw Transport API

If you need direct JSON-RPC control, the original new CodexClient(...) API is unchanged.

Event Model

  • ready: initialize handshake complete
  • request: incoming JSON-RPC server request requiring a response
  • notification: incoming JSON-RPC notification
  • log: stderr output from app-server
  • error: protocol/process errors

API

new CodexClient(options)

  • cwd, codexPath, args, env
  • analyticsDefaultEnabled
  • clientInfo and capabilities

await CodexClient.init(options)

  • returns a StructuredCodexClient
  • accepts thread bootstrap options like resumeThreadId, forkThread, approvalPolicy, sandbox, and instructions
  • keeps the raw client available at client.raw

Core methods

  • start() and shutdown()
  • sendRequest(method, params)
  • sendResponse(id, result)
  • sendError(id, error)

Convenience wrappers

  • Threads: startThread, resumeThread, forkThread, listThreads, readThread, ...
  • Models: listModels, setDefaultModel
  • Config: readConfig, writeConfigValue, batchWriteConfig
  • Turns: startTurn, interruptTurn

Examples

See /examples:

  • basic.ts
  • events.ts
  • error-handling.ts

Troubleshooting

  • If startup fails, verify codex app-server runs from your shell.
  • Listen for log and error events to debug handshake failures.

Versioning

This package uses independent semver releases.

Used by DisCode

DisCode uses this package as a real-world integration example:

License

ISC