|
| 1 | +# diff |
| 2 | + |
| 3 | +The diff pane as a plugin: `/diff` opens the session's uncommitted changes |
| 4 | +beside the transcript, one row per changed file and the selected file's |
| 5 | +hunks beneath, and closes it again. The pane refreshes as Claude edits, |
| 6 | +runs shell commands and finishes turns, and while it is open it polls the |
| 7 | +repository's HEAD so a commit or checkout made elsewhere shows too. The |
| 8 | +first successful edit of a session opens the pane by itself where the |
| 9 | +terminal is wide enough (144 columns when the person never chose, 110 when |
| 10 | +they kept it open before; a person who closed it is left alone). A file's |
| 11 | +ask button arms that file: its hunks ride the next prompt as context, once. |
| 12 | + |
| 13 | +The pane compares the working tree against HEAD, split at the session's |
| 14 | +start (the default), against HEAD plainly, or against the merge-base with |
| 15 | +the default branch; the choice is kept per repository in the plugin's |
| 16 | +store. A second picker shows one earlier turn's edits instead of the |
| 17 | +working tree, read from the session's messages. Files that changed before |
| 18 | +the session started, and noise (lockfiles, generated and test files), are |
| 19 | +listed apart and folded until asked for. Outside a git repository `/diff` |
| 20 | +says so and does nothing else. |
| 21 | + |
| 22 | +`hooks/register.ts` is the module; everything under `hooks/` is its parts. |
| 23 | + |
| 24 | +## What it hooks |
| 25 | + |
| 26 | +| event | what the hook does | |
| 27 | +| --- | --- | |
| 28 | +| `session.start` | Binds the engine once, registers `/diff` (a session where another `/diff` is listed leaves the plugin idle), and pins the repository. | |
| 29 | +| `ui.render` of `PromptHint` | Reads the terminal's width, which decides whether the first edit opens the pane. | |
| 30 | +| `ui.render` of `Pane` | Draws the pane: header, the file list, the toggles, the base and source pickers, and the selected file's hunks. | |
| 31 | +| `command.run` of `diff` | Opens or closes the pane and remembers the choice. | |
| 32 | +| `command.run` of `clear`, `resume` | Closes the pane and forgets the session's state. | |
| 33 | +| `tool.call` of `Edit`, `Write`, `NotebookEdit` | After the edit, refreshes an open pane; the session's first successful edit opens it. | |
| 34 | +| `tool.call` of `Bash`, `PowerShell` | After the command, refreshes an open pane. | |
| 35 | +| `turn.complete` | Refreshes an open pane. | |
| 36 | +| `prompt.submit` | Adds the armed file's hunks to the prompt's context and disarms. | |
| 37 | + |
| 38 | +## What it calls on `$` |
| 39 | + |
| 40 | +`clock.after`, `clock.every`, `clock.now`, `clock.sleep`, `command.register`, |
| 41 | +`fs.list`, `fs.read`, `fs.stat`, `process.run` (git, read-only), `session.messages`, |
| 42 | +`store.get`, `store.set`, `telemetry.log`, `telemetry.mark`, `ui.close`, |
| 43 | +`ui.invalidate`, `ui.log`, `ui.open`, `ui.resolve`, `ui.status`. |
| 44 | + |
| 45 | +`$.telemetry` is the telemetry plugin's noun; where it is absent the rows |
| 46 | +are dropped and nothing else changes. |
| 47 | + |
| 48 | +## Try it |
| 49 | + |
| 50 | +```sh |
| 51 | +claude --plugin-dir /path/to/diff |
| 52 | +``` |
| 53 | + |
| 54 | +then `/diff` inside a git repository with a modified file. |
0 commit comments