# AnyRouter Code Mode

> AnyRouter supports Code Mode. The agent writes one JavaScript program that calls your MCP tools, and only the answer comes back.

- Date: November 23, 2026
- Category: guides
- HTML: https://anyrouter.dev/blog/code-mode

## 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.

_(Interactive embed `code-mode-flow` — see the [HTML version](https://anyrouter.dev/blog).)_

```javascript
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 body of one Code Mode run. Each name is a function generated from a connected MCP tool._

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.

```bash
claude mcp add --transport http anyrouter-codemode \
  "https://anyrouter.dev/api/v1/mcp?codemode=1" \
  --header "Authorization: Bearer $ANYROUTER_API_KEY"
```

_Any client that takes a Streamable HTTP URL._

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.
