Integration guide

Claude Code as a Service: Headless, Multi-Tenant, via API

How to run Claude Code headless behind your product: the API contract, multi-tenant authorization, per-task sandbox isolation, document skills, and configuration comparison.

Short answer

Claude Code as a service means running Anthropic's Claude Code harness headless behind an HTTP API instead of at a terminal: your product submits tasks, streams progress to end users, persists sessions and files, and receives results and artifacts, while each task executes in an isolated sandbox. HarnessRouter provides this as a managed service through one API.

  • Claude Code is a complete agent harness that works on a real working tree: it edits files, runs commands, delegates to sub-agents, and iterates until the task is done.
  • Turning it into a service adds what the terminal never needed: an HTTP contract, multi-tenant authorization, per-task isolation, and durable sessions.
  • Through HarnessRouter, a Claude Code task returns whatever the work produces: code changes, generated files, and reviewable artifacts. Document skills come preloaded, and the capability surface extends further: a configured agent can load custom skills and connect MCP tools your product chooses.

A terminal tool and a service are different jobs

Anthropic documents Claude Code as an agentic coding tool that works in a real working tree with the shell: reading and editing files, running tests, and coordinating sub-agents to complete engineering tasks end to end. It even ships a headless print mode (claude -p with JSON output) for scripts and CI. That is a complete agent harness, and for a developer at a terminal or a pipeline it needs nothing more. Headless, however, is still not a service: the process runs on infrastructure you operate, invoked by whoever controls that machine, with no product contract around it. A service needs four things the CLI does not provide:

  • An HTTP contract: tasks submitted by your server, not commands typed by a developer.
  • Multi-tenancy: many end users and tenants sharing the capability without seeing each other's work.
  • Isolation: each task in its own sandbox, keeping runs separated from other users' work and from your infrastructure.
  • Product-level durability: sessions, files, and results held for each end user, which your server can authorize, continue, and hand back, beyond the machine-local persistence the CLI keeps for its operator.

The API shape

Through HarnessRouter, Claude Code runs behind the same contract as every other harness:

Input
A product task, the claude-code harness selection, a model from the current catalog, optional files, and execution policy.
Lifecycle
A durable session with status, streamed progress events, continuation, and cancellation.
Output
Code changes, finished documents, generated files and artifacts, and a recorded execution trace for every run.

Multi-tenant authorization and isolation

Two responsibilities split cleanly between your server and the platform. The platform isolates execution: an isolated sandbox spins up for each task automatically, and there is no execution infrastructure for your team to size, patch, or babysit. Your server owns tenant authorization, following the server-side proxy pattern:

  • Keep the API key server-side; browsers never call the execution API directly.
  • Derive the current user and tenant from your product's trusted session, never from browser-submitted identifiers.
  • Map every session, response, and file ID returned by the API to its owning user or tenant, and check that mapping before every continue, cancel, preview, or download.
  • Return a product-level denial when ownership cannot be proven.

Documents, custom skills, and MCP tools

Claude Code as a service is not limited to code changes. HarnessRouter runs Claude Code with the docx, pdf, pptx, and xlsx document skills preloaded, so a product task can return finished documents your app renders and your users download: the same harness that refactors a repository can produce a formatted report from uploaded files. And the preloaded set is a floor, not a ceiling. A configured agent can load custom skills and connect MCP servers, so the task surface grows with whatever your product wires in, from media workflows to browser and computer-use style tooling available in the MCP ecosystem.

Treat the configuration as a hypothesis

No single harness or model setup wins every task. Claude Code pairs with a model you select per task, and the right pairing is workload-specific: in HarnessRouter's same-task benchmark, cost across harness and model configurations varied by about 475x on identical work, and results vary by task. Because every harness runs behind the same contract, the comparison is a parameter change: run your real task on Claude Code and on other configurations, read the recorded traces, and promote the winner on evidence.

Running your first Claude Code task

  • Create a key and send a task to the claude-code harness through the quickstart; building and integration are free, and credits are used only when tasks run.
  • Stream progress into your product UI, then fetch results, files, and artifacts when the run completes.
  • Continue the session for revisions instead of restarting from zero.
  • Use the claude-code harness ID when the task should return code changes or finished documents your app can review.

FAQ

Does Claude Code have an official API?
Anthropic offers several first-party paths: the Claude Code CLI with a headless print mode for scripts and CI, the Claude Agent SDK as a library that runs the agent loop in your own infrastructure, and Managed Agents, a hosted REST API where Anthropic runs the agent and the sandbox. What HarnessRouter adds is the cross-vendor layer: one contract that runs Claude Code alongside Codex and Hermes, with the same sessions, streaming, files, and execution traces across all of them, so your product can compare configurations and switch without a rewrite.
Is running Claude Code multi-tenant safe?
Execution is isolated by the platform: each task runs in its own sandbox provisioned on demand. Tenant separation at the product level is your server's job: derive identity from your trusted session, map returned session and file IDs to their owners, and check that mapping before every operation on existing work.
Can end users continue or revise previous Claude Code work?
Yes. Sessions and files persist across runs, so your product can offer continue and revise flows: the user returns, your server checks ownership of the session, and the next task picks up where the last one finished.
How do I know Claude Code is the right harness for my feature?
Measure instead of assuming. Run a representative task on Claude Code and on other harness and model configurations through the same API, apply a success threshold, then compare cost, latency, and artifact quality from the recorded traces. The published same-task benchmark shows the format.

Run Claude Code as a service today

Headless, multi-tenant, isolated per task, with sessions and artifacts your product controls.

Start building free