EXPLAINER18 min read

Claude Code Mode: Move Beyond Brittle Tool Calls

A practical guide to using Claude Code Mode to run tool workflows in code, reduce repeated model turns and keep noisy results out of context.

P
PADISO teamPublished 2 Dec 2026

Claude Code Mode lets Claude write a program that runs several tool operations, filters their results and returns a compact answer, rather than asking the model to plan and narrate every operation in a separate turn. For engineering leaders, the useful distinction is not that code replaces tools, but that code takes over some of the orchestration between tools. It can reduce repeated model calls and context clutter, but it also changes where execution happens and what your controls need to inspect. Claude Code Mode’s documentation and PADISO’s guide to AI agents and automation are useful starting points for understanding the design and the broader production considerations.

What does Claude Code Mode change?

A tool is an action an AI system can request, such as reading a file, searching a repository or querying a service. A tool call is the structured request to perform that action. In a traditional tool loop, the model asks for one action, waits for the result, reads it and then decides what to do next.

Claude Code Mode changes that sequence. Instead of asking the model to issue each low-level action as a separate turn, it can generate a JavaScript program to perform a series of operations. The program can call tools, make decisions, process results and return only the information the model needs to continue.

That is programmatic orchestration: using ordinary code to control the order of operations and handle intermediate data. It is different from asking a model to produce a single tool-call object for each step. In a conventional loop, the orchestrator may send every raw result back into the model’s message history. In code mode, the program can keep intermediate results in its runtime and return a small, prepared result instead.

A simple example makes the difference clearer. Suppose a coding assistant needs to find every use of a deprecated function, read the relevant files, update the calls and run a test.

In a classic loop, the model may ask to search for the function, inspect the output, open a file, inspect that output, open the next file, and continue. It may then ask to edit files and run a test. Each response returns to the model, which has to interpret it before asking for another action.

With programmatic execution, Claude can write a script that searches for matches, reads selected files, extracts the relevant lines, applies a defined change and runs a check. The script can report a concise summary and any errors. Claude still makes decisions, but it does not need to reason over every intermediate line as a separate conversation turn.

The key idea is straightforward: let the model decide what work is needed, then let code handle repeatable mechanics and data processing. Keep the model in the loop where judgement matters. Keep verbose intermediate results out of its context unless they affect the decision.

What happens in a traditional tool loop?

A model does not normally reach into a developer’s computer or a company database by itself. The application gives it a set of tools, such as a search function or an API operation. The model selects a tool and supplies arguments. An orchestrator, which is the software coordinating the model and tools, executes the request and sends the result back.

The usual sequence is:

  1. The application sends the prompt and available tool descriptions to the model.
  2. The model returns a request to use a tool.
  3. The orchestrator runs that tool and receives its result.
  4. The application adds the result to the conversation and calls the model again.
  5. The model decides whether it needs another tool or can answer.

This approach is useful. It is explicit, easy to understand and can give an application a chance to check each requested action. A model can adapt when a result is unexpected. For a small task with one or two actions, this may be the clearest design.

The trouble starts when a task involves many dependent or repetitive actions. Each round trip adds time: the model has to start processing, generate a tool request, wait for the application to run it and then interpret the reply. A round trip is the full exchange between the application and the model, including the tool execution in the middle.

It also adds context. Context is the information the model receives to make its next decision. If the tool returns a long list of files, a large API response or verbose test output, the application may include that content in the next request. The model then has to process it again when it takes the next step.

This can produce an orientation tax: time and tokens spent rediscovering what is in a repository or service before the actual work begins. Tokens are the small text units models process and are commonly used to measure model input and output. Repeated context can increase usage even when the model has not learned anything new from the repeated material.

There is a second cost beyond tokens. Large, noisy results can obscure the small piece of information that matters. If a task starts with a constraint, then several long outputs arrive, the model has more material to keep track of while it reasons. This is one reason tool-heavy workflows can feel brittle: small changes in output length or format can affect the next decision.

How does Claude Code Mode work in practice?

The phrase can refer to related but distinct implementations. Claude Code’s experimental Code Mode is a capability in the Claude Code terminal application. Programmatic Tool Calling, or PTC, is the corresponding platform pattern for applications built with the Claude Messages API. They share the principle of using code to orchestrate tools, but they are not the same product or runtime.

Claude Code in the terminal

In the Claude Code terminal experience, Claude can generate JavaScript to run in a local execution environment. Rather than requesting every file inspection or shell operation as a separate model action, it can put several steps into a script and return a condensed result. You can inspect generated scripts during an interactive session using the mechanism documented by Anthropic.

The feature is experimental and disabled by default according to the Claude Code Mode documentation. The Claude Code changelog records its release history. That matters for teams because experimental features can change, have narrower support or require a deliberate rollout. Check the current documentation for supported versions, interfaces and configuration before making a team standard.

