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 / hooks / tools / may-have-written.ts
23 lines · 806 BRaw
1import type { ResultOf } from 'claude-code'
2
3/**
4 * Whether a shell tool's outcome may have changed the working tree, as the
5 * built-in gates its refresh: a throw or an answer, unless the engine says
6 * the tool held the call read-only (`ls`, `git status`); never a deny.
7 *
8 * `isReadOnly` is read through a type that may lack it, ahead of the
9 * declarations that name it; absent, the call counts as a write.
10 *
11 * @param result what `next` resolved to, or undefined when it threw
12 * @returns true when a refresh is due
13 */
14export function mayHaveWritten(
15 result: ResultOf['tool.call'] | undefined,
16): boolean {
17 const settled: { deny?: string; isReadOnly?: boolean } | undefined = result
18
19 return (
20 settled === undefined ||
21 (settled.deny === undefined && settled.isReadOnly !== true)
22 )
23}