exploreAgent.ts
1 import { BASH_TOOL_NAME } from 'src/tools/BashTool/toolName.js' 2 import { EXIT_PLAN_MODE_TOOL_NAME } from 'src/tools/ExitPlanModeTool/constants.js' 3 import { FILE_EDIT_TOOL_NAME } from 'src/tools/FileEditTool/constants.js' 4 import { FILE_READ_TOOL_NAME } from 'src/tools/FileReadTool/prompt.js' 5 import { FILE_WRITE_TOOL_NAME } from 'src/tools/FileWriteTool/prompt.js' 6 import { GLOB_TOOL_NAME } from 'src/tools/GlobTool/prompt.js' 7 import { GREP_TOOL_NAME } from 'src/tools/GrepTool/prompt.js' 8 import { NOTEBOOK_EDIT_TOOL_NAME } from 'src/tools/NotebookEditTool/constants.js' 9 import { hasEmbeddedSearchTools } from 'src/utils/embeddedTools.js' 10 import { AGENT_TOOL_NAME } from '../constants.js' 11 import type { BuiltInAgentDefinition } from '../loadAgentsDir.js' 12 13 function getExploreSystemPrompt(): string { 14 // Ant-native builds alias find/grep to embedded bfs/ugrep and remove the 15 // dedicated Glob/Grep tools, so point at find/grep via Bash instead. 16 const embedded = hasEmbeddedSearchTools() 17 const globGuidance = embedded 18 ? `- Use \`find\` via ${BASH_TOOL_NAME} for broad file pattern matching` 19 : `- Use ${GLOB_TOOL_NAME} for broad file pattern matching` 20 const grepGuidance = embedded 21 ? `- Use \`grep\` via ${BASH_TOOL_NAME} for searching file contents with regex` 22 : `- Use ${GREP_TOOL_NAME} for searching file contents with regex` 23 24 return `You are a file search specialist for Claude Code, Anthropic's official CLI for Claude. You excel at thoroughly navigating and exploring codebases. 25 26 === CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS === 27 This is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from: 28 - Creating new files (no Write, touch, or file creation of any kind) 29 - Modifying existing files (no Edit operations) 30 - Deleting files (no rm or deletion) 31 - Moving or copying files (no mv or cp) 32 - Creating temporary files anywhere, including /tmp 33 - Using redirect operators (>, >>, |) or heredocs to write to files 34 - Running ANY commands that change system state 35 36 Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail. 37 38 Your strengths: 39 - Rapidly finding files using glob patterns 40 - Searching code and text with powerful regex patterns 41 - Reading and analyzing file contents 42 43 Guidelines: 44 ${globGuidance} 45 ${grepGuidance} 46 - Use ${FILE_READ_TOOL_NAME} when you know the specific file path you need to read 47 - Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find${embedded ? ', grep' : ''}, cat, head, tail) 48 - NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification 49 - Adapt your search approach based on the thoroughness level specified by the caller 50 - Communicate your final report directly as a regular message - do NOT attempt to create files 51 52 NOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must: 53 - Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations 54 - Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files 55 56 Complete the user's search request efficiently and report your findings clearly.` 57 } 58 59 export const EXPLORE_AGENT_MIN_QUERIES = 3 60 61 const EXPLORE_WHEN_TO_USE = 62 'Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions.' 63 64 export const EXPLORE_AGENT: BuiltInAgentDefinition = { 65 agentType: 'Explore', 66 whenToUse: EXPLORE_WHEN_TO_USE, 67 disallowedTools: [ 68 AGENT_TOOL_NAME, 69 EXIT_PLAN_MODE_TOOL_NAME, 70 FILE_EDIT_TOOL_NAME, 71 FILE_WRITE_TOOL_NAME, 72 NOTEBOOK_EDIT_TOOL_NAME, 73 ], 74 source: 'built-in', 75 baseDir: 'built-in', 76 // Ants get inherit to use the main agent's model; external users get haiku for speed 77 // Note: For ants, getAgentModel() checks tengu_explore_agent GrowthBook flag at runtime 78 model: process.env.USER_TYPE === 'ant' ? 'inherit' : 'haiku', 79 // Explore is a fast read-only search agent — it doesn't need commit/PR/lint 80 // rules from CLAUDE.md. The main agent has full context and interprets results. 81 omitClaudeMd: true, 82 getSystemPrompt: () => getExploreSystemPrompt(), 83 }