The local execution detail is important. A script running in a developer’s terminal is not the same thing as code running in a remote, isolated service. Depending on its permissions and runtime, local code may be able to interact with files and network services accessible to that user. A model-generated script should therefore be treated as executable code, not as harmless prose.

Programmatic Tool Calling through the API

In an application built with the Claude API, PTC lets Claude write code that calls approved tools within an execution environment. The developer defines the tools and which callers may use them. The code can coordinate multiple calls and process their results before returning an answer. Anthropic describes the implementation in its Programmatic Tool Calling documentation and Code Execution Tool documentation.

This pattern is useful when you own an application that needs to expose services, databases or internal APIs to a model. It does not mean the model gets unrestricted access to every API. You still decide which operations exist, how credentials are held, what data can be returned and what actions need approval.

Design choice Traditional tool loop Programmatic execution
Who coordinates steps? The model requests actions one at a time, with the application running each one A generated program can coordinate multiple approved operations
What enters model context? Often each tool result, including intermediate output The program can filter and summarise intermediate output first
Best fit Short, simple workflows or actions where each step needs a separate check Repetitive, multi-step work with useful filtering or aggregation
Main trade-off More model round trips and potentially more repeated context More execution complexity and a need to review code-level permissions
What to monitor Model calls, tool results, errors and total task time Script execution, tool access, returned data, errors and total task time

The table describes patterns, not a rule that one approach always wins. A programmatic workflow can still call the model again when it reaches a decision that needs judgement. The goal is to avoid a model round trip for each mechanical action, not to remove the model from decisions altogether.

Why can programmatic execution cut latency and token use?

A long chain of sequential model turns creates a latency floor. If every step waits for a new inference, then the total wait is the sum of those exchanges, plus the time required to run tools. Programmatic execution can combine several mechanical operations into a single execution interval. It may also run independent operations in parallel, meaning at the same time, when it is safe to do so.

For example, imagine a support assistant that needs to look up a customer’s recent orders, check delivery status and retrieve the current refund policy. If the three lookups are independent, code can request them together, select the fields that matter and return a short summary. A multi-turn design might ask for one lookup, wait, ask for the next and then bring all three results into context.

The benefit depends on the task. If each lookup depends on the previous answer, there may be less opportunity to run them together. If the model needs to interpret every result before deciding the next action, separate turns may be justified. Programmatic execution is most useful when the sequence is predictable enough to encode, or when the model can write a small program to handle the branching.

The token effect comes from reducing repeated and irrelevant content. If a program reads a large response but keeps only five fields, only those fields need to return to the model. If it aggregates many records into a total and a short list of exceptions, the model can reason over that summary instead of every record.

Anthropic’s November 2025 engineering article, Code Execution with MCP: Building More Efficient Agents, reported a reduction from 150,000 tokens to 2,000 tokens in its described example when code loaded tools and filtered payloads. That is a result for a particular workflow, not a guaranteed saving for every system. The practical lesson is to measure how much of your current context consists of intermediate data that code could safely summarise.

Cloudflare described a related design in its Code Mode article, where an agent works through a small search-and-execute interface rather than receiving a very large set of API tool descriptions upfront. Its later article, Give Agents an Entire API in 1,000 Tokens, explains the motivation for putting a code layer between a model and a broad API. These are examples of an architectural pattern, not independent proof that every code-based agent will perform better.

The saving is not automatically a lower bill. A shorter conversation can mean fewer input tokens and fewer repeated model calls, but a script also takes time to generate and execute. If you use a more expensive model, make unnecessary calls or return a large result anyway, the total cost may not improve. Measure cost per completed task, not just tokens in one response.

MCP, the Model Context Protocol, is a standard way for AI applications to connect to external tools and data sources. An MCP server exposes capabilities, such as searching documents or retrieving a record. A client connects to the server and makes requests using the agreed protocol.

Code Mode does not replace MCP. It can sit above an MCP connection as an execution layer. Rather than showing the model a long list of individual operations and asking it to call each one directly, an application can provide a way for code to use the MCP client. The generated program can then make several MCP requests and filter the results.

Think of MCP as the connection and tool interface, and programmatic execution as one way to coordinate work through that interface. They solve different problems. MCP helps services expose capabilities in a consistent form. Code execution can reduce the amount of tool detail and intermediate data the model has to handle directly.

This distinction matters when planning an integration. If your MCP server exposes poorly defined operations, code mode will not make them safe or reliable. If the server returns huge payloads, code can filter them, but you still need to understand what data it receives. If a tool’s side effects are unclear, putting it behind generated code does not remove the risk.

For teams designing internal tool interfaces, start with the underlying operations. Make each operation narrow, name it clearly, validate its inputs and return only the data needed for the task. Then decide whether the model should call the operation directly or whether a code layer should coordinate several operations. PADISO’s MCP server development service focuses on designing and building those connections, while platform engineering can address the architecture around them.

