Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 4.16 KB

plugin.md

File metadata and controls

46 lines (27 loc) · 4.16 KB

The Claude Code plugin

The plugin in plugin/ puts the backread command in front of the model after a compaction. It has three parts:

  • The command. plugin/bin/backread is on the Bash tool's PATH while the plugin is enabled. It runs the copy of the backread package bundled with the plugin, so nothing else needs installing.
  • A skill, skills/backread/SKILL.md: when to search, the two commands, their caps and exit statuses.
  • A hook that runs after each compaction and adds one line to the context.

Install

From Claude Code:

/plugin marketplace add afterimaginary/backread
/plugin install backread@backread

The repository root holds the marketplace (.claude-plugin/marketplace.json), which lists the one plugin in plugin/. To try a checkout without installing, start Claude Code with claude --plugin-dir plugin.

It needs Python 3.13 or later as python3, python3.13 or newer on the PATH. Without one it runs through uv, which fetches a Python the first time. The launcher is a POSIX shell script, so it runs on macOS and Linux. The hook's timeout is 120 seconds, long enough for uv to fetch a Python on the first compaction.

claude.ai and Cowork don't install plugins with a top-level bin/ folder, so this plugin is for Claude Code only.

The hook

Claude Code fires SessionStart with source set to compact after every compaction, manual or automatic, and adds what a SessionStart hook prints to the context after the summary. The plugin's hook uses the compact matcher. (PostCompact also fires then, but it can't add anything to the context.)

The hook prints one line, under 300 characters:

`backread search <words> --transcript ~/.claude/projects/-work-scratch/00000000-0000-4000-8000-000000000001.jsonl` searches the original conversation that the summary was written from, by keywords, and returns up to 3 short excerpts with their handles.

What follows the command is DESCRIPTION in src/backread/hook.py, the only place it is written. REPORT.md names search as the arm to ship: it tells the agent the search exists without saying the summary may be wrong. So the line is that arm's neutral tool sentence from PLAN.md, with three changes for Claude Code: it follows the command instead of a tool name, it drops <context> (Claude Code's summary has no such tag), and it ends at "handles", since backread marks excerpts with handles and doesn't limit searches per question. A test applies those changes to the frozen sentence and checks the result matches. Like the arm's tool description, it states what the command does and gives no instruction.

The command names this session's transcript, from the hook's transcript_path input, so backread reads this session even when another one in the same folder wrote last. When the whole path would make the line too long, the project folder is written as * and the path is quoted; backread expands the * to the one folder holding that session. When that is too long too, the line leaves the transcript out and backread falls back to the newest transcript for the folder.

In a real session

Three compacted sessions with the plugin loaded, on Claude Code 2.1.327 and with the hook's line above: in two, the agent searched once with backread and found the details the summary had dropped; in the third, where the user had asked the compaction to drop them, it offered to search and asked first.

How the bundled copy works

plugin/lib/backread is a symlink to src/backread. When Claude Code installs the plugin it copies plugin/ into its plugin cache and replaces a symlink to elsewhere in the marketplace with the files it points at, so the installed plugin carries the package. plugin/scripts/run finds the Python and runs a module of that copy with python -I, so modules in the working directory, PYTHONPATH and user site-packages can't load in its place.

The manifest has no version, so Claude Code versions the plugin by commit and every pushed change reaches users on update.