StateJar docs

OpenCode

The opencode-statejar plugin adds the memory each message needs to OpenCode's system prompt, captures your messages with secrets removed, and comes with StateJar's tools. Add it and the MCP server to opencode.json.

What it does

The plugin is opencode-statejar on npm, open source (MIT) in statejar-integrations.

Install

You need OpenCode 1.19 or later. Add the plugin and the MCP server to opencode.json, in your project or in ~/.config/opencode/opencode.json for every project:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-statejar"],
  "mcp": {
    "statejar": {
      "type": "remote",
      "url": "https://statejar.com/mcp",
      "oauth": false,
      "headers": { "Authorization": "Bearer {env:STATEJAR_API_KEY}" }
    }
  }
}

OpenCode installs the plugin from npm at its next start. {env:STATEJAR_API_KEY} keeps the key out of the file.

Tools only, without the plugin: keep the mcp block and leave out plugin.

Set it up

Make a developer key on the API keys page and put it in the environment OpenCode runs in:

export STATEJAR_API_KEY="sj_live_…"        # macOS, Linux
setx STATEJAR_API_KEY "sj_live_…"          # Windows: a new terminal picks it up

The other options are variables, or the plugin's options in opencode.json ("plugin": [["opencode-statejar", { "scope": "my-project" }]]):

VariableOptionDefaultWhat it does
STATEJAR_SCOPEscopeopencodeThe scope in your account the plugin reads and writes. A new scope builds on your newest memory.
STATEJAR_AUTO_CAPTUREautoCapturetrueQueue your messages and send them in batches.
STATEJAR_RECALL_EACH_PROMPTrecallEachPrompttrueAdd the memory each message needs, as one audited query per message.
STATEJAR_API_URLapiUrlhttps://api.statejar.com/api/v1The REST API the plugin calls.

If STATEJAR_API_KEY is empty, the plugin uses the key that statejar login (the statejar package on PyPI) keeps. The MCP tools still need the variable.

Check it works

  1. opencode mcp list shows statejar connected.
  2. In a session, say "I'm Kavya, I live in Bengaluru and my laptop budget is 80000 rupees." Then exit OpenCode.
  3. Start OpenCode again and ask "what is my laptop budget?". The answer uses the budget and names the handle it came from.
  4. Ask for StateJar's status. The statejar_status tool shows the scope, what is queued, and the last batch's status (202 when accepted).

What it sends

Troubleshooting

This page as Markdown: /docs/opencode.md