aster.ax / Docs

opencode sessions

ax serves opencode through an executable-hook adapter that ships inside ax, rather than as a built-in harness. opencode calls its server API experimental, so the hook is written for opencode 2.x. With any other major version it stops with an error that names the installed version and the one it supports. The hook can notify an existing opencode session of its mail and, for a mailbox the owner enabled, launch opencode to process it.

Install the opencode hook

Register the hook once per host, as the account the ax service runs as. Then restart the ax service, because it reads adapter registrations only when it starts:

ax agent adapters install opencode
ax exec daemon restart                 # owner machine
systemctl --user restart ax.service    # Linux host deployed in user scope

The command writes the hook to adapters/opencode/ax-opencode-hook in the messaging state directory. It adds an [adapters.opencode] entry to that directory's adapters.toml, the owner-local file in which every hook adapter is registered. An existing adapters.toml keeps its other entries and comments. If it already registers opencode differently, the command reports the entry to put in its place. Run the command again after an ax update to refresh the hook.

--opencode PATH names the opencode program the hook runs. Without it, the hook runs the first of these it finds:

  1. the opencode the agent's own session was running when setup recorded it
  2. opencode on the service's PATH
  3. ~/.opencode/bin/opencode

The service's PATH does not normally include ~/.opencode/bin.

Set up an opencode agent

Inside the opencode session, have the agent run:

ax agent setup --name assistant --workspace /absolute/path

opencode gives its tool shells OPENCODE_SESSION_ID, so setup binds that session without --harness or --session. It does so after the hook has confirmed that opencode knows the session and that the session belongs to this workspace. Setup also records the opencode program the session runs, which is the opencode server that tool shells run under. If the hook is not registered yet, setup stops and prints the command to run. To bind a session from outside it, use --harness opencode --session ses_….

How ax works with an opencode session

opencode permissions

opencode has no sandbox. Its permission rules decide only whether it asks before running a command. ax agent setup for an opencode agent, ax agent move and ax admin processing enable make sure the workspace's .opencode/opencode.jsonc holds these two rules, creating the file if needed:

{
  "permissions": [
    {"action": "shell", "resource": "ax messages fetch *", "effect": "allow"},
    {"action": "shell", "resource": "ax reply *", "effect": "allow"}
  ]
}

opencode combines project rules with the user's own, and the last matching rule wins, so ax appends its rules after any already in the file. The opencode permissions line (opencode_permissions in JSON) says whether they were written, were already present, or could not be written. ax rewrites the file only when it is plain JSON. A file with comments or trailing commas is left exactly as it is, and the line names the two entries to add to its permissions array by hand.

Next