Skip to content

Add a /wt-diff pane to the Claude Code plugin - #4638

Merged
max-sixty merged 9 commits into
mainfrom
cc-diff-mod
Oct 31, 2026
Merged

max-sixty merged 9 commits into
mainfrom
cc-diff-mod

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

The Claude Code plugin gains /wt-diff, a pane beside the conversation that lists the worktrees the session has worked in, with the selected one's wt step diff below it, drawn file by file with Claude Code's own diff renderer. It is a hooks module, Claude Code's early-access function hooks API, and the plugin's only one.

A worktree joins the list when the session starts or moves into it, or when the session or a subagent edits a file there or runs a Bash command there that isn't read-only. Until /wt-diff first runs, the hooks only note those directories in session state: no git or wt process runs and nothing is drawn, which a test asserts. While the pane is open, wt list --format=json (once per repository) supplies the rows and wt step diff the selected worktree's files; it refreshes on open, on selection, after a burst of non-read-only tool calls goes quiet, and at the end of each turn.

Keys: 1–9 select a worktree, j/k move between files (ctrl+↓/ctrl+↑ from the prompt, borrowing the chords of Claude Code's own diff panel), r refreshes, and the arrows and page keys scroll. Running /wt-diff again, or ctrl+x tab, gives the pane the keyboard back. A plugin can't ship keybindings, so the pane has no dedicated chord.

Compatibility: Claude Code releases without hooks modules drop the modules key and still load the command hooks (checked on 2.1.100), so the 🤖/💬 markers keep working there. Codex and Gemini never read the module.

Where to look:

  • plugins/worktrunk/hooks/register.tsx — the module, with its spec at the top.
  • plugins/worktrunk/hooks/patch.ts — splits the patch into files, with rename and mode notes.
  • plugins/worktrunk/types/index.d.ts — the state contract; tests/diff.test.tsx — the suite.
  • hooks/hooks.json gains modules, plugin.json gains types, and the agent integration docs gain a /wt-diff section (skills mirrors regenerated).

One drawing holds 100,000 characters, so the selected file always draws (cut at whole hunks, or to the start of its first hunk, if it must be) and the others draw within the remaining budget; a patch over the 4 MiB that $.process.run captures drops its last file and says so.

Checked locally: claude plugin validate plugins/worktrunk, claude plugin test plugins/worktrunk (8 pass), test_docs_are_in_sync and test_plugin_layout_is_consolidated, and live sessions on Claude Code 2.1.314.

This was written by Claude Code on behalf of max-sixty

dev/claude-mod/wt-diff is a Claude Code plugin of function hooks (a
"mod"). `/wt-diff [branch]` opens a pane that lists the worktrees the
session has worked in: where it started, where its shell's directory has
been, and where Edit, Write or a Bash command changed files. Each row
carries its `wt list --format=json` counts, and the selected worktree's
`wt step diff` draws with Claude Code's own diff renderer.

Try it with `claude --plugin-dir dev/claude-mod/wt-diff`. The function
hooks API is early access and changes between Claude Code releases, so
the prototype sits under dev/ rather than in the shipped plugin.
The mod read `$.session.cwd()` in every hook, but in a subagent's hook it
answers the subagent's directory, so a subagent's call could move the
pane's `@` off the session's own worktree. The session's directory is now
read only in hooks of the main loop and on a press, and a subagent's Bash
call counts the worktree it ran in. Read-only tool calls no longer track
or refresh anything.

A file's heading now shows its place in the list, a rename's source path
and a mode change. Paths reach the parser unquoted (`core.quotePath=false`
through git's environment form of `-c`), and a name with a space loses
the tab git appends to it. The selected file always draws, cut to the
whole hunks that fit one drawing; a patch past the 4 MiB a run captures
drops its last, partial file and says so. Rows survive the removal of
the first worktree tracked in a repository.
…from the prompt

The next and previous buttons take j and k, as Claude Code's diff dialog
does, while the pane holds the keys. Each also names the engine's
app:diffFileListDown/Up action, so the person's chord for the diff panel's
file list (ctrl+down and ctrl+up by default) moves between files from the
prompt without focusing the pane.
… top

The file cursor started on the first file while the pane showed its top,
so the first j skipped to the second file. It now starts above the files:
j from the top reaches the first, and k from the first goes back up. The
diff also no longer waits on wt list before it draws.
…ocus

ctrl+x tab focuses the band above the prompt when a plugin draws one
(Leaf's does), so it can't be relied on to reach the pane. A bare
/wt-diff on an open pane now gives it the keyboard and keeps the worktree
and file it shows. The hint row says 'ctrl+x tab: focus' while the pane
lacks the keys, since its hotkeys work only once it has them.
The prototype under dev/claude-mod moves into plugins/worktrunk as the
plugin's hooks module: hooks/register.tsx, named under `modules` in
hooks/hooks.json beside the existing command hooks, with its state
contract in types/ and its `claude plugin test` suite in tests/.

A session that never runs /wt-diff now only notes directories: the
session's own, and those its edits and commands touched. Resolving them
to worktrees with `git rev-parse` waits until the pane opens, so until
then the plugin spawns no process and draws nothing; a test holds that.
Claude Code releases without hooks modules drop the `modules` key and
keep loading `hooks` (checked on 2.1.100), so activity markers keep
working there.

The agent integration page documents the pane and its keys.
A directory noted before the pane opens may be gone by the time it does;
locate() now stats upward to the nearest directory that exists and asks
git once there, instead of walking four levels by git's error text, so a
worktree whose edited subtree was deleted stays listed. Noting a
directory that is already the latest one writes nothing, so a run of
tool calls in one place costs a state read. The docs say which commands
count (those that aren't read-only) and that the pane's tracking, not
the whole plugin, runs no git or wt before the pane opens.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With [list] json-schema = 1, wt list --format=json returns a bare array, while readRows and worktreeOf require the schema 2 envelope. The pane then loses branch/status rows and /wt-diff <branch> reports no worktree. Pin schema 2 for both calls (suggestions below).

Comment thread plugins/worktrunk/hooks/register.tsx Resolved
Comment thread plugins/worktrunk/hooks/register.tsx Resolved
Comment thread plugins/worktrunk/hooks/register.tsx Resolved
Comment thread plugins/worktrunk/hooks/patch.ts Resolved
…quote names

- `[list] json-schema = 1` makes `wt list --format=json` a bare array, so
  the pane lost its rows and `/wt-diff <branch>` found no worktree. Both
  calls now pass `--config-set list.json-schema=2`.
- A selected file whose first hunk passed the drawing budget was drawn
  whole, past the 100,000 characters a drawing holds. It now draws the
  hunk's start under a header recounted to the kept lines, cutting a first
  line longer than the budget.
- Git still C-quotes a name holding a tab, newline, quote or backslash
  under core.quotePath=false, so such a file took the whole header as its
  path. Header names are unquoted before use.
@max-sixty
max-sixty merged commit 2c04fb3 into main Oct 31, 2026
46 checks passed
@max-sixty
max-sixty deleted the cc-diff-mod branch October 31, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants