native-agent-api

module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0

README

native-agent-api

CI OpenSSF Scorecard License

An HTTP API for Claude Code and Codex CLI. native-agent-api runs the real coding-agent CLI and serves it over REST, Server-Sent Events and WebSocket. Sessions, login, tools, skills, hooks, plugins, subagents and MCP servers keep working exactly as in a terminal.

Status: 0.x. The API may still change between minor versions; see the changelog.

Why

The AI providers' own CLIs are excellent agents. Claude Code and Codex CLI manage sessions, run tools, skills, hooks, plugins and MCP servers, and sign in with your subscription. But they are built for a person at a terminal on one machine.

Once the CLI runs on a server or another computer, reaching it takes extra tools:

  • SSH with tmux or screen
  • remote desktops such as RustDesk, VNC or Chrome Remote Desktop
  • browser terminals such as ttyd
  • agent apps with remote companions, such as Orca or Hermes Desktop

These give a person a screen. They do not give your software an interface.

native-agent-api turns the native CLI into a service:

  • Reach it from anything. Web apps, mobile apps, bots, scripts and other services talk to the agent over plain HTTP, SSE or WebSocket, from any language.
  • Use your subscription, not an API key. The CLI keeps its own login, so a Claude or ChatGPT plan you already have can power your projects and personal tools. Check the provider's terms first (see Notes).
  • Native, not re-implemented. The gateway drives the CLI's own protocol. Every native event reaches the client unchanged, and the agent's features keep working.
  • One API for both agents. Runs, sessions, events, permissions and usage look the same for Claude Code and Codex CLI. Agent-only data stays in a typed provider section.
  • Your machine, your control. The gateway runs next to the CLI. No third-party service sits between your client and the agent.

Features

Area What you get
Runs One-shot asks, or interactive runs you can message, interrupt, close and cancel
Sessions Continue with remembered settings, fork, list and delete
Live events SSE and WebSocket; reconnect without losing events; optional partial output
Permissions Approve or deny each tool use from the client, once or for a session or workspace
Workspaces Managed workspaces with a file API, or attached project directories
Native features Tools, skills, hooks, plugins, subagents, MCP servers, native control requests
Results and usage Structured output, turn and session tokens, context window, cost (Claude Code), subscription allowance
Agent management Login without a terminal, logout, status, model list, diagnostics
Security Token auth, IP allowlist, DNS-rebinding and cross-origin protection, redacted logs
Operation Explicit configuration, generated OpenAPI 3.1, optional hardened Docker setup

Per-agent details are in the roadmap and feature status.

How a run works

sequenceDiagram
    autonumber
    participant C as Client
    participant G as native-agent-api
    participant A as claude / codex
    C->>G: POST /v1/runs/start (prompt, model, workspace)
    G->>A: Start the CLI and send the prompt over stdio
    A-->>G: Native events
    G-->>C: agent events over SSE or WebSocket
    A-->>G: Tool permission request
    G-->>C: permission_request
    C->>G: Allow once, for the session or for the workspace
    G->>A: Native permission answer
    A-->>G: Result and usage
    G-->>C: turn event with result, tokens and cost
    Note over C,A: Later: POST /v1/sessions/{id}/continue or /fork

Supported agents

Agent Native CLI Tested CLI version Support
claude Claude Code 2.1.318 Support details
codex Codex CLI 0.167.0 Support details

The adapters are verified against the tested CLI version, which the Docker images install. Other versions can differ in commands, flags and events. GET /v1/agent reports both the installed cli.version and cli.tested_version.

One gateway process serves one agent. Run two processes to serve both. Each has its own login, port and token, and both speak the same API. Two processes can attach the same directory, so both agents work on the same files.

Two native-agent-api containers, one running Claude Code and one running Codex CLI. Your applications reach both over the same REST, SSE and WebSocket interface, and both agents work in one shared project directory.

With Docker, each installation is one container with its own volumes; see several installations.

Quick start

Requires macOS or Linux. The fastest way is make setup: it asks how to run the gateway, writes the env files, creates the client token and starts the gateway.

