AnyRouter supports Code Mode
Code Mode changes how an agent uses tools. Without it, the agent asks for one tool, reads the whole result, then asks for the next tool. With it, the agent writes one piece of JavaScript. That program calls the tools, uses one result in the next call, and returns only the part the agent needs to read.
Claude Code does this for its own tools: one program can search, edit, and run a check, and Claude reads the last line. Cloudflare runs that kind of program in an isolate, so the code cannot wander onto the network. AnyRouter Code Mode is the same idea for the servers you have connected. The program calls those servers. The code runs in a Cloudflare isolate. Your key never enters the program.
One program, several tool calls
You still describe the task in a prompt. The agent writes the program. A lookup, a filter, and a write can be one step.
One tool at a time
12,800 tokens through the model
list_issues(page=1)
3,200 tokens
tool call · 40 issues come back
list_issues(page=2)
3,200 tokens
tool call · 40 more issues come back
create_page()
6,400 tokens
the model copies both lists into this call
…
another tool call, and the results come back again
Code Mode
140 tokens the model reads
one program
Sandbox
list_issues(page=1)
3,200 tokens
40 issues stay here
list_issues(page=2)
3,200 tokens
40 issues stay here
create_page()
uses the lists already here
return { count, url }
20 tokens
this is the only result the model reads
One tool at a time
12,800 tokens
3,200 tokens from page 1, 3,200 tokens from page 2, then both lists again inside create_page.
Code Mode
140 tokens
The program is about 120 tokens. The answer is 20 tokens. The 6,400 tokens of issues stay in the sandbox.
const issues = await linear__list_issues({ team: "APP" })
const open = issues.filter((issue) => issue.state === "open")
const page = await notion__create_page({
title: "Open issues",
body: open.map((issue) => issue.title).join("\n"),
})
return { count: open.length, url: page.url }The agent sees { count, url }. It does not see every issue, and it does not copy that list into the next call by hand. console.log comes back too, when the program wants to leave a note.
Two tools do the work. search_tools finds a connected tool and returns a TypeScript signature, declare function linear__list_issues(...). execute runs the JavaScript. The sandbox already has that function. Calling it runs the same MCP tool your key can call. The full catalog is not loaded into the prompt first.
What the program cannot do
The isolate has no network of its own. Each generated function calls back to AnyRouter, which runs that tool with your key and your connections, the same way a normal MCP call would. A name that is not a JavaScript identifier still goes through codemode.call.
- A tool your key cannot use was never registered, so the program cannot call it.
- The program cannot fetch an arbitrary URL, and it never sees the key.
- If the program returns a secret, the agent sees that secret. Return the answer, not the raw payload.
This is not Claude Code's own Code Mode. That feature runs inside Claude Code and does not go through a gateway. AnyRouter Code Mode is for any agent you point at the AnyRouter MCP URL.
Turn it on
Code Mode is off until you opt in. On the MCP page in the dashboard, turn on Code mode. Or send { "code": true } to PATCH /api/v1/mcp/config. Until then, the Code Mode URL answers 403.
anyr still connects search mode. Search mode finds tools one at a time. It does not run a program. When you want Code Mode, connect this URL yourself.
claude mcp add --transport http anyrouter-codemode \
"https://anyrouter.dev/api/v1/mcp?codemode=1" \
--header "Authorization: Bearer $ANYROUTER_API_KEY"A run that finishes costs $0.01 of workspace credit. A run that fails is free. A balance below that price is refused before the program starts.
