Control Claude Code, AmazonQ, Opencode, Goose, Aider, Gemini, GitHub Copilot, Sourcegraph Amp, Codex, Auggie, and Cursor CLI with an HTTP API.
You can use AgentAPI:
agentapi:bash
OS=$(uname -s | tr "[:upper:]" "[:lower:]");
ARCH=$(uname -m | sed "s/x86_64/amd64/;s/aarch64/arm64/");
curl -fsSL "https://github.com/coder/agentapi/releases/latest/download/agentapi-${OS}-${ARCH}" -o agentapi && chmod +x agentapi
Alternatively, you can download the latest release binary from the releases page.
bash
agentapi --help
On macOS, if you're prompted that the system was unable to verify the binary, go to
System Settings -> Privacy & Security, click "Open Anyway", and run the command again.
claude is installed on your system and in the PATH):bash
agentapi server -- claude
If you're getting an error that
claudeis not in thePATHbut you can run it from your shell, trywhich claudeto get the full path and use that instead.
bash
curl -X POST localhost:3284/message \
-H "Content-Type: application/json" \
-d '{"content": "Hello, agent!", "type": "user"}'
bash
curl localhost:3284/messages
agentapi serverRun an HTTP server that lets you control an agent. If you'd like to start an agent with additional arguments, pass the full agent command after the -- flag.
agentapi server -- claude --allowedTools "Bash(git*) Edit Replace"
You may also use agentapi to run the Aider and Goose agents:
agentapi server -- aider --model sonnet --api-key anthropic=sk-ant-apio3-XXX
agentapi server -- goose
[!NOTE] When using Claude, Codex, Opencode, Copilot, Gemini, Amp or CursorCLI, always specify the agent type explicitly (eg:
agentapi server --type=codex -- codex), or message formatting may break.
An OpenAPI schema is available in openapi.json.
By default, the server runs on port 3284. Additionally, the server exposes the same OpenAPI schema at http://localhost:3284/openapi.json and the available endpoints in a documentation UI at http://localhost:3284/docs.
There are 4 endpoints:
/messages - returns a list of all messages in the conversation with the agent/message - sends a message to the agent. When a 200 response is returned, AgentAPI has detected that the agent started processing the message/status - returns the current status of the agent, either "stable" or "running"/events - an SSE stream of events from the agent: message and status updatesBy default, the server only allows requests with the host header set to localhost. If you'd like to host AgentAPI elsewhere, you can change this by using the AGENTAPI_ALLOWED_HOSTS environment variable or the --allowed-hosts flag. Hosts must be hostnames only (no ports); the server ignores the port portion of incoming requests when authorizing.
To allow requests from any host, use * as the allowed host.
agentapi server --allowed-hosts '*' -- claude
To allow a specific host, use:
agentapi server --allowed-hosts 'example.com' -- claude
To specify multiple hosts, use a comma-separated list when using the --allowed-hosts flag, or a space-separated list when using the AGENTAPI_ALLOWED_HOSTS environment variable.
agentapi server --allowed-hosts 'example.com,example.org' -- claude
# or
AGENTAPI_ALLOWED_HOSTS='example.com example.org' agentapi server -- claude
By default, the server allows CORS requests from http://localhost:3284, http://localhost:3000, and http://localhost:3001. If you'd like to change which origins can make cross-origin requests to AgentAPI, you can change this by using the AGENTAPI_ALLOWED_ORIGINS environment variable or the --allowed-origins flag.
To allow requests from any origin, use * as the allowed origin:
agentapi server --allowed-origins '*' -- claude
To allow a specific origin, use:
agentapi server --allowed-origins 'https://example.com' -- claude
To specify multiple origins, use a comma-separated list when using the --allowed-origins flag, or a space-separated list when using the AGENTAPI_ALLOWED_ORIGINS environment variable. Origins must include the protocol (http:// or https://) and support wildcards (e.g., https://*.example.com):
agentapi server --allowed-origins 'https://example.com,http://localhost:3000' -- claude
# or
AGENTAPI_ALLOWED_ORIGINS='https://example.com http://localhost:3000' agentapi server -- claude
agentapi attachAttach to a running agent's terminal session.
agentapi attach --url localhost:3284
Press ctrl+c to detach from the session.
AgentAPI runs an in-memory terminal emulator. It translates API calls into appropriate terminal keystrokes and parses the agent's outputs into individual messages.
There are 2 types of messages:
To parse individual messages from the terminal output, we take the following steps:
This lets us split the terminal output into a sequence of messages.
Each agent message contains some extra bits that aren't useful to the end user:
AgentAPI automatically removes these.
> or ------.Splitting the terminal output into a sequence of messages should still work, since it doesn't depend on the TUI structure. The logic for removing extra bits may need to be updated to account for new elements. AgentAPI will still be usable, but some extra TUI elements may become visible in the agent messages.
Pending feedback, we're considering the following features:
In the short term, AgentAPI solves the problem of how to programmatically control coding agents. As time passes, we hope to see the major agents release proper SDKs. One might wonder whether AgentAPI will still be needed then. We think that depends on whether agent vendors decide to standardize on a common API, or each sticks with a proprietary format.
In the former case, we'll deprecate AgentAPI in favor of the official SDKs. In the latter case, our goal will be to make AgentAPI a universal adapter to control any coding agent, so a developer using AgentAPI can switch between agents without changing their code.
$ claude mcp add agentapi \
-- python -m otcore.mcp_server <graph>