git clone https://github.com/emreuyguc/native-agent-api && cd native-agent-api
make setup
Choice in make setup Needs Agent login
Docker, published image (fastest) Docker with Compose v2 Through the API, once per installation
Docker, image built from source Docker with Compose v2 Through the API, once per installation
Host, built from source Go, the agent CLI on PATH The CLI's login on this machine
Host, installed binary A release binary (verify it), the agent CLI on PATH The CLI's login on this machine

To set up by hand on the host:

go install ./cmd/native-agent-api
cp .env.example .env && chmod 600 .env   # every setting is explicit; review the file
native-agent-api new-token               # client token for $TOKEN, digest for NATIVE_AGENT_TOKEN_SHA256
native-agent-api login claude
native-agent-api serve --env-file .env

In Docker, follow Docker setup. Then send a first request; a Docker installation uses its published port, such as 8701:

curl -s http://127.0.0.1:8080/v1/ask -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"prompt":"Explain HTTP/2 in one sentence.","model":{"id":"sonnet","effort":"low"}}' | jq -r .result.text

The interactive API reference is served at /docs, and the OpenAPI 3.1 document at /openapi.yaml.

Documentation

Notes

native-agent-api is an independent project, not affiliated with Anthropic or OpenAI. It uses the CLI and the login you provide; your use of each CLI and account stays subject to that provider's terms, so check them before serving a personal subscription to other people or applications.

Vulnerabilities: see SECURITY.md. Contributions: see CONTRIBUTING.md. License: Apache-2.0.

Directories

Path Synopsis
cmd
native-agent-api command
Command native-agent-api exposes native coding-agent CLIs over HTTP.
Command native-agent-api exposes native coding-agent CLIs over HTTP.
internal
agent
Package agent defines the contract between the gateway and native coding agent CLIs.
Package agent defines the contract between the gateway and native coding agent CLIs.
agent/agenttest
Package agenttest provides a scriptable agent.Agent for tests of the run manager and the HTTP API.
Package agenttest provides a scriptable agent.Agent for tests of the run manager and the HTTP API.
agent/builtin
Package builtin is the single list of agent adapters compiled into the gateway.
Package builtin is the single list of agent adapters compiled into the gateway.
agent/claude
Package claude runs the native Claude Code CLI in non-interactive stream-json mode.
Package claude runs the native Claude Code CLI in non-interactive stream-json mode.
agent/codex
Package codex adapts the native Codex CLI app-server protocol to the common agent contract.
Package codex adapts the native Codex CLI app-server protocol to the common agent contract.
buildinfo
Package buildinfo exposes product identity and build metadata.
Package buildinfo exposes product identity and build metadata.
cli
Package cli implements the native-agent-api command line.
Package cli implements the native-agent-api command line.
config
Package config loads and validates the gateway configuration from environment variables.
Package config loads and validates the gateway configuration from environment variables.
fsroot
Package fsroot decides which host directories the gateway may hand to an agent.
Package fsroot decides which host directories the gateway may hand to an agent.
httpapi
Package httpapi exposes the gateway over HTTP.
Package httpapi exposes the gateway over HTTP.
ids
Package ids generates and validates the opaque identifiers used by the gateway.
Package ids generates and validates the opaque identifiers used by the gateway.
iox
Package iox holds small io helpers shared by the gateway packages.
Package iox holds small io helpers shared by the gateway packages.
logx
Package logx builds the gateway logger and defines the level policy used in the code.
Package logx builds the gateway logger and defines the level policy used in the code.
permission
Package permission keeps the permissions a client granted beyond a single request.
Package permission keeps the permissions a client granted beyond a single request.
proctree
Package proctree starts native CLI processes and stops them with everything they started.
Package proctree starts native CLI processes and stops them with everything they started.
redact
Package redact removes credentials and control characters from text that leaves the gateway (API error messages, logs).
Package redact removes credentials and control characters from text that leaves the gateway (API error messages, logs).
run
Package run executes agent conversations in the background and records their events.
Package run executes agent conversations in the background and records their events.
session
Package session persists gateway-owned session metadata and coordinates active runs.
Package session persists gateway-owned session metadata and coordinates active runs.
workspace
Package workspace manages workspace directories and the file operations exposed over the API.
Package workspace manages workspace directories and the file operations exposed over the API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL