Context-Aware Tool Restrictions

Description

The system enforces distinct tool availability depending on the execution context in which code runs. There are four primary contexts -- main session, sub-agent (sync or async), in-process teammate, and coordinator mode -- each with its own allowed/denied tool set. The restrictions are defined as static Set constants in src/constants/tools.ts and enforced through filtering functions in src/tools/AgentTool/agentToolUtils.ts (for agent contexts) and src/utils/toolPool.ts (for coordinator mode).

In the main session (REPL), all base tools returned by getAllBaseTools() in src/tools.ts are available, subject only to per-tool isEnabled() checks, feature flags, and permission deny-rules applied via filterToolsByDenyRules(). The full tool pool is assembled by assembleToolPool(), which combines built-in tools with MCP tools, deduplicates by name, and sorts for prompt-cache stability. The React hook useMergedTools (or the headless equivalent in main.tsx) then applies coordinator-mode filtering if active. When coordinator mode is off, the main session sees the complete tool set.

For sub-agents (spawned via AgentTool), tools pass through filterToolsForAgent() in agentToolUtils.ts. This function first removes all tools in ALL_AGENT_DISALLOWED_TOOLS (AgentTool itself for non-Anthropic users, TaskOutputTool, ExitPlanModeTool, EnterPlanModeTool, AskUserQuestionTool, TaskStopTool, WorkflowTool). For async agents specifically, only tools listed in ASYNC_AGENT_ALLOWED_TOOLS are kept -- a whitelist of filesystem, search, shell, editing, web, and skill tools. In-process teammates get additional tools beyond the async whitelist: IN_PROCESS_TEAMMATE_ALLOWED_TOOLS adds TaskCreate, TaskGet, TaskList, TaskUpdate, SendMessage, and (if feature-gated) cron scheduling tools. In-process teammates also regain access to AgentTool for spawning sync sub-agents. In coordinator mode, the main session itself is restricted to only COORDINATOR_MODE_ALLOWED_TOOLS: AgentTool, TaskStopTool, SendMessageTool, and SyntheticOutputTool (plus any PR activity subscription MCP tools matched by suffix). This filtering is applied by applyCoordinatorToolFilter() in toolPool.ts, which runs in both the REPL path (via mergeAndFilterTools) and the headless path (via main.tsx).

Key claims

Relations

Sources