Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
codex: force hosted web search correctly
Raine Virta02071711a104
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d6fc39a..3624aef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## Unreleased++- Codex forced hosted web search requests now map to Codex's hosted web search tool choice instead of a function tool choice, fixing repeated upstream `Tool choice 'function' not found in 'tools' parameter.` errors. ([#10](https://github.com/raine/claude-code-proxy/issues/10))+## v0.0.20 (2026-06-15)- Cursor's generic `cursor`, `cursor-agent`, `cursor-plan`, and `cursor-ask` aliases now use Cursor default model selection instead of forcing Composer 2.5 fast mode.diff --git a/src/providers/codex/count-tokens.ts b/src/providers/codex/count-tokens.tsindex 5002a0d..5a25969 100644--- a/src/providers/codex/count-tokens.ts+++ b/src/providers/codex/count-tokens.ts@@ -47,9 +47,9 @@ export function countTranslatedTokens(if (typeof req.tool_choice === "string") {total += encode(req.tool_choice).length;- } else if (req.tool_choice?.type === "function") {+ } else if (req.tool_choice) {total += encode(req.tool_choice.type).length;- total += encode(req.tool_choice.name).length;+ if ("name" in req.tool_choice) total += encode(req.tool_choice.name).length;}total += req.input.length * 4;diff --git a/src/providers/codex/translate/request.test.ts b/src/providers/codex/translate/request.test.tsindex f15317b..e4f964c 100644--- a/src/providers/codex/translate/request.test.ts+++ b/src/providers/codex/translate/request.test.ts@@ -58,6 +58,28 @@ describe("translateRequest", () => {]);});+ it("maps forced Anthropic web search choice to Codex hosted search choice", () => {+ const translated = translateRequest({+ ...baseRequest,+ tools: [+ {+ type: "web_search_20250305",+ name: "web_search",+ },+ ],+ tool_choice: { type: "tool", name: "web_search" },+ });++ expect(translated.tools).toEqual([+ {+ type: "web_search",+ external_web_access: false,+ search_content_types: ["text", "image"],+ },+ ]);+ expect(translated.tool_choice).toEqual({ type: "web_search" });+ });+it("preserves non-empty Anthropic web search domain filters", () => {const translated = translateRequest({...baseRequest,diff --git a/src/providers/codex/translate/request.ts b/src/providers/codex/translate/request.tsindex ad8f02c..5e28d3f 100644--- a/src/providers/codex/translate/request.ts+++ b/src/providers/codex/translate/request.ts@@ -33,7 +33,12 @@ export interface ResponsesRequest {instructions?: string;input: ResponsesInputItem[];tools?: ResponsesTool[];- tool_choice?: "auto" | "none" | "required" | { type: "function"; name: string };+ tool_choice?:+ | "auto"+ | "none"+ | "required"+ | { type: "function"; name: string }+ | { type: "web_search" };parallel_tool_calls?: boolean;reasoning?: { effort?: Effort; summary?: unknown };store: false;@@ -194,7 +199,7 @@ export function translateRequest(store: false,stream: true,parallel_tool_calls: true,- tool_choice: mapToolChoice(req.tool_choice),+ tool_choice: mapToolChoice(req.tool_choice, req.tools),text,};if (instructions) out.instructions = instructions;@@ -211,9 +216,13 @@ export function translateRequest(return out;}-function mapToolChoice(choice: AnthropicRequest["tool_choice"]): ResponsesRequest["tool_choice"] {+function mapToolChoice(+ choice: AnthropicRequest["tool_choice"],+ tools: AnthropicRequest["tools"],+): ResponsesRequest["tool_choice"] {const mapped = mapAnthropicToolChoice(choice);if (mapped === "auto" || mapped === "none" || mapped === "required") return mapped;+ if (isForcedHostedWebSearchChoice(choice, tools)) return { type: "web_search" };return { type: "function", name: mapped.name };}@@ -282,6 +291,16 @@ function isRecord(value: unknown): value is Record<string, unknown> {return !!value && typeof value === "object";}+function isForcedHostedWebSearchChoice(+ choice: AnthropicRequest["tool_choice"],+ tools: AnthropicRequest["tools"],+): boolean {+ if (choice?.type !== "tool" || !choice.name) return false;+ return (+ tools?.some((tool) => tool.type === "web_search_20250305" && tool.name === choice.name) ?? false+ );+}+function toResponsesTool(tool: AnthropicTool): ResponsesTool {if (tool.type === "web_search_20250305") {const filters: ResponsesWebSearchTool["filters"] = {};