@@ -26,6 +26,7 @@ import {
2626 WriteTextFileRequest ,
2727 WriteTextFileResponse ,
2828} from "@agentclientprotocol/sdk" ;
29+ import { SettingsManager } from "./settings.js" ;
2930import {
3031 CanUseTool ,
3132 McpServerConfig ,
@@ -40,14 +41,16 @@ import * as fs from "node:fs";
4041import * as path from "node:path" ;
4142import * as os from "node:os" ;
4243import { nodeToWebReadable , nodeToWebWritable , Pushable , unreachable } from "./utils.js" ;
43- import { createMcpServer , EDIT_TOOL_NAMES , toolNames } from "./mcp-server.js" ;
44+ import { createMcpServer } from "./mcp-server.js" ;
45+ import { EDIT_TOOL_NAMES , acpToolNames } from "./tools.js" ;
4446import {
4547 toolInfoFromToolUse ,
4648 planEntries ,
4749 toolUpdateFromToolResult ,
4850 ClaudePlanEntry ,
4951 registerHookCallback ,
5052 createPostToolUseHook ,
53+ createPreToolUseHook ,
5154} from "./tools.js" ;
5255import { ContentBlockParam } from "@anthropic-ai/sdk/resources" ;
5356import { BetaContentBlock , BetaRawContentBlockDelta } from "@anthropic-ai/sdk/resources/beta.mjs" ;
@@ -69,6 +72,7 @@ type Session = {
6972 input : Pushable < SDKUserMessage > ;
7073 cancelled : boolean ;
7174 permissionMode : PermissionMode ;
75+ settingsManager : SettingsManager ;
7276} ;
7377
7478type BackgroundTerminal =
@@ -205,6 +209,11 @@ export class ClaudeAcpAgent implements Agent {
205209 const sessionId = userProvidedOptions ?. resume || randomUUID ( ) ;
206210 const input = new Pushable < SDKUserMessage > ( ) ;
207211
212+ const settingsManager = new SettingsManager ( params . cwd , {
213+ logger : this . logger ,
214+ } ) ;
215+ await settingsManager . initialize ( ) ;
216+
208217 const mcpServers : Record < string , McpServerConfig > = { } ;
209218 if ( Array . isArray ( params . mcpServers ) ) {
210219 for ( const server of params . mcpServers ) {
@@ -284,6 +293,12 @@ export class ClaudeAcpAgent implements Agent {
284293 } ) ,
285294 hooks : {
286295 ...userProvidedOptions ?. hooks ,
296+ PreToolUse : [
297+ ...( userProvidedOptions ?. hooks ?. PreToolUse || [ ] ) ,
298+ {
299+ hooks : [ createPreToolUseHook ( settingsManager , this . logger ) ] ,
300+ } ,
301+ ] ,
287302 PostToolUse : [
288303 ...( userProvidedOptions ?. hooks ?. PostToolUse || [ ] ) ,
289304 {
@@ -301,25 +316,25 @@ export class ClaudeAcpAgent implements Agent {
301316
302317 if ( ! disableBuiltInTools ) {
303318 if ( this . clientCapabilities ?. fs ?. readTextFile ) {
304- allowedTools . push ( toolNames . read ) ;
319+ allowedTools . push ( acpToolNames . read ) ;
305320 disallowedTools . push ( "Read" ) ;
306321 }
307322 if ( this . clientCapabilities ?. fs ?. writeTextFile ) {
308323 disallowedTools . push ( "Write" , "Edit" ) ;
309324 }
310325 if ( this . clientCapabilities ?. terminal ) {
311- allowedTools . push ( toolNames . bashOutput , toolNames . killShell ) ;
326+ allowedTools . push ( acpToolNames . bashOutput , acpToolNames . killShell ) ;
312327 disallowedTools . push ( "Bash" , "BashOutput" , "KillShell" ) ;
313328 }
314329 } else {
315330 // When built-in tools are disabled, explicitly disallow all of them
316331 disallowedTools . push (
317- toolNames . read ,
318- toolNames . write ,
319- toolNames . edit ,
320- toolNames . bash ,
321- toolNames . bashOutput ,
322- toolNames . killShell ,
332+ acpToolNames . read ,
333+ acpToolNames . write ,
334+ acpToolNames . edit ,
335+ acpToolNames . bash ,
336+ acpToolNames . bashOutput ,
337+ acpToolNames . killShell ,
323338 "Read" ,
324339 "Write" ,
325340 "Edit" ,
@@ -363,6 +378,7 @@ export class ClaudeAcpAgent implements Agent {
363378 input : input ,
364379 cancelled : false ,
365380 permissionMode,
381+ settingsManager,
366382 } ;
367383
368384 const availableCommands = await getAvailableSlashCommands ( q ) ;
0 commit comments