Skip to main content

opencode-runtime

Embed OpenCode in your Python application.

OpenCode is a great CLI coding agent. But to embed it in a product, SaaS backend, or multi-user automation system, you need more than a CLI process.

opencode-runtime turns OpenCode into a managed application runtime for Python. It uses OpenCode as the agent harness and adds what you need to run it as part of an application: lifecycle management, per-user workspaces, reusable sessions, health checks, streaming output, and multi-server orchestration.

Install

pip install opencode-runtime
npm install -g opencode-ai   # opencode must be on PATH

Use

Your first session

from opencode_runtime import OpenCodeRuntime

async with OpenCodeRuntime() as r:
    session = await r.session()
    response = await session.ask("Explain this repo")
    print(response.text)

One server per user, automatically

Every (workspace, user_id) pair gets its own isolated server, workspace, and conversation history — started on first use, reused after:

async with OpenCodeRuntime(runtime_dir=".opencode-runtime") as r:
    s1 = await r.session(workspace="org_a", user_id="u_1")
    s2 = await r.session(workspace="org_b", user_id="u_2")

Stream every token as it arrives

async for event in session.stream("Review this PR"):
    if event.type == "message.part.delta" and event.text:
        print(event.text, end="", flush=True)

Inspect

Servers started from Python are visible and manageable from the terminal:

opencode-runtime ps
  ID                  PID    PORT    STATUS      UPTIME    WORKSPACE   USER    PROJECT
  ───────────────────────────────────────────────────────────────────────────────────
  39dce5beb4debfaa   12051   58409   ● running   5m        org_a       u_1     ~/Developer/myproject
  81fa29acb3e9210f   12088   58411   ● running   3m        org_b       u_2     ~/Developer/myproject
opencode-runtime health 39dce5beb4debfaa
opencode-runtime inspect 39dce5beb4debfaa
opencode-runtime stop-all

Guides

Requirements

  • Python 3.10+
  • opencode 1.0+ on PATH

Contributing

See CONTRIBUTING.md.

License

Apache 2.0

Metadata

Release files for opencode-runtime 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opencode-runtime 0.5.0
File Size Uploaded Provenance
opencode_runtime-0.5.0.tar.gz 43.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for opencode-runtime 0.5.0
File Interpreter ABI Platform
opencode_runtime-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.6 kB

Release files / opencode_runtime-0.5.0.tar.gz

Download URL opencode_runtime-0.5.0.tar.gz
Size 43.6 kB
Tags Source
SHA-256 checksum
How to use checksums
708f63a7bf425c6a1e13fd4d3012c747ce4e6571b31c7f711fa831d7b5881882
BLAKE2b-256 checksum
How to use checksums
210bb3f2690c57b534d64e26b097c4dea9b442c7bbfa925e5b049873f8321287
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Release files / opencode_runtime-0.5.0-py3-none-any.whl

Download URL opencode_runtime-0.5.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9bea5165f3f4f7f843e0ceccf2372df6bb2f522699a36e4527bbabe5061eb85
BLAKE2b-256 checksum
How to use checksums
9cdd1aa319ee2ef6c57aa0607ce67073bf8466f5fb1fe8a5a92e4824924e4c28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Security for opencode-runtime 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for opencode_runtime-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page