Skip to content

Latest commit

 

History

History

re-ghidra-mcp-opencode

Folders and files

README.md

re-ghidra-mcp-opencode

An OpenCode V2 plugin that attaches a persistent headless Ghidra JVM to your session and exposes it as 19 reverse-engineering tools over MCP — 14 that read and navigate a program, and 5 that write durably back into the Ghidra project — plus two session hooks: one that preserves RE state across compaction, and one that points the model at the driver skill when Ghidra tools are in play.

It is the OpenCode member of a family: claude-code/plugins/re-ghidra-mcp-cc does this for Claude Code and qwen/plugins/re-ghidra-mcp-qwen for Qwen Code. The reverse-engineering engine lives in shared/ghidra-mcp behind the existing re-ghidra-cc-mcp binary; only the host integration (this plugin.ts) is OpenCode-specific.

Tested with OpenCode v2.0.20 and @opencode/plugin 2.0.32. The V2 plugin API is explicitly beta and will churn — re-test on bump.

Context footprint

Installing this plugin adds ≥ 21,297 bytes to every request, for the whole session. A further ≥ 37,147 bytes load only when one of its skills or agents is actually invoked. Its plugin.ts setup module adds ≥ 8,580 bytes, loaded in-process with the host on every request and counted separately below so the TypeScript tier stays comparable across releases.

Tier Bytes When you pay it
Resident ≥ 21,297 Every request, for the whole session
Invocation ≥ 37,147 Only when that skill or agent runs
Setup ≥ 8,580 Every request — plugin.ts loads in-process with the host

Bytes, not tokens. This is the exact serialised size of what the host loads, measured by probing the plugin's own MCP server and reading its skill and agent frontmatter. It is not a token count and does not convert to one at a fixed rate — treat it as a figure you can compare between plugins, not as a context budget.

≥, because hook output is excluded. Measuring it would mean executing the plugin's hooks against a synthetic event, which this tool will not do. A plugin whose hooks emit a large preamble costs more than the figure shown.

Generated by tools/plugin-footprint; regenerate with just footprint-regen.

How it works

The expensive thing about Ghidra is starting it. re-ghidra-cc-mcp serve launches one headless Ghidra JVM and holds it for the life of the MCP session, so a tool call hits an already-warm process instead of paying Ghidra startup cost per call. This plugin reuses that same binary as a type: "local" MCP server — the same 19 tools, the same environment passthrough.

The plugin itself owns no RE logic. Its setup registers exactly two session hooks:

  • compaction pushes a reminder of the durable RE state (attached program and analysis freshness, pending renames/comments/datatype writes, current investigation target) into the summarization request, so the continuation summary preserves what a plain transcript summary would drop.
  • context pushes a pointer at the ghidra-re-driver skill only when a Ghidra tool is among the request's tools, so idle sessions pay nothing.

Both handlers are stateless — no ctx.storage use.

The SessionStart hook itself is Claude Code-shaped and stays there — but its diagnosis is ported: plugin.ts runs the same preflight (install dir, Java, project values) once per session and, only when something is wrong, appends a finding to the first session context. Silent when healthy, never blocks.

The 19 tools

Read / navigate (14): list_project_programs, attach_program, inspect_function, find_functions, list_symbols, list_strings, list_data_items, list_segments, resolve_symbol, describe_address, get_xrefs, get_disassembly, read_bytes, get_datatype.

Write (5): rename, comment, set_datatype, set_prototype, set_local.

The writes are durable. On success they are saved into your Ghidra project. There is no undo stack and no cross-session rollback — reverting means restoring a backup. Copy a project you care about before letting an agent write to it.

Prerequisites

You supply these; nothing here bundles them.

  • Ghidra 12.1.2, with GHIDRA_INSTALL_DIR set to its install root (the directory containing support/, Ghidra/ and ghidraRun).
  • JDK 21 or newer on PATH (Ghidra 12.1.2 declares application.java.min=21).
  • A Ghidra project already created, imported, fully analyzed, and closed in the GUI.

The server reads the same environment as its Claude Code sibling:

Setting Environment variable
Ghidra install root GHIDRA_INSTALL_DIR
Directory holding the .gpr/.rep GHIDRA_MCP_PROJECT_DIR
Ghidra project name GHIDRA_MCP_PROJECT_NAME
Bare program filename to attach at boot GHIDRA_MCP_BOOTSTRAP_PROGRAM
VFS path, if the program is in a subfolder GHIDRA_MCP_BOOTSTRAP_PROGRAM_PATH
JVM -Xmx GHIDRA_MCP_MAX_HEAP
Data directory (logs, worker scripts) GHIDRA_MCP_HOME

