O Caminho das Pedras

The plugin that rewrote citations: how it worked on OpenCode v1 and why v2 switched it off

2026-11-20

A reply that cites a file is only useful if the reader can open the file. In a desktop client that depends on the path being in a form the renderer turns into a clickable target. When the form slips, the citation becomes dead text — and the reader goes back to hunting for the folder by hand.

For much of 2026, a plugin solved this on OpenCode v1: it intercepted every assistant text part before it was saved and normalized the paths. In the move to v2 that hook disappeared. The plugin no longer loads, the automatic fix is gone, and what remains is the rule in the instruction file. This article describes the full mechanism as it worked, what v2 offers instead, and where the request is tracked.

What breaks, and how the failure looks

The symptom is silent: the reply looks normal, the path is written, but clicking opens nothing. The table below is the measurement of each form, taken by clicking it in the app:

Form in the reply What happens
a relative path that exists, in backticks opens in the side panel
an absolute C:\… path, in backticks opens Explorer with the file selected
a path with :line opens and ignores the line — :line does not break it
a markdown link to a relative path opens, but the box shows the label, not the file
a markdown link with :line in the target breaks: Could not find … on disk
~ in backticks answers This is not a local file path
file:/// in backticks becomes a dead box, not clickable
a path that does not exist is not a target at all

The rule that follows is short: inside the working folder, relative; outside, absolute; ~ and file:/// never. The problem is that a model writes the reply, and models get the form wrong. That is what the plugin was for.

The central trap: three layers with similar names

Anyone trying to fix this tends to conflate three things that look the same:

Layer What it controls Where it lives
renderer what becomes a clickable target app behavior; not configurable
engine hook what a plugin can intercept OpenCode plugin API
instruction what the model decides to write instruction file loaded into the session

The v1 plugin acted on the middle layer. On v2 that layer has no interception point — and the other two do not replace it: the instruction reduces the error but does not fix it; the renderer only obeys what it receives.

How the mechanism worked on v1

A v1 plugin is a function that receives the context and returns an object of hooks. The migration guide describes the shape:

// v1
import type { Plugin } from "@opencode-ai/plugin"

export const Example: Plugin = async ({ directory }) => ({
  "experimental.text.complete": async (input, output) => {
    // output.text is the part's text, before it is saved
  },
})

The experimental.text.complete hook fires per text part, when the assistant finishes producing it, and hands over the text before persistence — which is what issue anomalyco/opencode#53019 records and what the migration guide confirms when it lists the hook among the v1 experimental hooks with no direct v2 equivalent.

The implementation was small and did four things, in this order:

  1. Split the text by fenced blocks and ignored their contents. Code is not a citation: rewriting a path inside a fence would corrupt the example.

  2. Collected the backticked spans that looked like paths — with a folder separator or an extension — and classified each against the working folder.

  3. Rewrote only what the app would not open: ~ and file:/// in backticks became an absolute path; a markdown link to a clean relative path became a bare path, because the bare path is what shows the target. Everything else passed through untouched, including :line, which the app accepts and ignores.

  4. Logged every rewrite, so the change was not invisible.

The detail that matters is the timing: before the save. The persisted text feeds the UI, the following turns and any reload of the conversation. A display-only fix would leave history in the wrong form — and the problem would return on the next load.

What v2 changed

v2 changed the plugin shape: instead of a function returning hooks, the file exports a definition with id and setup(ctx), and each hook is registered on the domain that owns it (documentation). The available hooks cover prompt, context, compaction, generate, title, model.request, http.request, http.response, experimental WebSocket, retry, tools, shell and permissions.

None of them runs between the model reply and persistence. The migration guide is explicit: there is no v2 hook corresponding to every v1 experimental hook, and it names experimental.text.complete among those that must be reconsidered.

The failure mode also changed, for the worse: a plugin written in the v1 shape does not load, and the engine logs only a warning —

failed to load plugin ... Plugin must export a default definition
  with an id and an effect or setup function

— with no visible signal in the conversation. The integration simply stops, and whoever depends on it learns from the symptom, not from the error.

What took its place

With the hook gone, the citation form depends only on the instruction: the file loaded into the session says which path to use in each situation. It works — it is what keeps citations correct most of the time — but it is discipline, not mechanism.

To avoid running without a net, what remains is an audit after the reply: a local tool reads the last message (or a file, or stdin), resolves each path against the working folder and lists what would break. It writes nothing. The limit is obvious: the error only shows up once the reply exists, and nothing stops it from reaching the reader.

The live issue

The request is anomalyco/opencode#53019, open since 3 October 2026. It describes the problem precisely — v2's SessionHooks, the TUI's only seam (registerCodeBlockRenderer), the http.response/WebSocket-frames workaround — and proposes two ways out:

  1. a display hook that runs before the text is rendered, without touching what is stored or what goes back to the model;

  2. a text.complete equivalent that runs when the part completes, with mutable text, before persistence.

The case in this article is the second: because the client resolves paths from the stored text, a display-only fix does not help — on reload, history would come back in the old form. That increment was commented on the issue itself, instead of opening a duplicate.

Until the hook exists, anyone who depends on normalizing output has three routes: keep the rule in the instruction, audit afterwards, or intercept the provider's HTTP stream — the last one works, but requires a parser per protocol and reassembling deltas that may split the path.

Practical consequence

If you maintain a plugin that rewrites assistant text, it does not run on v2 — and it does not warn. The first step is to move the rule into the instruction and accept that the correction is no longer automatic. If the behavior is essential, the place to say so is #53019, with your use case: the thread is what shows maintainers how many clients depend on the persisted text, and not only on the screen.

The old hook's code is not lost: it remains the specification of what v2 needs to deliver.

Sources

Bruno Torres

Bruno Torres

Solo digital entrepreneur. I build digital businesses from scratch with AI agents — and document the path, including what didn't work.

Comments

Share: X · Facebook · LinkedIn · WhatsApp · Telegram · E-mail ·