Skip to content

Repository files navigation

opencode-hypa

Hardwire Hypa into OpenCode — no MCP required.

npmCILicense: MIT

OpenCode plugin that intercepts bash / shell tool calls and rewrites them through hypa rewrite --json before execution. Noisy command output is compressed locally and deterministically — the same hardwire pattern Hypa uses for Claude, Codex, and Pi.

OpenCode bash tool call
↓
opencode-hypa plugin
↓
hypa rewrite --json
↓
hypa git … / hypa -c "…"
↓
errors · warnings · failing tests · exit codes

Install

opencode plugin opencode-hypa --global

Or add to ~/.config/opencode/opencode.json / opencode.json:

{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-hypa"]
}

Requirements

  • OpenCode with plugin support
  • Node.js 18+ (or Bun) for the plugin runtime
  • Hypa available via PATH, or installed as this package’s dependency (@hypabolic/hypa)

What it does

Hypa outcomePlugin behavior
Rewritten / GenericWrapperReplaces the bash command with Hypa’s rewritten form
PassthroughLeaves the original command alone
DenyBlocks the tool call
AskBlocks by default; set OPENCODE_HYPA_ASK_NON_INTERACTIVE=allow to proceed
Rewrite error / timeoutFails open — runs the original command

Commands that already start with hypa are never double-wrapped.

Agent visibility

When Hypa rewrites a command, OpenCode would otherwise hand the LLM a tool result whose title shows the rewritten command (hypa git log …) with no marker that a plugin changed it. The LLM can misread the prefix as its own typo. To prevent that, this plugin also registers tool.execute.after and annotates the tool result with a one-line note:

[hypa Rewritten] git log --oneline -10 => hypa git log --oneline -10

The note is prepended to both output.title and output.output, and the full record is written to output.metadata.hypaRewrite. Non-rewritten outcomes (passthrough / skipped / error) leave the tool result untouched.

Configuration

Set options in opencode.json as the second element of the plugin tuple, or override any field with an environment variable (env wins over options).

{
"plugin": [
"opencode-hypa",
{
"binary": "hypa",
"rewriteTimeoutMs": 5000,
"askNonInteractive": "deny",
"enabled": true
}
]
}
Option (PluginOptions)Env varDefaultDescription
binaryOPENCODE_HYPA_BINhypa (PATH / bundled)Hypa executable or absolute path
rewriteTimeoutMsOPENCODE_HYPA_REWRITE_TIMEOUT_MS5000Timeout for hypa rewrite --json
askNonInteractiveOPENCODE_HYPA_ASK_NON_INTERACTIVEdenyallow or deny when Hypa returns Ask
enabledOPENCODE_HYPA_ENABLEDtrueSet false / 0 to disable the plugin

Diagnostics

In the OpenCode TUI, run /hypa to open a modal with:

  • whether the plugin is enabled
  • resolved Hypa binary path and whether it exists
  • installed Hypa version (hypa --version, cached at TUI load)
  • effective config for each field with source tag (env, options, or default)
  • the last rewrite (input, command, outcome, timestamp) or none

Re-open /hypa to refresh the snapshot after config or rewrite changes.

Why not MCP?

hypa serve works as an MCP server, but the model has to choose those tools. This plugin rewrites every bash call automatically — the integration that actually saves context.

Development

npm install
npm test
npm run build

CI keeps a fast lockfile job on Node 18 and 22. A separate opencode-latest job (push/PR and weekly) installs @opencode-ai/plugin@latest from npm — the same version OpenCode publishes for the CLI (opencode-ai / GitHub Releases) — and re-runs typecheck, tests, the rewrite/hook smoke, and a real OpenCode bash-dispatch smoke (POST /session/:id/shell, with a dummy-model fallback because /shell does not invoke tool.execute.before).

Publishing

Releases publish to npm via Trusted Publishers (GitHub OIDC). No long-lived npm token is stored in the repo.

  1. On npm: opencode-hypa → Settings → Trusted Publisher
  2. Add GitHub with:
FieldValue
Organization or userkipyin
Repositoryopencode-hypa
Workflow filenamepublish.yml
Environment(leave empty)
  1. Publish a GitHub Release (vX.Y.Z), or run the publish workflow manually.

Related

License

MIT

About

OpenCode plugin that rewrites bash tool calls through Hypa for local output compression

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages