agentleFS
rjstonerjstone/agent-skills/skills/opencode-api/SKILL.md

opencode-api

Skill0 starsChanged 6 days agoMITView on GitHub

Use when calling or scripting the opencode server's HTTP API - sessions, prompts, messages, the event stream, PTYs and shells, files, MCP, config, permissions, worktrees, integrations - with curl, opencode api or another HTTP client, when reading the server's OpenAPI spec, or when unsure whether an opencode endpoint is v1 (/session, /event, /global/...) or v2 (/api/...).

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. dzianisv/skills★ 4same name
    2. pepebot-space/skills★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository10 other files it gives its agents.

The file

Files
SKILL.md

opencode server API (v2)

Overview

opencode v2 moved every server route under /api/ (POST /api/session, GET /api/event, GET /api/info), so the v1 routes you remember (/session, /event, /global/health, /doc) are probably wrong. Do not write opencode API calls from memory. Look each one up in the cached OpenAPI spec, references/openapi.json (~880 KB, 170 operations): search it with the script instead of reading it.

python scripts/api_lookup.py --tags                  # areas and operation counts
python scripts/api_lookup.py --list session          # operations in a tag (or matching text)
python scripts/api_lookup.py --op session.prompt     # params (with style), body, responses, opencode api + curl lines
python scripts/api_lookup.py --op POST /api/session  # same, by method and path
python scripts/api_lookup.py --schema Session        # one schema
python scripts/api_lookup.py --grep "fork session"   # words in ids, paths, summaries

Paths are relative to this skill's folder. --depth N limits how far $refs expand (default 3; use 1 for large bodies). When the spec and ERRATA.md disagree, ERRATA.md wins.

Calling the server

  • Easiest: opencode api <operationId> (or opencode api GET /api/...) talks to the running server with its connection and password already set: opencode api session.list --param limit=10, opencode api session.create --data '{"title": "x"}'. --op prints this form for each operation, and a curl line to adapt for other clients.
  • Other clients: HTTP Basic auth, user opencode, the server password (OPENCODE_PASSWORD, or set it with opencode service set password): curl -u opencode:$OPENCODE_PASSWORD http://127.0.0.1:<port>/api/info. opencode service status prints the address. Never print or log the password. Details: https://opencode.ai/docs/cli/web (Markdown: same URL + .md).
  • GET /api/info (server.info) returns the version, URLs and paths: a cheap first call to check the connection.
  • The running server does not serve its own spec (no route for it; v1's /doc is gone, checked 2026-11-08). The published copy is https://opencode.ai/docs/openapi.json, cached here.
  • Events: GET /api/event (event.subscribe) is a text/event-stream; filter with the types query parameter. It is volatile: a slow reader is dropped, and events during a disconnect are lost.
  • Location (72 of 170 operations take it): the query parameter location is an object (style: deepObject; --op flags it and prints the URL form): ?location[directory]=<url-encoded dir> (curl -g, or encode the brackets as %5B/%5D). On those operations a plain ?directory= is ignored (the server's default location answers; a few others, like session.list, have a real directory filter of their own), and ?location=<dir> → 400 InvalidRequestError "Expected object at ["location"]". opencode api fills it in for the current directory. Checked 2026-11-10 against opencode 2.2.6.
  • Plugin RPC: POST /api/rpc/{rpcID}/{method} (rpc.call) wraps the argument: body {"input": <value>} → {"output": <value>}. rpcID is the id in the plugin's Rpc.define. A bare argument as the body → rpc.invalid_input "Expected object".
  • Throwaway server (tests, sandboxes): opencode serve --hostname 127.0.0.1 --port <n> --print-logs prints server password <value> at startup; point XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME at a temp folder to keep it off your real setup. A location's plugins load in the background after its first request, so plugin-provided agents, skills, references and MCP servers appear a few seconds later.

Keeping it current

  • references/openapi.json is a verbatim copy; never edit it. Refresh with python scripts/refresh_references.py (--check reports staleness without writing). The docs page https://opencode.ai/docs/api/ is generated from the same file.
  • Found a mistake (the spec contradicts the running server)? Add an entry to ERRATA.md with the request, the response and the date.

Common mistakes

MistakeFix
v1 routes (/session/{id}/message, /event, /global/health)Look up the v2 operation: --grep, then --op
Reading openapi.json directlyapi_lookup.py; the file is far too large for context
curl without auth-u opencode:<password>, or use opencode api
Guessing a request body--op <id> shows the schema; --schema <Name> for nested types
?directory=<dir> or ?location=<dir>?location[directory]=<dir> (deep-object query)
RPC call with the bare argument as body{"input": <value>}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.