# Claude Code's Code Mode vs CodeCall: Where Should the Script Run?

> Code Mode runs Claude's JavaScript in Claude Code; CodeCall runs it on your MCP server, for every client. 20 runs compared: speed, tokens, data, accuracy.

Source: https://frontmcp.dev/blog/claude-code-code-mode-vs-codecall
Published: 2026-11-19
Author: David Antoon
Example version: FrontMCP 1.12.2
Technical checks recorded: 2026-11-19
Scope: Dated article; use the maintained reference for current instructions. Its presence in a release snapshot does not verify its code against that release.

*[Illustration: The script runs where the data is. Claude sends codecall:execute with a script to Claude Code, or any MCP client, which sends one tools/call to a FrontMCP server running CodeCall and Enclave. The server reads three lists, 138,680 bytes, and sends back five accounts, 484 bytes, and Claude gets the answer.]*

On November 12, 2026, Claude Code 2.1.323 shipped [Code Mode](https://code.claude.com/docs/en/code-mode), an experimental mode that changes how Claude uses tools. Without it, Claude asks for one tool call, reads the result, and decides on the next one. With it, Claude "writes a piece of JavaScript that makes the tool calls, and Claude Code runs that code in your session." One script can run calls in parallel, feed one result into the next call, and return only the part Claude needs to read.

That's the [code-execution pattern for MCP](https://www.anthropic.com/research/code-execution-with-mcp), and FrontMCP has shipped it on the server side since 2025 as [CodeCall](https://frontmcp.dev/reference/plugins/codecall): the model searches a server's tools, sends one script to `codecall:execute`, and the server runs it in [Enclave](https://github.com/agentfront/enclave), AgentFront's sandbox for code that agents write. ([Cloudflare's Code Mode MCP server](https://blog.cloudflare.com/code-mode-mcp/) takes the same server-side route, with a `search()` and an `execute()` tool.) Same idea, different place. Code Mode runs the script in Claude Code, on the user's machine. CodeCall runs it in the MCP server, next to the data, for whatever client calls it.

So we ran them side by side: one FrontMCP server, Claude Opus 5.5 in Claude Code 2.1.328, four setups, 20 runs. This post has the numbers, the server (it runs on this page), where each approach wins, and the two things a client-side mode can't bring: the server's own knowledge of its data, and work that outlives a script.

What we found:

- **Same answers.** All 12 runs of the first question, in all four setups, named the right five accounts with the right totals.
- **Both cut the work.** With plain tool calls, the question took 36.2 seconds and added 29,490 tokens to Claude's context (medians). Code Mode took 24.2 seconds and 8,627 tokens. CodeCall, with Code Mode off, took 26.8 seconds and 9,669 tokens.
- **Only CodeCall kept the data on the server.** It sent Claude Code 21 KB. When Claude Code did the join, the server sent it 302 KB.
- **The server's skill decided the vague question.** Asked for the accounts "most at risk", Claude named the company's five in all 4 runs where the server shipped its definition, in Code Mode and with CodeCall, and in none of the 4 runs where it didn't.
- **What each costs.** AgentScript refused Claude's first script in all 8 CodeCall runs, for using `Set`, which cost a request each time. Code Mode runs only in Claude Code's terminal, on the Anthropic API, and is experimental.

<a id="what-claude-codes-code-mode-does"></a>

## What Claude Code's Code Mode does

You turn it on with an environment variable, `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1`, and confirm once. Claude then gets a `REPL` tool that runs JavaScript, and Claude Code's tools become async functions inside it: `$` for shell commands, `edit()` for edits, and every connected MCP server's tools by their full names. This is part of a script Claude wrote in one of our runs, reformatted, calling three tools of our server at once:

```js
const [c, i, tk] = await Promise.all([
  tools.mcp__billing__list_customers({ plan: "enterprise" }),
  tools.mcp__billing__list_invoices({ status: "overdue" }),
  tools.mcp__billing__list_tickets({ status: "open", priority: "high" }),
]);
```

Each call in a script still goes through your permission rules and `PreToolUse` hooks under the tool's usual name. In auto mode, a classifier reviews the script before it runs, and Anthropic's page warns that it "doesn't see values computed at run time, such as a path taken from search output". A script you wait on stops after ten minutes; in the background it can run for two hours.

It has limits worth reading before you plan around it ([requirements](https://code.claude.com/docs/en/code-mode#requirements)):

- **Where:** an interactive `claude` session in a terminal, from the native build. Not `claude -p`, the Agent SDK, the VS Code panel, the Desktop app or cloud sessions.
- **Which accounts:** a Claude subscription or a Console account, directly against the Anthropic API. Not through a gateway, Amazon Bedrock, Google Cloud or Microsoft Foundry, and not with the HIPAA configuration or zero data retention.
- **Which models:** Claude Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.2.
- **Status:** "experimental and off by default. It may change or be removed in any release."

<a id="what-codecall-does"></a>

## What CodeCall does

[CodeCall](https://frontmcp.dev/reference/plugins/codecall) is a FrontMCP plugin. With `mode: "codecall_only"`, `tools/list` shows six tools instead of the server's own: the model finds tools with `codecall:search`, reads their input and output schemas with `codecall:describe`, and sends a script to `codecall:execute`. The script is AgentScript, a subset of JavaScript. Enclave parses it and, before it runs, refuses anything that could reach the host, like `eval`, `fetch`, `process`, `globalThis` and `.constructor`, and constructs it doesn't allow, like `while` loops. Then it runs the script with a deadline and a cap on tool calls. Each `callTool()` goes through the server's normal call flow, with the caller's credentials, hooks and input validation. Only what the script returns goes back.

To a client, CodeCall's tools are ordinary MCP tools. ChatGPT, Cursor, Claude Desktop, `claude -p`, the Agent SDK and Claude Code, with Code Mode or without, call `codecall:execute` like any other tool, with any model that can call one.

<a id="the-server-we-tested"></a>

## The server we tested

A hypothetical billing and support product with 600 customers, 2,400 invoices and 1,800 tickets, generated in `billing.data.ts`. Eight tools read and change it. One of them, `change_plan`, is marked destructive, and CodeCall keeps it out of reach with `includeTools`. The app also has a skill, three jobs and a workflow, which later sections use.

The question we gave Claude: *"Which five enterprise customers with an open high-priority ticket owe us the most in overdue invoices? For each, give the overdue total in dollars and their account manager's email."* Answering it means joining three lists: 165 enterprise customers, 292 overdue invoices and 241 open high-priority tickets, 138,680 bytes of JSON as the tools return them. Then one lookup per account manager.

The **Call** tab below sends `codecall:execute` the script a model would write for it, and shows the five accounts it returns: 484 bytes. Open the **Tests** tab: its nine tests check every number in this post that comes from the server, in Node and in your browser.

Initial call configuration:

```js
{ tool: "codecall:execute", arguments: { script: [
'const { customers } = await callTool("list_customers", { plan: "enterprise" });',
'const { invoices } = await callTool("list_invoices", { status: "overdue" });',
'const { tickets } = await callTool("list_tickets", { status: "open", priority: "high" });',
'const owed = {};',
'for (const invoice of invoices) owed[invoice.customerId] = (owed[invoice.customerId] ?? 0) + invoice.amountCents;',
'const urgent = {};',
'for (const ticket of tickets) urgent[ticket.customerId] = true;',
'const top = customers',
'  .filter((customer) => owed[customer.id] && urgent[customer.id])',
'  .sort((a, b) => owed[b.id] - owed[a.id])',
'  .slice(0, 5);',
'const rows = [];',
'for (const customer of top) {',
'  const manager = await callTool("get_manager", { id: customer.managerId });',
'  rows.push({ customer: customer.name, overdueDollars: owed[customer.id] / 100, manager: manager.email });',
'}',
'return rows;',
].join("\n") } }
```

```ts billing.app.ts active
import { App } from "@frontmcp/sdk";
import { CodeCallPlugin } from "@frontmcp/plugin-codecall";
import { billingTools } from "./billing.tools";
import { AtRiskAccounts, CollectionsRun, FindAtRiskAccounts, FlagUrgentTickets, RemindOverdueCustomers } from "./collections";

@App({
  id: "billing",
  name: "Billing and Support",
  tools: billingTools,
  skills: [AtRiskAccounts],
  jobs: [FindAtRiskAccounts, RemindOverdueCustomers, FlagUrgentTickets],
  workflows: [CollectionsRun],
  plugins: [
    CodeCallPlugin.init({
      mode: "codecall_only",
      includeTools: (tool) => !tool.annotations?.destructiveHint,
      vm: { maxSanitizeProperties: 10_000 },
    }),
  ],
})
export class BillingApp {}
```

```ts billing.tools.ts
import { PublicMcpError, Tool, ToolContext, z } from "@frontmcp/sdk";
import { customers, customerSchema, invoices, invoiceSchema, managers, managerSchema, tickets, ticketSchema } from "./billing.data";

const notFound = (kind: string, id: string) => new PublicMcpError(`There's no ${kind} ${id}.`, "NOT_FOUND");

@Tool({
  name: "list_customers",
  description: "List customers, with their plan, region, seat count and account manager's id. Filter by plan and region.",
  inputSchema: {
    plan: z.enum(["starter", "team", "enterprise"]).optional().describe("Only customers on this plan"),
    region: z.enum(["us", "eu", "apac"]).optional().describe("Only customers in this region"),
  },
  outputSchema: { customers: z.array(customerSchema) },
  annotations: { readOnlyHint: true },
})
class ListCustomers extends ToolContext {
  async execute({ plan, region }: { plan?: string; region?: string }) {
    return { customers: customers.filter((customer) => (!plan || customer.plan === plan) && (!region || customer.region === region)) };
  }
}

@Tool({
  name: "get_customer",
  description: "Get one customer by id.",
  inputSchema: { id: z.string().describe("The customer's id, like C-1") },
  outputSchema: customerSchema.shape,
  annotations: { readOnlyHint: true },
})
class GetCustomer extends ToolContext {
  async execute({ id }: { id: string }) {
    return customers.find((customer) => customer.id === id) ?? this.fail(notFound("customer", id));
  }
}

@Tool({
  name: "list_invoices",
  description: "List invoices with their lines. Filter by status and customer. Amounts are in US cents.",
  inputSchema: {
    status: z.enum(["paid", "open", "overdue"]).optional().describe("Only invoices with this status"),
    customerId: z.string().optional().describe("Only this customer's invoices, like C-1"),
  },
  outputSchema: { invoices: z.array(invoiceSchema) },
  annotations: { readOnlyHint: true },
})
class ListInvoices extends ToolContext {
  async execute({ status, customerId }: { status?: string; customerId?: string }) {
    return { invoices: invoices.filter((invoice) => (!status || invoice.status === status) && (!customerId || invoice.customerId === customerId)) };
  }
}

@Tool({
  name: "list_tickets",
  description: "List support tickets. Filter by status, priority and customer.",
  inputSchema: {
    status: z.enum(["open", "closed"]).optional().describe("Only tickets with this status"),
    priority: z.enum(["low", "normal", "high"]).optional().describe("Only tickets with this priority"),
    customerId: z.string().optional().describe("Only this customer's tickets, like C-1"),
  },
  outputSchema: { tickets: z.array(ticketSchema) },
  annotations: { readOnlyHint: true },
})
class ListTickets extends ToolContext {
  async execute({ status, priority, customerId }: { status?: string; priority?: string; customerId?: string }) {
    return {
      tickets: tickets.filter(
        (ticket) => (!status || ticket.status === status) && (!priority || ticket.priority === priority) && (!customerId || ticket.customerId === customerId),
      ),
    };
  }
}

@Tool({
  name: "get_manager",
  description: "Get an account manager by id, with their email.",
  inputSchema: { id: z.string().describe("The manager's id, like M-1") },
  outputSchema: managerSchema.shape,
  annotations: { readOnlyHint: true },
})
class GetManager extends ToolContext {
  async execute({ id }: { id: string }) {
    return managers.find((manager) => manager.id === id) ?? this.fail(notFound("manager", id));
  }
}

@Tool({
  name: "add_ticket_note",
  description: "Add an internal note to a support ticket. The customer doesn't see it.",
  inputSchema: { ticketId: z.string().describe("The ticket's id, like T-1"), note: z.string().min(1) },
  outputSchema: ticketSchema.shape,
})
class AddTicketNote extends ToolContext {
  async execute({ ticketId, note }: { ticketId: string; note: string }) {
    const ticket = tickets.find((candidate) => candidate.id === ticketId) ?? this.fail(notFound("ticket", ticketId));
    ticket.notes.push(note);
    return ticket;
  }
}

@Tool({
  name: "send_payment_reminder",
  description: "Email the customer a reminder for one overdue invoice.",
  inputSchema: { invoiceId: z.string().describe("The invoice's id, like INV-1001") },
  outputSchema: { invoiceId: z.string(), sentTo: z.string() },
})
class SendPaymentReminder extends ToolContext {
  async execute({ invoiceId }: { invoiceId: string }) {
    const invoice = invoices.find((candidate) => candidate.id === invoiceId) ?? this.fail(notFound("invoice", invoiceId));
    if (invoice.status !== "overdue") this.fail(new PublicMcpError(`Invoice ${invoiceId} isn't overdue.`, "NOT_OVERDUE"));
    return { invoiceId, sentTo: `billing@${invoice.customerId.toLowerCase()}.example.com` };
  }
}

@Tool({
  name: "change_plan",
  description: "Move a customer to another plan. Takes effect on the next invoice.",
  inputSchema: { customerId: z.string().describe("The customer's id, like C-1"), plan: z.enum(["starter", "team", "enterprise"]) },
  outputSchema: customerSchema.shape,
  annotations: { destructiveHint: true },
})
class ChangePlan extends ToolContext {
  async execute({ customerId, plan }: { customerId: string; plan: "starter" | "team" | "enterprise" }) {
    const customer = customers.find((candidate) => candidate.id === customerId) ?? this.fail(notFound("customer", customerId));
    customer.plan = plan;
    return customer;
  }
}

export const billingTools = [ListCustomers, GetCustomer, ListInvoices, ListTickets, GetManager, AddTicketNote, SendPaymentReminder, ChangePlan];
```

```ts collections.ts
import { Job, JobContext, Skill, Workflow, z } from "@frontmcp/sdk";
import { customers, invoices, managers, tickets } from "./billing.data";

@Skill({
  name: "at-risk-accounts",
  description: "Find the enterprise accounts most at risk: money overdue and an urgent ticket open. Rank them and name their account managers.",
  instructions: `An account is at risk when the customer is on the enterprise plan, has at least one invoice with status "overdue", and has at least one ticket with status "open" and priority "high". Rank at-risk accounts by the total of their overdue invoices, largest first.
1. Call list_customers with plan "enterprise", list_invoices with status "overdue", and list_tickets with status "open" and priority "high". Let the tools filter: don't list everything and filter afterwards.
2. Join the three lists by customerId. amountCents is in US cents: divide a total by 100 for dollars.
3. Call get_manager once for each manager of the accounts you report, and give each account's name, overdue total in dollars and manager's email.`,
  tools: ["list_customers", "list_invoices", "list_tickets", "get_manager"],
  tags: ["billing", "support"],
})
export class AtRiskAccounts {}

@Job({
  name: "find-at-risk-accounts",
  description: "Find at-risk enterprise accounts: an overdue invoice and an open high-priority ticket.",
  inputSchema: {},
  outputSchema: { customerIds: z.array(z.string()), ticketIds: z.array(z.string()) },
})
export class FindAtRiskAccounts extends JobContext {
  async execute() {
    const overdue = new Set(invoices.filter((invoice) => invoice.status === "overdue").map((invoice) => invoice.customerId));
    const urgent = tickets.filter((ticket) => ticket.status === "open" && ticket.priority === "high");
    const atRisk = customers.filter((customer) => customer.plan === "enterprise" && overdue.has(customer.id) && urgent.some((ticket) => ticket.customerId === customer.id));
    const customerIds = atRisk.map((customer) => customer.id);
    return { customerIds, ticketIds: urgent.filter((ticket) => customerIds.includes(ticket.customerId)).map((ticket) => ticket.id) };
  }
}

@Job({
  name: "remind-overdue-customers",
  description: "Send a payment reminder for every overdue invoice of these customers.",
  inputSchema: { customerIds: z.array(z.string()) },
  outputSchema: { reminded: z.array(z.string()) },
  retry: { maxAttempts: 3, backoffMs: 1000 },
})
export class RemindOverdueCustomers extends JobContext {
  async execute({ customerIds }: { customerIds: string[] }) {
    const due = invoices.filter((invoice) => invoice.status === "overdue" && customerIds.includes(invoice.customerId));
    for (const invoice of due) await this.callTool("send_payment_reminder", { invoiceId: invoice.id });
    this.log(`Sent ${due.length} reminders`);
    return { reminded: due.map((invoice) => invoice.id) };
  }
}

@Job({
  name: "flag-urgent-tickets",
  description: "Add a note to each ticket that its customer has an overdue invoice, with the account manager's email.",
  inputSchema: { ticketIds: z.array(z.string()) },
  outputSchema: { flagged: z.array(z.string()) },
})
export class FlagUrgentTickets extends JobContext {
  async execute({ ticketIds }: { ticketIds: string[] }) {
    for (const ticketId of ticketIds) {
      const ticket = tickets.find((candidate) => candidate.id === ticketId)!;
      const manager = managers.find((candidate) => candidate.id === customers.find((customer) => customer.id === ticket.customerId)!.managerId)!;
      await this.callTool("add_ticket_note", { ticketId, note: `Overdue invoice on this account. Account manager: ${manager.email}` });
    }
    return { flagged: ticketIds };
  }
}

@Workflow({
  name: "collections-run",
  description: "Find at-risk enterprise accounts, remind them of overdue invoices, and flag their urgent tickets.",
  steps: [
    { id: "find", jobName: "find-at-risk-accounts" },
    { id: "remind", jobName: "remind-overdue-customers", dependsOn: ["find"], input: (steps) => ({ customerIds: steps.get("find").outputs.customerIds }) },
    { id: "flag", jobName: "flag-urgent-tickets", dependsOn: ["find"], input: (steps) => ({ ticketIds: steps.get("find").outputs.ticketIds }) },
  ],
})
export class CollectionsRun {}
```

```ts billing.data.ts
import { z } from "@frontmcp/sdk";

export const customerSchema = z.object({
  id: z.string(),
  name: z.string(),
  plan: z.enum(["starter", "team", "enterprise"]),
  region: z.enum(["us", "eu", "apac"]),
  managerId: z.string().describe("The account manager's id, like M-1"),
  seats: z.number(),
});

export const invoiceSchema = z.object({
  id: z.string(),
  customerId: z.string(),
  status: z.enum(["paid", "open", "overdue"]),
  amountCents: z.number().describe("The invoice total, in US cents"),
  dueOn: z.string(),
  lines: z.array(z.object({ description: z.string(), quantity: z.number(), unitPriceCents: z.number() })),
});

export const ticketSchema = z.object({
  id: z.string(),
  customerId: z.string(),
  title: z.string(),
  priority: z.enum(["low", "normal", "high"]),
  status: z.enum(["open", "closed"]),
  openedOn: z.string(),
  notes: z.array(z.string()),
});

export const managerSchema = z.object({ id: z.string(), name: z.string(), email: z.string(), team: z.string() });

export type Customer = z.infer<typeof customerSchema>;
export type Invoice = z.infer<typeof invoiceSchema>;
export type Ticket = z.infer<typeof ticketSchema>;

const companyNames = ["Northwind", "Blue Harbor", "Copperline", "Fernwood", "Granite Peak", "Lumen", "Meridian", "Oakridge", "Pinecrest", "Quarry Lane", "Redwood", "Silverlake", "Tidewater", "Upland", "Willow Creek", "Amberfield", "Brightwater", "Cedar Point", "Driftwood", "Eastgate", "Foxglove", "Harborview", "Ironbridge", "Juniper", "Kestrel", "Larkspur", "Maple Row", "Nightingale", "Orchard Hill", "Riverbend"];
const companyKinds = ["Labs", "Logistics", "Health", "Foods", "Systems", "Studio", "Energy", "Retail", "Robotics", "Media", "Analytics", "Freight", "Clinics", "Software", "Capital", "Outdoors", "Pharma", "Travel", "Security", "Learning"];
const plans = ["enterprise", "team", "starter", "starter"] as const;
const regions = ["us", "eu", "apac"] as const;
const ticketTitles = ["SSO login fails for new users", "Export to CSV times out", "Invoice shows the wrong seat count", "Webhook deliveries are delayed", "API returns 429 under normal load", "Dashboard charts are empty"];
const months = ["2026-07", "2026-08", "2026-09", "2026-10"];

const pick = (seed: number, range: number) => {
  let mixed = Math.imul(seed ^ 0x9e3779b9, 0x85ebca6b);
  mixed ^= mixed >>> 13;
  mixed = Math.imul(mixed, 0xc2b2ae35);
  mixed ^= mixed >>> 16;
  return (mixed >>> 0) % range;
};

export const managers = [
  { id: "M-1", name: "Dana Okafor", email: "dana.okafor@example.com", team: "Enterprise East" },
  { id: "M-2", name: "Luis Moreno", email: "luis.moreno@example.com", team: "Enterprise West" },
  { id: "M-3", name: "Priya Raman", email: "priya.raman@example.com", team: "EMEA" },
  { id: "M-4", name: "Kenji Sato", email: "kenji.sato@example.com", team: "APAC" },
  { id: "M-5", name: "Ruth Adler", email: "ruth.adler@example.com", team: "Growth" },
  { id: "M-6", name: "Sam Whitfield", email: "sam.whitfield@example.com", team: "Growth" },
];

export const customers: Customer[] = companyNames.flatMap((name, row) =>
  companyKinds.map((kind, column) => {
    const index = row * companyKinds.length + column;
    const plan = plans[pick(index + 500, plans.length)];
    return {
      id: `C-${index + 1}`,
      name: `${name} ${kind}`,
      plan,
      region: regions[pick(index + 900, regions.length)],
      managerId: `M-${pick(index + 1300, managers.length) + 1}`,
      seats: plan === "enterprise" ? 150 + pick(index, 850) : plan === "team" ? 20 + pick(index, 80) : 1 + pick(index, 15),
    };
  }),
);

export const invoices: Invoice[] = customers.flatMap((customer, customerIndex) =>
  months.map((month, monthIndex) => {
    const seed = customerIndex * months.length + monthIndex;
    const seatPrice = customer.plan === "enterprise" ? 3200 : customer.plan === "team" ? 1800 : 1200;
    const lines = [
      { description: "Platform fee", quantity: 1, unitPriceCents: customer.plan === "enterprise" ? 250000 : 4900 },
      { description: "Seats", quantity: customer.seats, unitPriceCents: seatPrice },
      { description: "Support", quantity: 1, unitPriceCents: customer.plan === "enterprise" ? 90000 : 0 },
    ];
    const overdue = monthIndex < 3 && pick(seed + 7000, 6) === 0;
    return {
      id: `INV-${1001 + seed}`,
      customerId: customer.id,
      status: overdue ? "overdue" : monthIndex === 3 ? "open" : "paid",
      amountCents: lines.reduce((sum, line) => sum + line.quantity * line.unitPriceCents, 0),
      dueOn: `${month}-28`,
      lines,
    };
  }),
);

export const tickets: Ticket[] = customers.flatMap((customer, customerIndex) =>
  [0, 1, 2].map((slot) => {
    const seed = customerIndex * 3 + slot;
    const roll = pick(seed + 101, 4);
    return {
      id: `T-${seed + 1}`,
      customerId: customer.id,
      title: ticketTitles[seed % ticketTitles.length],
      priority: roll === 0 ? "high" : roll < 3 ? "normal" : "low",
      status: pick(seed + 211, 2) === 0 ? "open" : "closed",
      openedOn: `2026-11-${String(1 + (seed % 17)).padStart(2, "0")}`,
      notes: [],
    };
  }),
);
```

```ts main.ts
import "reflect-metadata";
import { FrontMcp } from "@frontmcp/sdk";
import { BillingApp } from "./billing.app";

@FrontMcp({
  info: { name: "Billing and Support", version: "1.0.0" },
  apps: [BillingApp],
})
export default class BillingServer {}
```

```ts billing.test.ts
import { test, expect } from "@frontmcp/testing";
import { App, connect } from "@frontmcp/sdk";
import { CodeCallPlugin } from "@frontmcp/plugin-codecall";
import { billingTools } from "./billing.tools";
import { customers, invoices, tickets } from "./billing.data";
import { AtRiskAccounts, CollectionsRun, FindAtRiskAccounts, FlagUrgentTickets, RemindOverdueCustomers } from "./collections";

const atRiskScript = `
const { customers } = await callTool("list_customers", { plan: "enterprise" });
const { invoices } = await callTool("list_invoices", { status: "overdue" });
const { tickets } = await callTool("list_tickets", { status: "open", priority: "high" });
const owed = {};
for (const invoice of invoices) owed[invoice.customerId] = (owed[invoice.customerId] ?? 0) + invoice.amountCents;
const urgent = {};
for (const ticket of tickets) urgent[ticket.customerId] = true;
const top = customers
  .filter((customer) => owed[customer.id] && urgent[customer.id])
  .sort((a, b) => owed[b.id] - owed[a.id])
  .slice(0, 5);
const rows = [];
for (const customer of top) {
  const manager = await callTool("get_manager", { id: customer.managerId });
  rows.push({ customer: customer.name, overdueDollars: owed[customer.id] / 100, manager: manager.email });
}
return rows;
`.trim();

const fiveAccounts = [
  { customer: "Driftwood Learning", overdueDollars: 96120, manager: "luis.moreno@example.com" },
  { customer: "Blue Harbor Travel", overdueDollars: 52368, manager: "kenji.sato@example.com" },
  { customer: "Northwind Pharma", overdueDollars: 40912, manager: "dana.okafor@example.com" },
  { customer: "Brightwater Foods", overdueDollars: 34792, manager: "kenji.sato@example.com" },
  { customer: "Meridian Robotics", overdueDollars: 30152, manager: "kenji.sato@example.com" },
];

const callAndParse = async (mcp: any, tool: string, input: object) => (await mcp.tools.call(tool, input)).json();
const textBytes = (result: any) => new TextEncoder().encode((result.raw ?? result).content[0].text).length;

async function billingServer(plugins: any[] = []) {
  @App({
    id: "billing",
    name: "Billing and Support",
    tools: billingTools,
    skills: [AtRiskAccounts],
    jobs: [FindAtRiskAccounts, RemindOverdueCustomers, FlagUrgentTickets],
    workflows: [CollectionsRun],
    plugins,
  })
  class Billing {}
  return connect({ info: { name: "billing", version: "1.0.0" }, apps: [Billing] });
}

test("the client is listed CodeCall's six tools instead of the server's 13", async ({ mcp }) => {
  const listed = await mcp.tools.list();
  expect(listed.map((tool: { name: string }) => tool.name)).toEqual([
    "codecall:describe",
    "codecall:execute",
    "codecall:invoke",
    "codecall:search",
    "codecall:searchKnowledge",
    "codecall:searchSkills",
  ]);
  const plain = await billingServer();
  const everyTool = await plain.listTools();
  await plain.close();
  expect(everyTool.map((tool: { name: string }) => tool.name)).toEqual([
    "add_ticket_note",
    "cancel_job",
    "change_plan",
    "execute_job",
    "execute_workflow",
    "get_customer",
    "get_job_status",
    "get_manager",
    "get_workflow_status",
    "list_customers",
    "list_invoices",
    "list_tickets",
    "send_payment_reminder",
  ]);
  expect(new TextEncoder().encode(JSON.stringify(everyTool)).length).toBe(11328);
  expect(new TextEncoder().encode(JSON.stringify(listed)).length).toBe(18145);
});

test("the data: 600 customers, 2,400 invoices and 1,800 tickets, and the three lists the question needs", () => {
  expect([customers.length, invoices.length, tickets.length]).toEqual([600, 2400, 1800]);
  const enterprise = customers.filter((customer) => customer.plan === "enterprise");
  const overdue = invoices.filter((invoice) => invoice.status === "overdue");
  const urgent = tickets.filter((ticket) => ticket.status === "open" && ticket.priority === "high");
  expect([enterprise.length, overdue.length, urgent.length]).toEqual([165, 292, 241]);
  const countValues = (value: unknown): number =>
    Array.isArray(value)
      ? value.length + value.reduce((sum: number, item) => sum + countValues(item), 0)
      : value && typeof value === "object"
        ? Object.values(value).reduce((sum: number, item) => sum + 1 + countValues(item), 0)
        : 0;
  expect(countValues({ invoices: overdue })).toBe(5549);
});

test("one script answers the question, and only the answer comes back", async ({ mcp }) => {
  const result = await mcp.tools.call("codecall:execute", { script: atRiskScript });
  expect(result.json()).toEqual({ status: "ok", result: fiveAccounts });
  expect(textBytes(result)).toBe(484);
});

test("without CodeCall, the client receives the three lists: 138,680 bytes of text", async () => {
  const plain = await billingServer();
  const sizes = [];
  for (const [tool, input] of [
    ["list_customers", { plan: "enterprise" }],
    ["list_invoices", { status: "overdue" }],
    ["list_tickets", { status: "open", priority: "high" }],
  ] as const) {
    sizes.push(textBytes(await plain.callTool(tool, input)));
  }
  await plain.close();
  expect(sizes).toEqual([17598, 86106, 34976]);
});

test("with CodeCall's default limits, a script can't receive the 292 overdue invoices", async () => {
  const defaults = await billingServer([CodeCallPlugin.init({ mode: "codecall_only" })]);
  const script = 'const { invoices } = await callTool("list_invoices", { status: "overdue" });\nreturn invoices.length;';
  const outcome = (await defaults.callTool("codecall:execute", { script })).structuredContent;
  await defaults.close();
  expect(outcome).toMatchObject({ status: "runtime_error", error: { message: "Tool handler return value exceeds maximum properties (2000)." } });
});

test("a script that uses Set is refused before it runs, with the line and the name", async ({ mcp }) => {
  const script = `const { tickets } = await callTool("list_tickets", { status: "open", priority: "high" });\nconst urgent = new Set(tickets.map((ticket) => ticket.customerId));\nreturn urgent.size;`;
  const outcome = await callAndParse(mcp, "codecall:execute", { script });
  expect(outcome.status).toBe("illegal_access");
  expect(outcome.error.message).toContain('UNKNOWN_GLOBAL (line 2): Unknown identifier "__safe_Set"');
});

test("change_plan is out of reach: of a script, and of a direct call", async ({ mcp }) => {
  const outcome = await callAndParse(mcp, "codecall:execute", { script: 'return await callTool("change_plan", { customerId: "C-1", plan: "starter" });' });
  expect(outcome).toMatchObject({ status: "tool_error", error: { toolName: "change_plan", code: "ACCESS_DENIED" } });
  expect(await mcp.tools.call("change_plan", { customerId: "C-1", plan: "starter" })).toBeError("TOOL_NOT_FOUND");
});

test("the skill is found by codecall:searchSkills and served as SKILL.md", async ({ mcp }) => {
  const { skills } = await callAndParse(mcp, "codecall:searchSkills", { queries: ["enterprise accounts at risk"] });
  expect(skills.map((skill: { name: string }) => skill.name)).toEqual(["at-risk-accounts"]);
  const skill = await mcp.resources.read("skill://at-risk-accounts/SKILL.md");
  expect(skill.text()).toContain("Rank at-risk accounts by the total of their overdue invoices");
});

test("a script hands the follow-up to the collections-run workflow", async ({ mcp }) => {
  const script = `const run = await callTool("execute_workflow", { name: "collections-run" });\nconst steps = run.result.stepResults;\nreturn { state: run.state, accounts: steps.find.outputs.customerIds.length, reminders: steps.remind.outputs.reminded.length, flagged: steps.flag.outputs.flagged.length };`;
  const outcome = await callAndParse(mcp, "codecall:execute", { script });
  expect(outcome).toEqual({ status: "ok", result: { state: "completed", accounts: 17, reminders: 21, flagged: 17 } });
});
```

The only difference between the two servers in our runs is the `plugins` line in `billing.app.ts`. Without it, the same app lists its 13 tools: the eight above and the five tools FrontMCP adds for jobs and workflows.

<a id="code-mode-vs-codecall-four-setups-one-question"></a>

## Code Mode vs CodeCall: four setups, one question

We asked the question three times in each of four setups: Claude Code with Code Mode on and off, against the server with and without CodeCall. All twelve runs got the five accounts, their totals and their managers right. They got there in different ways.

*[Illustration: Code Mode: Claude sends REPL with a script to Claude Code. Claude Code calls list_customers, list_invoices and list_tickets on the billing server, which lists 13 tools, and gets back the three lists, 138,680 bytes. The script joins and sorts them in Claude Code, calls get_manager three times and gets three managers, and Claude gets the five accounts.]*

- **Plain tool calls**, Code Mode off and no CodeCall. Claude called the three list tools and `get_manager` directly. The customer and ticket lists went into its context. The invoice list was too big to show it, so Claude Code saved it to a file, and Claude joined it with `jq` in the shell, typing the enterprise customers' ids into the command. It never read the server's skill.
- **Code Mode.** Claude read the server's skill, fetched the three lists in parallel in one script and kept them in the REPL's variables. Before joining them, it printed a preview of each, up to 4 KB of raw records in all, to learn their shape. A second script joined them, with a `Set`, and looked up the managers.
- **CodeCall.** Claude read the skill, searched and described the four tools, whose output schemas came back with them, and sent a script to `codecall:execute`. In every run, that first script used `Set`. AgentScript doesn't have it, so CodeCall refused the script before it ran, and Claude sent it again with a plain object. The lists never left the server.

*[Illustration: CodeCall: Claude sends codecall:execute with a script to its MCP client, which sends tools/call codecall:execute to the billing server, which lists CodeCall's 6 tools. The script is checked as AgentScript and run in Enclave, and the three lists, 138,680 bytes, are read on the server. The server sends back the five accounts, 484 bytes, and Claude gets the five accounts.]*

| Median of 3 runs (range) | Plain tool calls | Code Mode | CodeCall | Code Mode and CodeCall |
| --- | --- | --- | --- | --- |
| Correct answers | 3 of 3 | 3 of 3 | 3 of 3 | 3 of 3 |
| Seconds from prompt to answer | 36.2 (28.1–44.9) | 24.2 (24.2–26.4) | 26.8 (21.6–34.9) | 23.7 (20.4–24.4) |
| Model requests | 7 (6–7) | 6 (6–7) | 6 (6–8) | 6 |
| Tokens the question added to the context | 29,490 (28,743–30,152) | 8,627 (8,169–12,044) | 9,669 (9,330–9,696) | 8,695 (7,986–10,931) |
| Input tokens, all requests | 394,557 | 166,485 | 275,929 | 167,575 |
| Output tokens | 3,449 | 2,171 | 2,144 | 2,191 |
| Tool calls the server received | 6 | 6 | 4 (4–5) | 4 (3–4) |
| Bytes the server sent back for them | 302,106 | 302,107 | 21,022 (19,266–21,026) | 19,954 (17,536–22,699) |

What the numbers say:

- **Code Mode and CodeCall do the same job.** Next to plain tool calls, each cut what the question added to Claude's context by two thirds or more, from 29,490 tokens to under 10,000, and each answered faster. Without Code Mode, putting CodeCall on the server took Claude Code from 36.2 seconds to 26.8, and from 29,490 tokens added to its context to 9,669.
- **In Claude Code, Code Mode was a little faster.** Its prompt is smaller: the first request of a Code Mode session was 23,127 tokens, against 40,444 without it, because Claude Code's tools are functions inside one `REPL` tool instead of separate tool definitions. Every request pays for that difference, which is most of the gap in the "all requests" row. It's Claude Code's prompt, not the server's.
- **Only CodeCall kept the data on the server.** In both setups without it, the server sent all three lists to Claude Code for every question: 302 KB, each result once as text and once as `structuredContent`. With CodeCall it sent about 20 KB: `codecall:search` (5 KB) and `codecall:describe` (10.7 KB), which a conversation needs once, the refused script's error and the answer.
- **CodeCall's one extra request was the `Set` refusal.** It cost every CodeCall run a request and about 1.8 KB, and it's fixable on FrontMCP's side ([below](https://frontmcp.dev/blog/claude-code-code-mode-vs-codecall#what-codecall-refused)).

Code Mode exists only in Claude Code's terminal. Most clients call a server's tools one at a time, as in the first column. CodeCall is how a server gets the third column's numbers in any of them, without waiting for each client to build a code mode of its own.

<a id="more-accurate-the-server-knows-what-at-risk-means"></a>

## More accurate: the server knows what "at risk" means

The first question spelled out its rule. Real questions often don't. So we asked a vaguer one: *"Which five of our enterprise accounts are most at risk right now, and who manages each one?"* Nothing in the tools says what "at risk" means at this company. A model can write the join; it can't know the rule unless someone tells it, and a client-side mode has nobody to ask.

The server can tell it. `collections.ts` declares a [skill](https://frontmcp.dev/reference/sdk/skill), `at-risk-accounts`: a description, the four tools it uses, and instructions that define an account at risk and say how to rank them. FrontMCP serves it as an MCP resource, `skill://at-risk-accounts/SKILL.md`, listed in `skill://index.json`, and through `codecall:searchSkills`. The Playground's tests read it both ways.

We asked the vague question against the server with and without the skill, twice each:

| "Most at risk", 2 runs each | Skill on the server | Runs that named the company's five | Median seconds |
| --- | --- | --- | --- |
| Plain tool calls | No | 0 of 2 | 34.6 |
| Code Mode | No | 0 of 2 | 26.3 |
| Code Mode | Yes | 2 of 2 | 25.4 |
| CodeCall | Yes | 2 of 2 | 23.7 |

Without the skill, Claude said what it was doing and chose its own rule: *"The billing server has no risk score, so I ranked accounts by how much money is overdue."* All four runs without the skill, with Code Mode and without, returned the same five: the five largest overdue balances. Only two of them are at risk by the company's rule. Fernwood Labs, Lumen Studio and Northwind Software have no urgent ticket open, and Northwind Pharma, Brightwater Foods and Meridian Robotics, which do, were missing. With the skill, in every run, Claude read `skill://index.json` before it touched any data, without being asked, and said where its rule came from: *I used the billing server's own "at-risk-accounts" rule.*

Code Mode read the same skill as a plain MCP resource, without CodeCall. That's the point of putting it on the server: the definition lives next to the data, and every client that connects gets it.

<a id="when-the-work-outlives-a-script"></a>

## When the work outlives a script

A script is for one question. Sending reminders to every at-risk account each morning, retrying the ones that fail, and noting it on their tickets is a process, and a terminal session is the wrong place for it: Code Mode stops a script you wait on after ten minutes, or two hours in the background, and it runs only in someone's Claude Code session.

FrontMCP has jobs and workflows for that. `collections.ts` declares three [jobs](https://frontmcp.dev/reference/sdk/job), `find-at-risk-accounts`, `remind-overdue-customers` (with three attempts) and `flag-urgent-tickets`, and a [workflow](https://frontmcp.dev/reference/sdk/workflow), `collections-run`, that runs the first and then the other two in parallel, each step's input built from the first step's result. FrontMCP adds `execute_workflow` and the other job tools to the server by itself. CodeCall hides them from `tools/list` like every other tool, and a script can call them:

**Reuses runnable project: billing.**

Initial call configuration:

```js
{ tool: "codecall:execute", arguments: { script: [
'const run = await callTool("execute_workflow", { name: "collections-run" });',
'const steps = run.result.stepResults;',
'return {',
'  state: run.state,',
'  accounts: steps.find.outputs.customerIds.length,',
'  reminders: steps.remind.outputs.reminded.length,',
'  flagged: steps.flag.outputs.flagged.length,',
'};',
].join("\n") } }
```



The run found 17 at-risk accounts, sent 21 reminders and flagged 17 tickets, all on the server. Pass `background: true` and the call returns a `runId` at once, which a signed-in caller polls with `get_workflow_status`. Add `trigger: "schedule"` with a cron expression and the workflow runs [on a schedule](https://frontmcp.dev/reference/sdk/workflow#running-on-a-schedule), with no model and no client connected. A script that worked once becomes the server's own process.

<a id="what-codecall-refused"></a>

## What CodeCall refused

CodeCall's checks are on the server, so they hold whatever the client is and whatever the user allowed. Three of them came up:

- **`Set`, in every CodeCall run.** AgentScript has no `Set`, `Map`, `RegExp` or `Promise`, and `codecall:execute`'s description doesn't say so: its `BLOCKED:` line names loops, `eval` and `fetch`. Claude reached for `Set` each time, got `illegal_access` with the line and the name, and rewrote the script. Nothing had run. Listing the missing globals in the description would save that request, and we've [filed it with FrontMCP](https://github.com/agentfront/frontmcp/issues/1329). The **Call** tab below sends such a script:

**Reuses runnable project: billing.**

Initial call configuration:

```js
{ tool: "codecall:execute", arguments: { script: [
'const { tickets } = await callTool("list_tickets", { status: "open", priority: "high" });',
'const urgent = new Set(tickets.map((ticket) => ticket.customerId));',
'return urgent.size;',
].join("\n") } }
```



- **The size of a tool's result.** Under CodeCall's default `secure` preset, a script may receive at most 2,000 values from a tool, counting every array item and object key. The 292 overdue invoices, with their lines, hold 5,549, so the script ended with `Tool handler return value exceeds maximum properties (2000).` That's why `billing.app.ts` sets `vm: { maxSanitizeProperties: 10_000 }`. The error doesn't name the tool, and the option's description doesn't say it counts tool results, so we [filed that too](https://github.com/agentfront/frontmcp/issues/1330). A test in the Playground keeps the default and shows the error.
- **`change_plan`, from a script and from a client.** `includeTools` keeps destructive tools away from CodeCall, so a script that calls `change_plan` gets `ACCESS_DENIED`, and a client that calls it by name gets `Tool "change_plan" not found`. In the Code Mode runs, `change_plan` was one of the 13 tools the server listed, and our `mcp__billing` permission rule allowed all of them: there, what a script may call is the user's setting, and the server can't tell a script's call from anyone else's.

<a id="pros-and-cons"></a>

## Pros and cons

| | Code Mode in Claude Code | CodeCall in a FrontMCP server |
| --- | --- | --- |
| Where the script runs | In Claude Code, on the user's machine | In the MCP server, in Enclave |
| Clients | Claude Code 2.1.323 or later, interactive, in a terminal | Any MCP client |
| Models | Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2, on the Anthropic API | Any model that can call a tool |
| What a script can reach | Claude Code's tools, your files and shell, and every connected MCP server | The tools of one server that CodeCall may use |
| Language | JavaScript | AgentScript: no `Set`, `Map`, `RegExp`, `while` or `fetch` |
| Who decides what a script may call | The user: permission rules and hooks | The server: `includeTools`, authorities, the sandbox's limits |
| What's checked before a script runs | In auto mode, a classifier reads the script; it doesn't see values computed at run time | Enclave refuses anything outside AgentScript; each call's real arguments then go through the server's rules |
| Variables between scripts | Kept: in our runs, a second script joined lists the first had fetched | None: each script starts fresh |
| Where the data goes | Every tool result goes to the client: 302 KB a question here | Only what the script returns: 484 bytes, after about 16 KB of discovery |
| How long a script may run | 10 minutes, or 2 hours in the background | 3.5 seconds by default; jobs and workflows for longer work |
| What it takes | An environment variable | A plugin on the server |
| Status | Experimental | Released |

**Code Mode's strengths:** it needs nothing from the server, so it works with every MCP server today. One script can mix your shell, your files and several servers. It runs real JavaScript: no Code Mode script failed in our runs. Its variables stay between scripts, so Claude can look at a result before it decides what to do with it. And in Claude Code, the two setups with Code Mode on were the fastest we ran, about 24 seconds.

**Its limits:** only Claude Code's terminal, on the Anthropic API, with four models, and it's experimental. Every tool result travels to the user's machine. The user's permission rules decide what a script may call, so the server's owner has no say.

**CodeCall's strengths:** one server change serves every client and every model. The data stays on the server, and the server decides what a script may call, with the same authorities and hooks as any call. `codecall:describe` gives the model each tool's output schema: in our runs, Claude wrote its script from those and never looked at raw records. And it comes with the rest of FrontMCP: skills and workflows.

**Its limits:** AgentScript is a subset, and Claude tripped on it in every run. The default limits are small for big lists. A script reaches one server's tools, and each script starts fresh: a second one can't reuse what the first fetched. And the six meta-tools are a fixed cost: 18,145 bytes in `tools/list`, more than this server's own 13 tools (11,328 bytes). On a server with a handful of small tools, a plain `tools/list` is cheaper.

<a id="use-both"></a>

## Use both

They don't compete for the same spot. With Code Mode on and CodeCall on the server, Claude called `codecall:search`, `codecall:describe` and `codecall:execute` from its REPL, like any other MCP tool. That setup matched Code Mode on its own, 23.7 seconds and 8,695 tokens added to the context, while the server sent 19,954 bytes instead of 302,107. Code Mode kept Claude Code's side lean, and CodeCall kept the lists on the server.

<a id="setting-it-up"></a>

## Setting it up

Everything in this post is in one `@App`: the tools, the skill, the jobs, the workflow and the plugin. FrontMCP serves the skill, adds the job and workflow tools, and wires CodeCall to all of them:

```bash
npm install @frontmcp/sdk@1.12.2 @frontmcp/plugin-codecall@1.12.2
```

```ts billing.app.ts
@App({
  id: "billing",
  name: "Billing and Support",
  tools: billingTools,
  skills: [AtRiskAccounts],
  jobs: [FindAtRiskAccounts, RemindOverdueCustomers, FlagUrgentTickets],
  workflows: [CollectionsRun],
  plugins: [
    CodeCallPlugin.init({
      mode: "codecall_only",
      includeTools: (tool) => !tool.annotations?.destructiveHint,
      vm: { maxSanitizeProperties: 10_000 },
    }),
  ],
})
export class BillingApp {}
```

To hand it to Claude Code users with its skills, build it as a program with [`frontmcp build --target cli`](https://frontmcp.dev/reference/cli#the-cli-target). Its `install -p claude` command writes a Claude Code plugin with the server entry and each skill as a `SKILL.md`, and `install -p codex` does the same for Codex. Over HTTP, any client connects to it as to any MCP server.

<a id="what-we-measured-and-what-we-didnt"></a>

## What we measured, and what we didn't

- **The runs.** November 19, 2026, on one Apple-silicon MacBook running macOS 26.6.2 and Node 24.22.1: FrontMCP 1.12.2, `@frontmcp/plugin-codecall` 1.12.2 and Enclave 2.19.2; Claude Code 2.1.328, native build, with Claude Opus 5.5 (`--model opus`). Three runs of each setup for the first question, two for the "at risk" question.
- **Each run** was a new interactive session in an empty folder, started with `--strict-mcp-config` and only the billing server, over HTTP on the same machine, with `--setting-sources project,local` so no plugins or hooks of ours loaded, and `--allowedTools mcp__billing`. Sessions started in auto mode. A small program typed the prompt and waited for the answer in the session's transcript.
- **What we counted.** Model requests and tokens come from the transcript's `usage` fields. "Tokens the question added" is the input of the last request minus the input of the first. Seconds run from the prompt to the answer, as the transcript records them. Bytes are response bodies, counted by a proxy between Claude Code and the server. A correct answer names the five accounts in order, with their totals and their managers' emails. Every run's numbers are in [the JSON record](https://frontmcp.dev/evidence/code-mode-vs-codecall.json).
- **What we didn't.** Cost; other models and clients; a server across a network, where every extra round trip would add latency (all four setups talked to `localhost`); runs at scale. Three runs show the spread, not a distribution. The data and the question are ours, chosen to need a join, and a hypothetical company's.
- **What's checked on every build.** Every number that comes from the server, the 138,680 bytes, the 484-byte answer, both catalogs, the refusals and the workflow, is pinned by the Playground's tests, in Node and in the browser. The model runs are a record of one day, and a later Claude Code, model or FrontMCP release can change them.

<a id="try-it"></a>

## Try it

The server above runs on this page: edit a tool or the script in the [Playground](https://frontmcp.dev/playground) and the tests show what changed. [Letting the Model Write Code with CodeCall](https://frontmcp.dev/learn/letting-the-model-write-code-with-codecall) teaches CodeCall step by step, [Teaching the Model Skills](https://frontmcp.dev/learn/teaching-the-model-skills) covers skills, and [Chaining Jobs into Workflows](https://frontmcp.dev/learn/chaining-jobs-into-workflows) covers workflows. If you use Claude Code, turn on Code Mode too: they work together.
