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   ● alive    Up 5m     org_a       u_1     ~/Developer/myproject
  81fa29acb3e9210f   12088   58411   ● alive    Up 3m     org_b       u_2     ~/Developer/myproject
opencode-runtime health 39dce5beb4debfaa
opencode-runtime stop-all

Guides

Requirements

  • Python 3.10+
  • opencode 1.0+ on PATH

Contributing

See CONTRIBUTING.md.

License

Apache 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencode_runtime-0.4.1.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencode_runtime-0.4.1-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file opencode_runtime-0.4.1.tar.gz.

File metadata

  • Download URL: opencode_runtime-0.4.1.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opencode_runtime-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a42686c8eb4b0c43f7c03c5b48550d82c8f23347c7df81132e66df265f4b306d
MD5 ed0258a3a4d79d36b1827063b088d661
BLAKE2b-256 489651659b91184c5d6b98741ea3f41756158981c6729c65be61ff80046ad228

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_runtime-0.4.1.tar.gz:

Publisher: publish.yml on ashish16052/opencode-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opencode_runtime-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for opencode_runtime-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47d1261772adbb44f441301c29eef4f8ab43eda6c5033de61c3819390707f14a
MD5 54480656e3ab8bd9b2fda7841ee59f48
BLAKE2b-256 c196965aa2a18f75d8457bdc38806cb3f79a60a66133f55334e2583013466ee2

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_runtime-0.4.1-py3-none-any.whl:

Publisher: publish.yml on ashish16052/opencode-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.0

2 files

This release

0.4.1 This release

2 files

0.4.0

2 files

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