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.
TypeScript
diff: a shell command the tool held read-only fetches nothing, as the built-in panel's touch is gated (#95423)
Alice T'Poteat6c6915eb63e7
diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex 289f5f11..f7929d93 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -927,9 +927,7 @@ export function register(on: On) {result.deny === undefined &&result.isError !== true- const hasLanded = isEdit- ? hasEdited- : result === undefined || result.deny === undefined+ const hasLanded = isEdit ? hasEdited : Tools.mayHaveWritten(result)if (hasLanded) {landed += 1diff --git a/mods/diff/hooks/tools/index.ts b/mods/diff/hooks/tools/index.tsindex 3083c37a..aaff6452 100644--- a/mods/diff/hooks/tools/index.ts+++ b/mods/diff/hooks/tools/index.ts@@ -1,4 +1,5 @@export * from './editing-tools.js'+export * from './may-have-written.js'export * from './shell-tools.js'export * from './todo-tool.js'diff --git a/mods/diff/hooks/tools/may-have-written.ts b/mods/diff/hooks/tools/may-have-written.tsnew file mode 100644index 00000000..18cdf1bf--- /dev/null+++ b/mods/diff/hooks/tools/may-have-written.ts@@ -0,0 +1,23 @@+import type { ResultOf } from 'claude-code'++/**+ * Whether a shell tool's outcome may have changed the working tree, as the+ * built-in gates its refresh: a throw or an answer, unless the engine says+ * the tool held the call read-only (`ls`, `git status`); never a deny.+ *+ * `isReadOnly` is read through a type that may lack it, ahead of the+ * declarations that name it; absent, the call counts as a write.+ *+ * @param result what `next` resolved to, or undefined when it threw+ * @returns true when a refresh is due+ */+export function mayHaveWritten(+ result: ResultOf['tool.call'] | undefined,+): boolean {+ const settled: { deny?: string; isReadOnly?: boolean } | undefined = result++ return (+ settled === undefined ||+ (settled.deny === undefined && settled.isReadOnly !== true)+ )+}diff --git a/mods/diff/tests/fixtures/index.ts b/mods/diff/tests/fixtures/index.tsindex af8bba2e..f6774b1a 100644--- a/mods/diff/tests/fixtures/index.ts+++ b/mods/diff/tests/fixtures/index.ts@@ -40,6 +40,7 @@ export * from './pane.js'export * from './pane-view'export * from './parse-file-diff'export * from './poll-word.js'+export * from './read-only-answer.js'export * from './renamed.js'export * from './repository.js'export * from './repository-of'diff --git a/mods/diff/tests/fixtures/read-only-answer.ts b/mods/diff/tests/fixtures/read-only-answer.tsnew file mode 100644index 00000000..33e1dd71--- /dev/null+++ b/mods/diff/tests/fixtures/read-only-answer.ts@@ -0,0 +1,13 @@+import type { ResultOf } from 'claude-code'++/**+ * A shell tool's answer as the engine gives it for a command the tool holds+ * read-only (`ls`, `git status`): the result, and `isReadOnly` beside it.+ *+ * Built through Object.assign, since the declarations may not name the+ * field yet; the plugin reads it through a type that may lack it too.+ */+export const READ_ONLY_ANSWER: ResultOf['tool.call'] = Object.assign(+ { result: 'listed' },+ { isReadOnly: true as const },+)diff --git a/mods/diff/tests/register.test.ts b/mods/diff/tests/register.test.tsindex 6d4a7dc0..98fbe645 100644--- a/mods/diff/tests/register.test.ts+++ b/mods/diff/tests/register.test.ts@@ -121,6 +121,41 @@ describe('register', () => {)})+ test('a shell command the tool held read-only fetches nothing', async ($, on) => {+ const world = Fixtures.inRepository(on)++ const fetchesSince = (read: number) =>+ world.runs.slice(read).filter(run => run.argv.includes('--numstat'))+ .length++ on('tool.call', ($, e) =>+ e.tool === 'Bash' && e.command === 'ls'+ ? Fixtures.READ_ONLY_ANSWER+ : { result: 'done' },+ )++ await $.session.start(Fixtures.SESSION)+ await $.command.run(Fixtures.DIFF)+ await world.clock.advance(Fixtures.SETTLE_MS)++ const opened = world.runs.length++ await $.tool.call({ tool: 'Bash', command: 'ls' })+ await world.clock.advance(Fixtures.SETTLE_MS)++ expect(+ fetchesSince(opened),+ "read-only, the pane open: nothing, as the built-in's touch is gated",+ ).toBe(0)++ const listed = world.runs.length++ await $.tool.call({ tool: 'Bash', command: 'make' })+ await world.clock.advance(Fixtures.SETTLE_MS)++ expect(fetchesSince(listed), 'a command that may write: one fetch').toBe(1)+ })+test('/diff whose probe never answers probes once more', async ($, on) => {const probes: (readonly string[])[] = []const clock = Fixtures.startsSession(on)