Settings layer (.opencode/re-ghidra-mcp-opencode.local.md)

Why a settings file matters more for this plugin than for most: one server is one Ghidra project. The project directory, project name and bootstrap program are per-workspace by nature, so without a settings layer every repo would duplicate the plugin's registration in an opencode.jsonc just to carry three strings.

Copy examples/re-ghidra-mcp-opencode.local.md to .opencode/re-ghidra-mcp-opencode.local.md in the project root. Precedence is CLI flag > GHIDRA_* environment > this file (decided by the shared config resolver). The MCP server picks the file with RE_GHIDRA_HOST=opencode, which opencode.jsonc sets — an OpenCode session never reads .claude/re-ghidra-mcp-cc.local.md.

One server = one Ghidra project. Two servers on the same project — or one server and an open GUI — collide on Ghidra's project.lock. Different workspaces must target different projects.

Run the doctor skill when anything here is wrong; it walks these checks in order and names the broken one.

Installing

The plugin is a file copy — no registry, no build of the TypeScript itself:

Project-local (one project):

cp opencode/plugins/re-ghidra-mcp-opencode/plugin.ts .opencode/plugins/re-ghidra-mcp-opencode.ts
cp -r opencode/plugins/re-ghidra-mcp-opencode/skills/. .opencode/skills/
cp -r opencode/plugins/re-ghidra-mcp-opencode/agents/. .opencode/agents/
# merge opencode/plugins/re-ghidra-mcp-opencode/opencode.jsonc into .opencode/opencode.jsonc

Global (every project): the same copies under ~/.config/opencode/ — plugins/re-ghidra-mcp-opencode.ts, skills/…, agents/…, merged into opencode.jsonc.

A copied plugin.ts auto-loads — no plugins entry is needed for the standard path. Skills and agents auto-discover once copied.

plugin.ts imports @opencode/plugin as a value, so the install target needs that package resolvable. From the project root (or ~/.config/opencode/ for a global install):

bun add @opencode/plugin@2.0.32

Use the version under "Tested with" at the top of this README if it names a newer one. OpenCode also runs bun install at startup, but install the dependency now rather than discovering it missing on next launch.

The MCP server needs its binary. re-ghidra-cc-mcp is a [[bin]] of the existing re-ghidra-mcp-cc crate, staged by:

just build-re-ghidra-mcp-opencode

That builds re-ghidra-cc-mcp into opencode/plugins/re-ghidra-mcp-opencode/bin/ (which is gitignored); release builds for all platforms come from CI via cargo-dist. Alternatively, unpack re-ghidra-mcp-cc-plugin.zip from the latest release, which carries the binaries for every supported platform. Either way, stage the built (or release-unpacked) binary at .opencode/bin/re-ghidra-cc-mcp next to the snippet's merge target — and write the merged command as an absolute path (<DEST>/bin/re-ghidra-cc-mcp, .exe on Windows). A relative ./bin/... does NOT resolve against the config dir: the host spawns it against the session directory and fails with NotFound: ChildProcess.spawn.

Skills and agents

Kind File What it does here
Skill (auto) skills/ghidra-re-driver/SKILL.md How to drive the 19 tools, and when not to trust a decompile. GENERATED — see below
Skill (invoked) skills/doctor/SKILL.md Interactive diagnosis of a broken Ghidra setup. OpenCode-ported variant of the Claude Code doctor skill (host paths, shell-neutral commands) — deliberately NOT byte-identical
Agent agents/re-analyst.md Autonomous naming/annotation sweep. Port of the Claude Code re-analyst agent; body verbatim, frontmatter unchanged (the source carries no mode, permission or variant to convert, and no prompt: key is introduced)

skills/ghidra-re-driver/SKILL.md is generated

The canonical driver skill lives at shared/ghidra-mcp/skill/SKILL.md and is compiled into the binary with include_str!. This copy is regenerated from the binary that embeds it:

just emit-ghidra-skill

Do not edit the copy — claude-code/plugins/re-ghidra-mcp-cc/tests/skill_emit.rs compares it to the binary's output byte for byte and will fail.

Testing

bun install && bun test tests/

The suite drives both session hooks against a fake ctx (registration shape, reminder injection, driver-pointer gating) plus the pure needsDriverPointer helper, so it runs identically on a machine that has never had Ghidra installed. The generated skill copy is pinned on the Rust side:

cargo nextest run -p re-ghidra-mcp-cc --test skill_emit