When should you use it, and when should you stay with direct tool calls?

Use programmatic execution when a task has several predictable operations, repeated data handling or large outputs that can be reduced before the model sees them. Good candidates include searching many files and extracting matching sections, aggregating records from multiple services, comparing data across sources, or running a series of checks that can be expressed as code.

Direct tool calls are often better when the task is small, when each action needs a distinct human approval, or when the next step depends on interpretation of the previous result. They are also easier to reason about during early prototyping. A single file edit in a file the model has already identified may not benefit from writing and running an orchestration script.

A useful decision test is to ask four questions:

  1. How many model turns are doing mechanical work? If a task repeatedly asks the model to list, read, filter and combine data, there may be work for code to handle.
  2. How much of each result is useful? If most returned data is discarded, filter it before it reaches the model.
  3. Can the sequence be expressed and checked? If a script can validate its inputs and outputs, programmatic execution may be appropriate. If the model must make a judgement after every result, keep those decision points explicit.
  4. What can the script affect? A read-only search is different from sending a payment, changing a production record or pushing code. The more consequential the action, the stronger the controls should be.
Task pattern Likely starting point Reason
One well-understood lookup Direct tool call A code layer can add overhead without removing meaningful repetition
Search many files, then return only relevant excerpts Programmatic execution Code can filter repetitive output before it reaches context
Read several independent records and calculate a summary Programmatic execution, with validation Code can fetch and aggregate data; the model can explain exceptions
Decide whether a contract clause creates a legal risk Direct model reasoning with carefully selected evidence The core work is interpretation, not mechanical orchestration
Make an irreversible change to a customer account Explicit approval workflow A faster execution path must not bypass the business control
Explore an unfamiliar API with unclear behaviour Begin with narrow direct calls Learn the interface before automating a larger sequence

These are starting points, not fixed rules. Many production designs combine both approaches. Code handles predictable retrieval and preparation. The model makes a decision. A separate permission check or human approval governs a consequential action.

How should engineering teams adopt it safely?

Treat the execution boundary as a first-class design choice. An execution boundary is the point at which generated code is allowed to interact with tools, files, networks or business systems. Be explicit about what crosses that boundary and who can approve it.

1. Start with a read-only, measurable workflow

Pick a task that is currently slow or noisy, but does not make an irreversible change. Repository search, document retrieval or read-only reporting are good places to begin. Record the current task’s completion time, model calls, input and output tokens, tool errors and the amount of raw data passed back to the model.

Keep the task and test data consistent when comparing designs. A benchmark that uses different prompts, records or repository states can make the result misleading. Include failed attempts and retries, not only successful runs. A workflow that is cheaper when it succeeds but fails more often may be worse overall.

2. Define what the program may do

Give a script access only to the operations required for its job. Separate read operations from write operations. Restrict access to sensitive records and avoid placing long-lived credentials in generated code or model-visible output. For API applications, hold credentials in the application or the approved execution environment and expose narrow tool functions rather than broad administrative access.

For terminal use, check what local files and network resources the execution environment can reach. If the machine holds sensitive source code or credentials, consider running the tool inside a managed, isolated development environment. Isolation means restricting the process so that a mistake or malicious instruction has a smaller area in which to cause harm.

3. Validate inputs and outputs

Treat both model-generated code and tool results as untrusted inputs. Validate the arguments passed to tools. Check that returned values have the expected shape and handle missing, malformed or unusually large results. Set limits on loops, result sizes and execution time. A script should stop safely rather than continue indefinitely or process an unexpected volume of data.

For write actions, use a separate approval step. The program can prepare a proposed change, show a summary and wait for a person or policy engine to authorise it. Do not assume that a generated script is safe because it was produced by a capable model or because it looks readable.

4. Inspect permissions and hooks

Tool permissions need to match the new execution pattern. A policy that checks for one exact shell command may not catch a compound command assembled inside a script. Review how your environment evaluates generated code, and use explicit allow, ask and deny rules for sensitive operations. Where the environment supports hooks, use them to inspect or block actions at the execution boundary.

Anthropic’s Claude Code Mode documentation describes the current controls and configuration. Teams should verify the behaviour against their deployed version rather than relying on assumptions from an older guide. In particular, confirm whether controls evaluate each underlying tool call, the generated script as a whole, or both.

5. Log actions without logging everything

You need enough evidence to understand what happened: the task identity, tools invoked, permissions applied, execution status, errors and the summary returned. Avoid indiscriminately logging sensitive payloads. A useful log records the decision trail and outcome while minimising unnecessary personal or confidential data.

Observability means being able to see how a system behaves after deployment. For agent workflows, that includes more than the final answer. Track how often scripts fail, how often they retry, whether they exceed time limits, which tools they call and how much data they return. This helps distinguish a model problem from a tool, permission or runtime problem.

