()
| 170 | * (unset) tst (default: always defer MCP and shouldDefer tools) |
| 171 | */ |
| 172 | export function getToolSearchMode(): ToolSearchMode { |
| 173 | // CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS is a kill switch for beta API |
| 174 | // features. Tool search emits defer_loading on tool definitions and |
| 175 | // tool_reference content blocks — both require the API to accept a beta |
| 176 | // header. When the kill switch is set, force 'standard' so no beta shapes |
| 177 | // reach the wire, even if ENABLE_TOOL_SEARCH is also set. This is the |
| 178 | // explicit escape hatch for proxy gateways that the heuristic in |
| 179 | // isToolSearchEnabledOptimistic doesn't cover. |
| 180 | // github.com/anthropics/claude-code/issues/20031 |
| 181 | if (isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS)) { |
| 182 | return 'standard' |
| 183 | } |
| 184 | |
| 185 | const value = process.env.ENABLE_TOOL_SEARCH |
| 186 | |
| 187 | // Handle auto:N syntax - check edge cases first |
| 188 | const autoPercent = value ? parseAutoPercentage(value) : null |
| 189 | if (autoPercent === 0) return 'tst' // auto:0 = always enabled |
| 190 | if (autoPercent === 100) return 'standard' |
| 191 | if (isAutoToolSearchMode(value)) { |
| 192 | return 'tst-auto' // auto or auto:1-99 |
| 193 | } |
| 194 | |
| 195 | if (isEnvTruthy(value)) return 'tst' |
| 196 | if (isEnvDefinedFalsy(process.env.ENABLE_TOOL_SEARCH)) return 'standard' |
| 197 | return 'tst' // default: always defer MCP and shouldDefer tools |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Default patterns for models that do NOT support tool_reference. |
no test coverage detected