claudetool: accept relative paths in patch tool
diff --git a/claudetool/patch.go b/claudetool/patch.go
index b40396a..b2b5db6 100644
--- a/claudetool/patch.go
+++ b/claudetool/patch.go
@@ -28,6 +28,8 @@
 // PatchTool specifies an llm.Tool for patching files.
 type PatchTool struct {
 	Callback PatchCallback // may be nil
+	// Pwd is the working directory for resolving relative paths
+	Pwd string
 }
 
 // Tool returns an llm.Tool based on p.
@@ -38,7 +40,7 @@
 		InputSchema: llm.MustSchema(PatchInputSchema),
 		Run: func(ctx context.Context, m json.RawMessage) llm.ToolOut {
 			var input PatchInput
-			output := patchRun(ctx, m, &input)
+			output := p.patchRun(ctx, m, &input)
 			if p.Callback != nil {
 				return p.Callback(input, output)
 			}
@@ -71,7 +73,7 @@
   "properties": {
     "path": {
       "type": "string",
-      "description": "Absolute path to the file to patch"
+      "description": "Path to the file to patch"
     },
     "patches": {
       "type": "array",
@@ -118,15 +120,19 @@
 
 // patchRun implements the guts of the patch tool.
 // It populates input from m.
-func patchRun(ctx context.Context, m json.RawMessage, input *PatchInput) llm.ToolOut {
+func (p *PatchTool) patchRun(ctx context.Context, m json.RawMessage, input *PatchInput) llm.ToolOut {
 	if err := json.Unmarshal(m, &input); err != nil {
 		return llm.ErrorfToolOut("failed to unmarshal user_patch input: %w", err)
 	}
 
-	// Validate the input
+	path := input.Path
 	if !filepath.IsAbs(input.Path) {
-		return llm.ErrorfToolOut("path %q is not absolute", input.Path)
+		if p.Pwd == "" {
+			return llm.ErrorfToolOut("path %q is not absolute and no working directory is set", input.Path)
+		}
+		path = filepath.Join(p.Pwd, input.Path)
 	}
+	input.Path = path
 	if len(input.Patches) == 0 {
 		return llm.ErrorToolOut(fmt.Errorf("no patches provided"))
 	}
diff --git a/loop/agent.go b/loop/agent.go
index 0953a56..5fb2f33 100644
--- a/loop/agent.go
+++ b/loop/agent.go
@@ -1392,6 +1392,7 @@
 	}
 	patchTool := &claudetool.PatchTool{
 		Callback: a.patchCallback,
+		Pwd:      a.workingDir,
 	}
 
 	// Register all tools with the conversation
diff --git a/loop/testdata/agent_loop.httprr b/loop/testdata/agent_loop.httprr
index fce2958..a0b8568 100644
--- a/loop/testdata/agent_loop.httprr
+++ b/loop/testdata/agent_loop.httprr
@@ -1,9 +1,9 @@
 httprr trace v1
-18228 2477
+18219 2468
 POST https://api.anthropic.com/v1/messages HTTP/1.1

 Host: api.anthropic.com

 User-Agent: Go-http-client/1.1

-Content-Length: 18030

+Content-Length: 18021

 Anthropic-Version: 2023-06-01

 Content-Type: application/json

 

@@ -85,7 +85,7 @@
     "properties": {
      "path": {
       "type": "string",
-      "description": "Absolute path to the file to patch"
+      "description": "Path to the file to patch"
      },
      "patches": {
       "type": "array",
@@ -557,24 +557,24 @@
 Anthropic-Organization-Id: 3c473a21-7208-450a-a9f8-80aebda45c1b

 Anthropic-Ratelimit-Input-Tokens-Limit: 2000000

 Anthropic-Ratelimit-Input-Tokens-Remaining: 2000000

-Anthropic-Ratelimit-Input-Tokens-Reset: 2025-07-30T18:29:45Z

+Anthropic-Ratelimit-Input-Tokens-Reset: 2025-07-30T19:14:22Z

 Anthropic-Ratelimit-Output-Tokens-Limit: 400000

 Anthropic-Ratelimit-Output-Tokens-Remaining: 400000

-Anthropic-Ratelimit-Output-Tokens-Reset: 2025-07-30T18:29:50Z

+Anthropic-Ratelimit-Output-Tokens-Reset: 2025-07-30T19:14:27Z

 Anthropic-Ratelimit-Requests-Limit: 4000

 Anthropic-Ratelimit-Requests-Remaining: 3999

-Anthropic-Ratelimit-Requests-Reset: 2025-07-30T18:29:44Z

+Anthropic-Ratelimit-Requests-Reset: 2025-07-30T19:14:21Z

 Anthropic-Ratelimit-Tokens-Limit: 2400000

 Anthropic-Ratelimit-Tokens-Remaining: 2400000

-Anthropic-Ratelimit-Tokens-Reset: 2025-07-30T18:29:45Z

+Anthropic-Ratelimit-Tokens-Reset: 2025-07-30T19:14:22Z

 Cf-Cache-Status: DYNAMIC

-Cf-Ray: 9676ec577ae3eb24-SJC

+Cf-Ray: 96772db40ff5cf27-SJC

 Content-Type: application/json

-Date: Wed, 30 Jul 2025 18:29:50 GMT

-Request-Id: req_011CRdgJS1bQMPR17iFwT9eP

+Date: Wed, 30 Jul 2025 19:14:27 GMT

+Request-Id: req_011CRdjhnD2HyANxHw5CqnXv

 Server: cloudflare

 Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

 Via: 1.1 google

 X-Robots-Tag: none

 

-{"id":"msg_01Gj3ha6GnJh81AQoF5vUENq","type":"message","role":"assistant","model":"claude-sonnet-4-20250514","content":[{"type":"text","text":"Here are the tools available to me:\n\n**File & Code Operations:**\n- `bash` - Execute shell commands\n- `patch` - Modify files with precise text edits\n- `keyword_search` - Search for files in unfamiliar codebases\n\n**Task Management:**\n- `todo_read` - Read current todo list\n- `todo_write` - Create and manage task lists\n- `think` - Think out loud, take notes, form plans\n\n**Development Workflow:**\n- `codereview` - Run automated code review\n- `done` - Mark work as complete with checklist verification\n\n**Browser Automation:**\n- `browser_navigate` - Navigate to URLs\n- `browser_click` - Click elements\n- `browser_type` - Type into input fields\n- `browser_wait_for` - Wait for elements\n- `browser_get_text` - Read page text\n- `browser_eval` - Execute JavaScript\n- `browser_scroll_into_view` - Scroll to elements\n- `browser_resize` - Resize browser window\n- `browser_take_screenshot` - Capture screenshots\n- `browser_recent_console_logs` - Get console logs\n- `browser_clear_console_logs` - Clear console logs\n\n**Utility:**\n- `about_sketch` - Get help with Sketch functionality\n- `read_image` - Read and encode image files"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":4179,"cache_read_input_tokens":0,"output_tokens":314,"service_tier":"standard"}}
\ No newline at end of file
+{"id":"msg_01LPHcYnvczudVFZMnpNPsv2","type":"message","role":"assistant","model":"claude-sonnet-4-20250514","content":[{"type":"text","text":"Here are the tools available to me:\n\n**Code & File Management:**\n- `bash` - Execute shell commands\n- `patch` - Modify files with precise text edits\n- `keyword_search` - Search for files/code with conceptual queries\n\n**Task Management:**\n- `todo_read` - Read current task list\n- `todo_write` - Create/update structured task list\n- `think` - Internal note-taking and planning\n\n**Development Workflow:**\n- `codereview` - Run automated code review\n- `done` - Complete work with verification checklist\n\n**Browser Automation:**\n- `browser_navigate` - Navigate to URLs\n- `browser_click` - Click elements\n- `browser_type` - Type into inputs\n- `browser_wait_for` - Wait for elements\n- `browser_get_text` - Read element text\n- `browser_eval` - Execute JavaScript\n- `browser_scroll_into_view` - Scroll to elements\n- `browser_resize` - Resize browser window\n- `browser_recent_console_logs` - Get console logs\n- `browser_clear_console_logs` - Clear console logs\n- `browser_take_screenshot` - Capture screenshots\n\n**Utilities:**\n- `read_image` - Read and encode image files\n- `about_sketch` - Get help about Sketch itself"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":3,"cache_creation_input_tokens":4177,"cache_read_input_tokens":0,"output_tokens":308,"service_tier":"standard"}}
\ No newline at end of file