Skip to content
Back to skills

Opencode2 Self Management

ASecurity

Drive your own opencode2 session from inside an agents-sandbox VM - request a context compaction through the session.compact API, tell the TUI's --port server from the CLI's `serve --service` background service, refresh an edited skill or scope a skill query, or clean up a scratch `opencode2 serve` without killing the session's own daemon. Use when an agent is asked to compact/shrink its own context, when an edited skill "didn't change", when a project skill is missing from the bare /api/skil...

  • 93 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 9, 2026
ai-agentsshellsqltestingapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 4, 2026

npx -y skills add inoio/agents-sandbox --skill opencode2-self-management --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Opencode2 Self Management?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Opencode2 Self Management
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/inoio-opencode2-self-management/badge)](https://www.skillsdirectory.com/skills/inoio-opencode2-self-management)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: opencode2-self-management
description: Drive your own opencode2 session from inside an agents-sandbox VM - request a context compaction through the session.compact API, tell the TUI's --port server from the CLI's `serve --service` background service, refresh an edited skill or scope a skill query, or clean up a scratch `opencode2 serve` without killing the session's own daemon. Use when an agent is asked to compact/shrink its own context, when an edited skill "didn't change", when a project skill is missing from the bare /api/skill list, or before `pkill`-ing a scratch server.
---

# Managing your own opencode2 session from inside the VM

How an agent inside an agents-sandbox VM drives its own opencode2 session and finds its skills.
`opencode2` is on `PATH` (installed at `/opt/agents-sandbox/bin/opencode2`).

## Compact your own context

There is no `compact` tool in the tool catalog. Request a compaction through the API:

```sh
opencode2 api session.compact --param sessionID="$OPENCODE_SESSION_ID" -d '{}'
```

Delivery is `steer`: it fires at the next step boundary, so issue it as your last action. Exit 0 with a
`"type":"compaction"` body means the request was admitted; the generated summary replaces the conversation
afterwards. `$OPENCODE_SESSION_ID` is exported in the agent shell.

## Two servers, one database

A VM commonly runs two `opencode2 serve` processes: the one the TUI attached to (started with
`--hostname`/`--port`) and the CLI's managed background service (`serve --service`). They share the SQLite
database at `~/.local/share/opencode/opencode.db`, so `$OPENCODE_SESSION_ID` and `session list` resolve against
either. Bare CLI commands talk to the background service; pass `--server http://127.0.0.1:<port>` to target a
specific one. `opencode2 service status` prints the background-service URL; `opencode2 api get /api/info` prints
`{version,pid,urls,capabilities}` for whichever server answered.

## Never `pkill -f "opencode2 serve"`

The daemon the session runs on has the same argv shape as any scratch server (`opencode2 serve
--hostname 127.0.0.1 --port 4096`), so a broad pattern matches both and kills your own session. Clean up a
throwaway server by its recorded PID (`pid=$!` after the `nohup … &`, then `kill "$pid"`) or by its unique
port (`pkill -f 'port 4599'`), never by the binary and subcommand alone. The launcher's daemon is launched
directly as the agent binary (`opencode2 serve …`), so its argv has the same shape as a scratch server's; there
is no marker in argv to key on. The killed daemon is a launcher-owned job that restarts on the next client
attach, so the symptom is an `ECONNREFUSED` reconnect loop, not a permanent outage.

## Skill content is cached per location

opencode2 reads each skill's `SKILL.md` into per-location memory and serves that cached copy. A **new** skill is
registered without a reload, but **editing** an existing skill file does not change what the server serves until
it re-reads: `opencode2 api get /api/skill`, and a session loading the skill, keep returning the old text.
`opencode2 reload` refreshes it — it re-reads config, then tears down and restarts the location, aborting
in-flight tool calls with `Interaction cancelled because the location shut down`. A server restart does the same.
So when a skill you just edited "didn't change", reload before re-testing; a session that loaded the old content
keeps it until then.

Skills are scoped by location: `GET /api/skill?location[directory]=<dir>` returns the global skills plus that
directory's `.agents/skills`. The bare `/api/skill` reports the *server's own* location, so a project skill can
be missing from it while still available to a session in that project — scope the query before concluding a
skill is absent.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.