JSPM

  • Created
  • Published
  • Downloads 4191
  • Score
    100M100P100Q126222F
  • License SEE LICENSE IN LICENSE

grāmatr lifecycle plugin for OpenCode — maps OpenCode plugin events to grāmatr hooks via the connected MCP client (route_request injection, session continuity, git-gate).

Package Exports

  • @gramatr/opencode-plugin

Readme

grāmatr

@gramatr/opencode-plugin

Real-time intelligent context engineering, in OpenCode.

Install in 30 seconds

Add both entries to your opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "gramatr": {
      "type": "remote",
      "url": "https://api.gramatr.com/mcp",
      "enabled": true
    }
  },
  "plugin": [
    "@gramatr/opencode-plugin"
  ]
}

Restart OpenCode. It will fetch the plugin from npm at startup (no global install required) and prompt you through OAuth Device Authorization (RFC 8628) on first connect — visit the short URL, paste the user code, you're in. Works in SSH, WSL, and CI where browser redirects can't reach the client. Tokens are stored by OpenCode's MCP client; the plugin never handles raw credentials.

If you don't have a grāmatr account yet, sign up at gramatr.com.

What this gets you

  • Cheaper, faster prompts. A multi-head classification pipeline pre-routes each request and replaces the tens-of-thousands-token system prompt you'd otherwise hand-maintain. The effect compounds the longer you work.
  • Consistent behavior across sessions. The same contract — directives plus quality gates — runs on every prompt, so your AI acts the same on session 200 as on session 1.
  • Continuity across tools. A session you start in OpenCode resumes cleanly in Claude Code, Cursor, or the web — the handoff is persisted by the same backend.
  • Auditable safety rails. Per-prompt hard gates (e.g. git push --force to main is blocked locally before the tool runs).

What this package is

@gramatr/opencode-plugin is a lifecycle plugin for OpenCode. It maps OpenCode's plugin events (session.created, message.updated, tool.execute.before, session.idle, session.compacted) to grāmatr hooks — pre-classifying every prompt through the remote MCP server at api.gramatr.com/mcp, restoring session continuity on start, and enforcing git-gate hard rules before destructive shell commands run. The same intelligent context engineering layer used across Claude Code, ChatGPT, Cursor, Codex, and Gemini.

How it works

OpenCode
   │
   ├── plugin: @gramatr/opencode-plugin  ──┐
   │                                       │ lifecycle events
   │                                       │ (session.created, message.updated, …)
   │                                       ▼
   └── mcp.gramatr (remote, OAuth) ──► api.gramatr.com/mcp
                                       (route_request, load_handoff,
                                        save_reflection, …)

The plugin is a thin connector: every grāmatr hook is invoked against the already-connected remote MCP server declared in the mcp block — there is no local binary, no execSync, no shell-out. Guidance from the server is injected into the active session as a noReply system message so the model sees it before formulating its next response.

When OpenCode's plugin API exposes a typed client.callTool(), the connector will switch to direct MCP tool invocation and drop the prompt-injection path.

Requirements

  • OpenCode with @opencode-ai/plugin ≥ 1.0.0
  • Node.js ≥ 22
  • Network access to https://api.gramatr.com/mcp

License

See LICENSE in this package.