6. Compare outcomes, not just token counts

A practical evaluation should cover four dimensions:

  • Quality: Did the workflow reach the correct result and respect the user’s constraints?
  • Latency: How long did the complete task take, including tools, retries and approvals?
  • Cost: What did the full task consume in model and execution resources?
  • Risk: Did it access only permitted data and avoid unauthorised side effects?

Run both the existing tool loop and the programmatic version against the same representative tasks. Include ordinary cases, edge cases and failures. Keep a human review step for high-impact decisions until you have evidence that the controls and evaluations are adequate.

This is where AI strategy and solutioning connects to implementation. A use case should be assessed for value, data readiness, risk and operational ownership before a team optimises its execution pattern. The goal is not to use code mode everywhere. It is to choose the simplest design that meets the task’s quality, cost and control requirements.

What changes for regulated and sensitive workloads?

In regulated organisations, reducing tool calls is not a sufficient reason to change an execution architecture. You need to know where code runs, what data it can read, where outputs are stored, who can see logs and how access is revoked.

For Australian financial services and insurance teams, assess the design against the organisation’s existing obligations and control framework. APRA-regulated entities should consider how the system fits their information security and operational risk arrangements, including relevant requirements under CPS 234 and CPS 230. Privacy controls should also address the collection, use, disclosure and retention of personal information under the Privacy Act. The precise obligations depend on the organisation and use case, so technical teams should involve their risk, privacy and legal owners.

There is a practical difference between a local terminal runtime and a hosted code execution service. With local execution, the developer’s environment and its permissions matter. With a hosted runtime, the provider’s execution and data handling terms matter. Review the current service documentation for retention, data location, isolation and compliance before sending sensitive information. Do not infer that a managed execution container is automatically suitable for every regulated workload.

Build a short control checklist before a pilot:

  • What data may the model and generated code access?
  • Which operations are read-only, and which can change business state?
  • Where does code run, and what network or file access does it have?
  • What is retained by the application, model provider and execution environment?
  • How are approvals, tool calls, errors and outcomes recorded?
  • How can access be stopped quickly if a tool or credential is compromised?
  • Who owns the workflow after the pilot, including incident response and ongoing evaluation?

For financial services and insurance use cases, PADISO’s work on AI for financial services and AI for insurance provides relevant context for connecting AI designs with industry controls.

What should you measure in a pilot?

Measure the task from the user’s request to a verified result. Token count is useful, but it is only one part of the story. An agent that produces an answer quickly but misses a required check has not improved the workflow.

A small pilot can use a baseline and a comparison table like this:

Measure What to record Why it matters
Model turns Number of model requests for a completed task Shows whether orchestration reduced back-and-forth
Tokens Input and output tokens across the whole task Shows whether repeated context or large results fell
End-to-end time Start of request to verified completion Captures model, tool, runtime and approval delays
Task success Whether the final result meets a defined test Prevents efficiency gains from hiding quality loss
Tool failure rate Failed, timed-out or invalid tool operations Reveals reliability issues outside the model
Data returned Size and sensitivity of data passed to the model Helps assess context use and privacy exposure
Human intervention Where a person had to correct or approve the workflow Shows whether the system fits the operating process

Set the success criteria before running the comparison. For example, a code-review assistant might need to identify all relevant references, avoid editing unrelated files and report test failures accurately. A finance workflow might need to reconcile specified records and flag exceptions without changing source data. The criteria should reflect the business task, not merely whether the script ran.

If results improve, expand carefully. Add new tool permissions one at a time, keep the same evaluation discipline and make the owner of the workflow clear. If results do not improve, check whether the task is too simple, the script adds overhead, the tools are poorly designed or the model still needs to see more context to make a sound decision.

Where PADISO fits

PADISO helps teams assess agent workflows, design tool and execution boundaries, and move useful automations from prototype into production. Our AI agents and automation service can help review a candidate workflow, its controls and how to evaluate it; the first step is to map the task and its current failure, latency and cost points.

The next step

Pick one tool-heavy workflow that is currently slow or returns more data than the model needs. Measure its baseline, identify what code could safely filter or combine, then compare a controlled programmatic version against the existing design. If you want an independent view of the use case and its readiness, start with the PADISO AI readiness test.

WANT TO TALK THROUGH YOUR SITUATION?

Talk it through with us. Thirty minutes, no slides.

P
Written by the PADISO TeamSydney-based technology leaders who build what they advise on. Seven years of fractional CTO, architecture and AI work for enterprise, government and private equity.

Keep reading

All posts →

Let's talk.

Tell us what you are weighing up, whether it is a build, a roadmap or a deal. You will leave the call knowing your next step.

Book a 30-min callhi@padiso.co