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 / edited-path-of.ts
21 lines · 640 BRaw
1import type { ToolCallInput } from 'claude-code'
2
3/**
4 * The file an editing tool was called on, as its input names it:
5 * `file_path` for Edit and Write, `notebook_path` for NotebookEdit.
6 *
7 * @param e the `tool.call` event
8 * @returns the path as given, or null when the input names none
9 */
10export function editedPathOf(e: ToolCallInput): string | null {
11 const isFileEdit = e.tool === 'Edit' || e.tool === 'Write'
12 const isNotebookEdit = e.tool === 'NotebookEdit'
13
14 const path = isFileEdit
15 ? e.file_path
16 : isNotebookEdit
17 ? e.notebook_path
18 : null
19
20 return typeof path === 'string' && path !== '' ? path : null
21}