$git clone https://github.com/universal-tool-calling-protocol/code-mode> Transform your AI agents from clunky tool callers into efficient code executors — in just 3 lines.
| 1 | <div align="center"> |
| 2 | <!-- <img alt="utcp code mode banner" src="https://github.com/user-attachments/assets/77723130-ecbc-4d1d-9e9b-20f978882699" width="80%" style="margin: 20px auto;"> --> |
| 3 | |
| 4 | <h1 align="center">🤖 Code-Mode Library: First library for tool calls via code execution</h1> |
| 5 | <p align="center"> |
| 6 | <a href="https://github.com/universal-tool-calling-protocol"> |
| 7 | <img src="https://img.shields.io/github/followers/universal-tool-calling-protocol?label=Follow%20Org&logo=github" /></a> |
| 8 | <a href="https://img.shields.io/npm/dt/@utcp/code-mode" title="PyPI Version"> |
| 9 | <img src="https://img.shields.io/npm/dt/@utcp/code-mode"/></a> |
| 10 | <a href="https://github.com/universal-tool-calling-protocol/code-mode/blob/main/LICENSE" alt="License"> |
| 11 | <img src="https://img.shields.io/github/license/universal-tool-calling-protocol/code-mode" /></a> |
| 12 | |
| 13 | [](https://www.npmjs.com/package/@utcp/code-mode) |
| 14 | </p> |
| 15 | </div> |
| 16 | |
| 17 | > Transform your AI agents from clunky tool callers into efficient code executors — in just 3 lines. |
| 18 | |
| 19 | ## Why This Changes Everything |
| 20 | |
| 21 | LLMs excel at writing code but struggle with tool calls. Instead of exposing hundreds of tools directly, give them ONE tool that executes TypeScript code with access to your entire toolkit. |
| 22 | |
| 23 | [Apple](https://machinelearning.apple.com/research/codeact), [Cloudflare](https://blog.cloudflare.com/code-mode/), and [Anthropic](https://www.anthropic.com/engineering/code-execution-with-mcp) say that Code-Mode is a more efficient way to approach tool calling compared to the traditional dump function information and then extract a JSON for function calling. |
| 24 | |
| 25 | ## Benchmarks |
| 26 | |
| 27 | Independent [Python benchmark study](https://github.com/imran31415/codemode_python_benchmark) validates the performance claims with **$9,536/year cost savings** at 1,000 scenarios/day: |
| 28 | |
| 29 | | Scenario Complexity | Traditional | Code Mode | **Improvement** | |
| 30 | |---------------------|-------------|-----------|----------------| |
| 31 | | **Simple (2-3 tools)** | 3 iterations | 1 execution | **67% faster** | |
| 32 | | **Medium (4-7 tools)** | 8 iterations | 1 execution | **75% faster** | |
| 33 | | **Complex (8+ tools)** | 16 iterations | 1 execution | **88% faster** | |
| 34 | |
| 35 | ### **Why Code Mode Dominates:** |
| 36 | |
| 37 | **Batching Advantage** - Single code block replaces multiple API calls |
| 38 | **Cognitive Efficiency** - LLMs excel at code generation vs. tool orchestration |
| 39 | **Computational Efficiency** - No context re-processing between operations |
| 40 | |
| 41 | # Getting Started |
| 42 | |
| 43 | [<img width="2606" height="1445" alt="Frame 4 (4)" src="https://github.com/user-attachments/assets/58ba26ab-6e77-459b-a59a-eeb60d711746" /> |
| 44 | ](https://www.youtube.com/watch?v=zsMjkPzmqhA) |
| 45 | |
| 46 | ## Get Started in 3 Lines |
| 47 | |
| 48 | ```typescript |
| 49 | import { CodeModeUtcpClient } from '@utcp/code-mode'; |
| 50 | |
| 51 | const client = await CodeModeUtcpClient.create(); // 1. Initialize |
| 52 | await client.registerManual({ name: 'github', /* MCP config */ }); // 2. Add tools |
| 53 | const { result } = await client.callToolChain(`/* TypeScript */`); // 3. Execute code |
| 54 | ``` |
| 55 | |
| 56 | That's it. Your AI agent can now execute complex workflows in a single request instead of dozens. |
| 57 | |
| 58 | ## What You Get |
| 59 | |
| 60 | ### **Progressive Tool Discovery** |
| 61 | ```typescript |
| 62 | // Agent discovers tools dynamically, loads only what it needs |
| 63 | const tools = await client.searchTools('github pull request'); |
| 64 | // Instead of 500 tool definitions → 3 relevant tools |
| 65 | ``` |
| 66 | |
| 67 | ### **Natural Code Execution** |
| 68 | ```typescript |
| 69 | const { result, logs } = await client.callToolChain(` |
| 70 | // Chain multiple operations in one request |
| 71 | const pr = await github.get_pull_request({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 }); |
| 72 | const comments = await github.get_pull_request_comments({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 }); |
| 73 | const reviews = await github.get_pull_request_reviews({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 }); |
| 74 | |
| 75 | // Process data efficiently in-sandbox |
| 76 | return { |
| 77 | title: pr.title, |
| 78 | commentCount: c |