spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

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