Install
$ agentstack add skill-dzianisv-skills-opencode-api ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ● Network access Used
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
OpenCode REST API
Use this skill when you need reliable, scriptable control of OpenCode over HTTP.
Default OpenCode server base URL: http://localhost:4096.
Canonical docs: https://opencode.ai/docs/server/
Quick Start
Start a local, protected server:
export OPENCODE_SERVER_USERNAME=opencode
export OPENCODE_SERVER_PASSWORD="change-me"
opencode serve --hostname 127.0.0.1 --port 4096
Basic API helper:
api() {
curl -sS --fail \
-u "$OPENCODE_SERVER_USERNAME:$OPENCODE_SERVER_PASSWORD" \
-H 'Content-Type: application/json' "$@"
}
Health check:
api "http://127.0.0.1:4096/global/health"
Core Flow
- Check server health with
GET /global/health. - List sessions with
GET /session. - Create a session with
POST /sessionif needed. - Send work with
POST /session/{id}/messageorPOST /session/{id}/prompt_async. - Track progress via
GET /session/statusand SSEGET /event. - Resolve permission requests through
POST /session/{id}/permissions/{permissionID}.
Minimal Request Examples
Create a session:
api -X POST "http://127.0.0.1:4096/session" \
-d '{"title":"billing-platform-service#761 follow-up"}'
Send a normal prompt (waits for response):
api -X POST "http://127.0.0.1:4096/session/SESSION_ID/message" \
-d '{
"parts": [
{"type":"text","text":"Address unresolved PR feedback and summarize changes."}
]
}'
Send async prompt (fire-and-track):
api -X POST "http://127.0.0.1:4096/session/SESSION_ID/prompt_async" \
-d '{
"parts": [
{"type":"text","text":"Apply requested review updates and report status."}
]
}'
Reply to permission request:
api -X POST "http://127.0.0.1:4096/session/SESSION_ID/permissions/PERMISSION_ID" \
-d '{"response":"allow","remember":true}'
Stream events (SSE):
curl -N -u "$OPENCODE_SERVER_USERNAME:$OPENCODE_SERVER_PASSWORD" \
"http://127.0.0.1:4096/event"
API Surface You Will Use Most
GET /doc- OpenAPI spec source of truth.GET /session- enumerate sessions.GET /session/status- status for all sessions in one call.GET /session/{id}/message- read conversation state.GET /session/{id}/todo- inspect tracked tasks.POST /session/{id}/message- synchronous prompt.POST /session/{id}/prompt_async- asynchronous prompt.POST /session/{id}/abort- cancel stuck work.GET /session/{id}/diff- inspect produced code changes.GET /find,GET /find/file,GET /file/content- pre-read context before prompting.
Performance and Reliability Optimizations
- Keep one long-lived server process per workspace to avoid repeated startup and warm-up.
- Prefer SSE (
/event) over tight polling loops for status changes. - Use
/prompt_asyncfor fan-out workflows; use/session/statusfor cheap centralized progress checks. - Pull context with
/findand/file/contentfirst; then send narrower prompts to reduce token usage. - Use stable session titles like
#to make future lookups deterministic. - Handle
permission.updatedevents immediately to avoid idle stalls. - Use
query.directorywhen driving multiple projects from one controller. - Reuse a keep-alive HTTP client instead of spawning short-lived
curlin high-volume automation.
Security Guardrails
- Default bind should stay
127.0.0.1. - Always set basic auth if the server is reachable by other processes or hosts.
- Keep CORS explicit and minimal (
--corsonly for trusted origins). - If exposed remotely, put TLS and access control in front of OpenCode.
Error Handling
400usually means payload shape mismatch; verify against/doc.404usually means wrong session/message/permission ID.- If a session appears stuck, call
/session/{id}/abort, then post a refined follow-up prompt.
Email-Driven Follow-Up Pattern
For PR-review automation:
- Ingest actionable review emails from Gmail triage.
- Extract
repo,pr_number, and requested change. - Find or create session titled
# review-followup. - Post follow-up via
/prompt_async. - Watch
/eventfor completion, permission, and error events. - Pull
/session/{id}/diffand/session/{id}/todofor summary output.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: dzianisv
- Source: dzianisv/skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.