Repository navigation
Add a /wt-diff pane to the Claude Code plugin - #4638
Merged
Merged
Conversation
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
left a comment
Collaborator
There was a problem hiding this comment.
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).
…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.
worktrunk-bot
approved these changes
Oct 31, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'swt step diffbelow 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-difffirst runs, the hooks only note those directories in session state: nogitorwtprocess runs and nothing is drawn, which a test asserts. While the pane is open,wt list --format=json(once per repository) supplies the rows andwt step diffthe 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–9select a worktree,j/kmove between files (ctrl+↓/ctrl+↑from the prompt, borrowing the chords of Claude Code's own diff panel),rrefreshes, and the arrows and page keys scroll. Running/wt-diffagain, orctrl+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
moduleskey 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.jsongainsmodules,plugin.jsongainstypes, and the agent integration docs gain a/wt-diffsection (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.runcaptures 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_syncandtest_plugin_layout_is_consolidated, and live sessions on Claude Code 2.1.314.