किसी coding agent को काम करते देखिए तो एक लय दिखती है: एक file पढ़ो, सोचो, दूसरी file पढ़ो, सोचो, एक command चलाओ, सोचो। हर कदम छोटा लगता है। बिल कुछ और कहता है। इनमें से हर कदम पूरी conversation दोबारा model को भेजता है, और हर tool result context window में आकर वहीं टिका रहता है। एक सवाल का जवाब देने के लिए दस file reads का मतलब है दस पूरे round trips, हर एक अपने से पहले का सब कुछ ढोता हुआ।

Code mode इसका इलाज है: हर कदम पर एक JSON tool call की जगह model एक छोटा script लिखता है जो कई tools को call करता है, एक sandbox उसे चलाता है, और conversation में वापस सिर्फ़ वही जाता है जो script print करता है। बीच के results — वे दस files, कच्चे API responses, वे rows जिन्हें आप filter करवाना चाहते थे — model के context में कभी आते ही नहीं।

बचत काल्पनिक नहीं है। Anthropic की engineering team ने दिखाया कि एक workflow 150,000 tokens से घटकर 2,000 रह गया — 98.7% की कमी — जब tools को सीधे call करने की जगह code से call किया गया। हमारे अपने benchmark में, code mode के इर्द-गिर्द बना एक harness — वह client program जो agent loop चलाता है — उसी model के साथ Codex के solve rate के बराबर पहुँचा, प्रति solved task करीब 24% कम लागत पर। यह post बताती है कि code mode क्या है, क्यों काम करता है, लोकप्रिय clients इसे कहाँ इस्तेमाल करते हैं, और हमने क्या मापा।

समस्या: tool calls की कीमत हर round trip पर चुकती है

Agent loop ऐसे चलता है। Model एक tool call भेजता है — एक छोटा JSON object जो किसी tool का नाम और उसके arguments बताता है। Harness उसे चलाता है, result को conversation में जोड़ता है, और पूरी conversation वापस model को भेजता है ताकि वह अगला कदम तय कर सके। फिर वही। और फिर वही।

हर round के साथ दो लागतें बढ़ती जाती हैं:

  • Tokens. हर round trip system prompt, tool definitions और अब तक का हर message दोबारा भेजता है। Prompt caching इसे कुछ हल्का करता है, लेकिन cached tokens की भी कीमत लगती है — यह रहा दस लाख tokens की असली लागत का हिसाब — और हर नया tool result ताज़ा input है जिसे अगला round ढोना ही पड़ेगा।
  • Context. Tool definitions शुरू में ही load हो जाती हैं। काफ़ी सारे Model Context Protocol (MCP) servers जोड़ लीजिए — वह standard जो बाहरी tools को agents से जोड़ता है — और आपके एक शब्द टाइप करने से पहले ही definitions अकेले दसियों हज़ार tokens खा सकती हैं। Anthropic के example workflow ने 150,000 tokens जलाए, ज़्यादातर tool definitions और बीच के results पर। ज़्यादा भरा हुआ window यह भी मतलब रखता है कि model tools ज़्यादा बुरी तरह चुनता है और instructions जल्दी भूलता है।

दो-कदम वाले task के लिए इनमें से कुछ भी मायने नहीं रखता। उस काम के लिए बहुत मायने रखता है जो agents असल में करते हैं: बारह files की तुलना करो, किसी API के पन्ने पलटो, दो datasets join करो, list का हर item जाँचो। Model को हर बीच का byte देखने की ज़रूरत नहीं है। उसे जवाब चाहिए। कुछ भी बदलने से पहले, मापिए कि कौन-से tokens definitions से आ रहे हैं और कौन-से results से — यही बँटवारा तय करता है कि code mode आपके लिए इलाज है भी या नहीं।

Code mode क्या है

Code mode model को एक ही tool देता है — आमतौर पर code, exec, या execute — जो एक script स्वीकार करता है। जिन tools को agent आम तौर पर एक-एक करके call करता, वे script के runtime में functions की तरह उपलब्ध होते हैं। Orchestration model ख़ुद लिखता है: loops, filters, parallel calls, conditionals। एक sandbox उसे चलाता है और सिर्फ़ printed या returned value लौटाता है।

वही task, दो तरीक़ों से। Direct tool calls — तीन क्रमिक calls, तीन round trips, हर file का पूरा content context में:

{"tool": "read_file", "arguments": {"path": "src/a.rs"}}
{"tool": "read_file", "arguments": {"path": "src/b.rs"}}
{"tool": "read_file", "arguments": {"path": "src/c.rs"}}

Code mode — एक round trip, context में सिर्फ़ summary:

const [a, b, c] = await Promise.all([
  files.read({ path: "src/a.rs" }),
  files.read({ path: "src/b.rs" }),
  files.read({ path: "src/c.rs" }),
]);
for (const f of [a, b, c]) {
  print(`${f.split("\n").length} lines`);
}

तीन चीज़ें इसे काम करने लायक बनाती हैं:

  1. बीच के results sandbox में ही रहते हैं। Script 5,000 लाइन की file पढ़ सकता है, उसे grep कर सकता है, और जो दो लाइनें काम की हैं बस वे print कर सकता है। Model दो लाइनों की कीमत देता है, 5,000 की नहीं।
  2. कई की जगह एक round trip। हर code call अब भी conversation दोबारा भेजता है — लेकिन जहाँ दस calls थे, वहाँ अब एक है। Script के अंदर की स्वतंत्र calls parallel चलती हैं।
  3. Models tool-call JSON से बेहतर code लिखते हैं। Code Mode के लिए Cloudflare का यही मुख्य तर्क है: LLMs ने training में असली code की लाखों लाइनें देखी हैं, जबकि tool-calling एक सँकरा, कृत्रिम format है जो उन्हें सिर्फ़ fine-tuning में मिलता है। for loop लिखना ख़ूब अभ्यास किया हुआ हुनर है; क्रम में दस बिल्कुल सही आकार के JSON calls भेजना नहीं।

अकादमिक नतीजा product लहर से पहले का है। CodeAct paper (Wang et al., ICML 2024) ने API-Bank और लेखकों के M³ToolEval benchmark पर 17 LLMs को परखा: executable Python code के ज़रिए काम करने वाले agents, JSON या text tool calls से काम करने वालों के मुक़ाबले 20% तक ज़्यादा बार सफल हुए, और उन्हें कम कदम लगे। Code model को control flow, variables और पढ़ने लायक error messages देता है जिनसे वह debug कर सकता है — एक JSON call इनमें से कुछ नहीं देता।

Code mode बनाम direct tool calls बनाम tool search

Client किसी model से tools को चार तरीक़ों से जोड़ सकता है, और ये समस्या के अलग-अलग हिस्से हल करते हैं:

तरीक़ा Model क्या भेजता है Context में क्या रहता है कहाँ फ़िट बैठता है
Direct tool calls हर कदम पर एक JSON call हर call और उसका पूरा result छोटे tasks, कम tools
Shell scripts shell tool के ज़रिए Bash या Python script और उसका printed output Ad-hoc orchestration; न typed tool access, न per-call guardrails
Tool search direct calls; definitions ज़रूरत पर load होती हैं load हुए schemas और पूरे results बहुत सारे tools, प्रति task कम calls
Code mode typed tool functions को call करता एक script script और उसका printed output Multi-step काम, बड़े intermediate results

Tool search definitions के टैक्स को ठीक करता है; code mode definitions के टैक्स और round-trip के टैक्स, दोनों को। ये साथ चल सकते हैं — Octomind और Claude Code दोनों ship करते हैं।

प्रकाशित आँकड़े क्या कहते हैं

प्रकाशित नतीजे mixed workloads पर करीब 37% कम tokens से लेकर tool-heavy चरम मामलों में 99% से ऊपर तक जाते हैं; जीत का आकार इस पर टिका है कि आपके context का कितना हिस्सा tool overhead है।

स्रोत तारीख़ क्या मापा गया नतीजा
CodeAct, ICML 2024 Feb 2024 17 LLMs, API-Bank + M³ToolEval JSON/text actions के मुक़ाबले 20% तक ज़्यादा success rate
Anthropic: Code execution with MCP Nov 2025 Example workflow, tools को code से call किया गया 150K → 2K tokens (−98.7%)
Anthropic: Advanced tool use Nov 2025 उनके evals पर Programmatic Tool Calling औसतन −37% tokens (43.5K → 27.3K)
Anthropic: Advanced tool use Nov 2025 Tool Search Tool, MCP मूल्यांकन Opus 4.5 की accuracy 79.5% → 88.1%
Cloudflare: Code Mode MCP server Mar 2026 पूरा Cloudflare API, 2 tools के ज़रिए (tiktoken) बराबर के tool definitions के 1.17M के मुक़ाबले ~1,000 tokens (−99.9%)

इन्हें गारंटी नहीं, मौजूदगी के सबूत की तरह पढ़िए। 98.7% और 99.9% के आँकड़े best-case demos हैं — एक बड़े document वाला workflow और एक विशाल API surface, यानी ठीक वही जगह जहाँ code mode चमकता है। Anthropic का −37% उनके evaluation set का औसत है, जो mixed workload के क़रीब है। आपका दो-कदम वाला task कुछ नहीं बचाएगा।

आपके इस्तेमाल के clients में code mode

नवंबर 2026 तक, यह pattern ज़्यादातर बड़े agent stacks में ship हो चुका है — अलग-अलग नामों से और अलग-अलग दायरे के साथ।

Claude API: Programmatic Tool Calling

Anthropic code mode को दो API features के रूप में ship करता है। Programmatic Tool Calling Claude को Python लिखने देता है जो Anthropic के code-execution sandbox के अंदर आपके tools को call करता है; tool results script के पास जाते हैं, context में नहीं। Tool Search Tool definitions वाला आधा हिस्सा हल करता है: tools को defer_loading: true से चिह्नित कीजिए और Claude हर schema पहले से load करने की जगह ज़रूरत वाले tools खोजता है। दोनों 24 नवंबर, 2025 को beta में आए (anthropic-beta: advanced-tool-use-2025-11-20); tool reference मौजूदा code_execution versions और उस allowed_callers field को document करता है जो तय करता है कि script किन tools को call कर सकता है। OpenAI अपनी API में यही pattern Programmatic Tool Calling के रूप में ship करता है: model एक program लिखता है जो आपके tools को call करता है, और results conversation की जगह execution environment में रहते हैं।

Claude Code: Code Mode (experimental) और tool search

Claude Code Code Mode को experimental feature के रूप में ship करता है, default से बंद: Claude JavaScript लिखता है जो एक ही कदम में कई tool calls करता है, script session में चलता है, और conversation code की जगह अंदरूनी tool calls दिखाती है — पूरी transcript में script दिखता है। यह subagents में काम करता है, और हर call पर वही आम permission checks लागू रहते हैं। अलग से, MCP tool search definition bloat पर वार करता है: MCP tool definitions ज़रूरत पर load होती हैं, और ENABLE_TOOL_SEARCH=auto इसे तब चालू करता है जब definitions context window का मोटे तौर पर 10% या उससे ज़्यादा लेने वाली हों।

OpenAI Codex: exec tool

Codex के open-source client में code-mode runtime मौजूद है: codex-rs/core/src/tools/code_mode/। Model को एक exec tool दिखता है जो JavaScript लेता है; script के अंदर वह tools.exec_command(...) और tools.apply_patch(...) जैसे nested tools को call करता है। hooks documentation बताती है कि hooks इन nested calls को कैसे observe करते हैं। कोई model code mode से होकर जाएगा या नहीं, यह model और turn type पर निर्भर है — ठीक इसी बारे में open issues मौजूद हैं।

Cloudflare: server की तरफ़ code mode

Cloudflare का मोड़: sandbox server देता है, इसलिए किसी भी MCP client को कुछ implement किए बिना code mode मिल जाता है। इसका Code Mode MCP server पूरा Cloudflare API दो tools के ज़रिए खोलता है — typed OpenAPI spec खंगालने के लिए search(), API पर JavaScript चलाने के लिए execute() — करीब 1,000 tokens के context में, चाहे कितने भी endpoints हों। बराबर का पारंपरिक MCP server 1.17 million tokens की tool definitions माँगता, जो ज़्यादातर models की context windows से बड़ा है। Code Mode SDK Agents SDK में open source है, तो आप अपनी API को भी उसी तरह wrap कर सकते हैं।

Octomind: हर बाहरी tool call script से होकर जाता है

Octomind, हमारा open-source coding agent, code mode को harness में ही बनाता है और default से चालू ship करता है। Model को एक code tool मिलता है; बाहरी MCP tools उसके description में callable functions की तरह सूचीबद्ध होते हैं, पूरे schemas भेजने की जगह। Script TypeScript होता है, और कुछ भी चलने से पहले एक embedded compiler उसे strict mode में type-check करता है — अनजान tool, ग़लत argument, या छूटा हुआ await एक भी tool call होने से पहले पूरा script ख़ारिज कर देता है। Script के अंदर की हर call उन्हीं guardrails से गुज़रती है जो एक direct call पर लगती हैं, और session script की हर call का रिकॉर्ड रखता है। Model तक सिर्फ़ वही पहुँचता है जो script print करता है। जब tool list ख़ुद response budget से बड़ी हो जाती है, तो एक search_tools tool (BM25 keyword ranking + local embeddings) description से सही tools ढूँढता है। पूरा mechanism documentation में दर्ज है, और सादी tool definitions चाहिए तो [mcp] code_mode = false इसे बंद कर देता है।

बाक़ी सब

Cursor, Gemini CLI, GitHub Copilot CLI और opencode tools को direct calls और एक shell के रूप में खोलते हैं, और नवंबर 2026 तक हमें उनके public docs में कोई documented code-mode feature नहीं मिला। यह documentation के बारे में एक observation है, internals पर फ़ैसला नहीं — और shell का escape hatch मतलब रखता है कि उनके agents चाहें तो इस pattern के क़रीब पहुँच सकते हैं।

हमने क्या मापा

हम coding agents को merged pull requests से निकाले असली tasks पर benchmark करते हैं — octobench, 5 languages, projects के अपने held-out tests, network सीलबंद ताकि कोई agent upstream fix ढूँढ न सके। GOLD suite 13 one-shot tasks और 2 long-run sequences चलाती है, प्रति column 5 rounds।

8–10 नवंबर, 2026 के run ने दो harnesses की तुलना उसी model (gpt-6.1-sol), same reasoning effort और same containers पर की: Codex CLI 0.167.0 और Octomind 0.70.1, जिसका harness हर बाहरी tool call को code mode से होकर भेजता है।

प्रति round, GOLD results Codex Octomind
One-shot solve rate (मिलाकर, 5 rounds) 58.5% (38/65) 58.5% (38/65)
प्रति solved task लागत $0.59 $0.45
प्रति solved task tokens 3.4M 2.2M
Output tokens 478K 253K
कुल tokens (cache reads सहित) 122.4M 76.6M
प्रति solved task wall time 0.13h 0.13h

वही solve rate, प्रति solve करीब 24% कम लागत, प्रति solve करीब 35% कम tokens, और output tokens मोटे तौर पर आधे। जिस काम को दोनों harnesses ने एक ही round में हल किया, उस पर relative token index (हर item को cross-column median पर normalize करके) Codex के लिए 1.10 है और Octomind के लिए 0.80।

दो ईमानदार caveats। पहला, यह harness-level तुलना है, अलग किया गया code-mode ablation नहीं: दोनों clients system prompts, compression और tool design में भी अलग हैं, और Codex का अपना code mode है — table पूरे harness का श्रेय दर्ज करती है। दूसरा, wall time बराबर निकला। हमारे sample में Octomind का API route प्रति request करीब 14% धीमा चला, लेकिन confidence interval में कोई फ़र्क़ शामिल नहीं; जो भी हो, token की बचत समय की बचत में नहीं बदली। Per-round records और protocol सार्वजनिक हैं; ख़ुद चलाकर देखिए।

आज ही आज़माइए

  • Claude API: advanced-tool-use-2025-11-20 beta header जोड़िए, tools को allowed_callers से चिह्नित कीजिए, और code-execution tool चालू कीजिए। Anthropic की guide में request का आकार दिया है।
  • Claude Code: experimental Code Mode feature चालू कीजिए (यह default से बंद है); अपने MCP servers हमेशा की तरह जोड़िए और मौजूदा versions पर tool search definition bloat सँभाल लेता है।
  • Codex: मौजूदा versions code-mode runtime के साथ आते हैं; exec से होकर कब जाना है, यह model तय करता है।
  • Octomind: octomind.run से install कीजिए और octomind run developer चलाइए — हर बाहरी tool के लिए code mode default से चालू है।
  • आपकी अपनी API: इसे Cloudflare Code Mode SDK से wrap कीजिए और किसी भी MCP client को फ़ायदा मिलेगा, client में कोई बदलाव नहीं चाहिए।

जहाँ code mode मदद नहीं करता

Code mode medium और heavy multi-step काम पर फ़ायदा देता है; छोटे tasks पर यह direct calls से ज़्यादा tokens ख़र्च कर सकता है। Script लिखने में output tokens लगते हैं, और बचत उन दो जगहों से आती है जो छोटे task के पास होती ही नहीं: कई round trips और बड़े intermediate results। एक छोटी file पढ़ने की एक call पहले से ही optimal है — उसे script में लपेटना overhead जोड़ता है, घटाता कुछ नहीं।

हमारे per-task आँकड़े दोनों दिशाएँ दिखाते हैं। python_pydantic_deque_schema पर, एक छोटा Python task जिसे दोनों harnesses ने पाँचों rounds में हल किया, code-mode harness ने ज़्यादा ख़र्च किया: प्रति round median 3.27M tokens ($0.66) बनाम Codex के 2.13M ($0.51)। Suite की सबसे भारी sequence पर — 14-turn का DuckDB optimizer run जिसे दोनों harnesses ने हर round में पूरा किया — उसने बहुत कम ख़र्च किया: 18.42M tokens ($3.55) बनाम 43.70M ($7.05), आधे से भी कम। वही model, वही ऊपर वाला caveat: harness-level, ablation नहीं। Per-task results में बड़ी जीतें heavy tasks पर हैं; छोटे tasks सिक्का उछालने बराबर हैं या घाटे में।

आप जितने ज़्यादा MCP servers जोड़ते हैं, पलड़ा उतना ही code mode की तरफ़ झुकता है। Definition की बचत आपके tool surface के आकार के साथ बढ़ती है: Cloudflare का 1.17M-token वाला example चरम है, लेकिन एक दर्जन जुड़े servers ही हर round में, हर task पर, हमेशा के लिए दसियों हज़ार definition tokens डाल देते हैं। Code mode और tool search वह टैक्स हटा देते हैं; दो tools वाला agent वह टैक्स कभी देता ही नहीं।

असली लागतें भी हैं। किसी को sandbox चलाना पड़ता है, resource limits और monitoring के साथ — Anthropic इस पर साफ़ है। Debugging एक परत और गहरी हो जाती है: जब script आधे में fail होता है, तो आपको जानना होता है कि कौन-सी calls चलीं — इसीलिए Octomind per-call रिकॉर्ड रखता है और execution से पहले scripts को type-check करता है। और Octomind process का पहला script embedded compiler के load होने के लिए करीब एक second रुकता है। छोटा, लेकिन असली।

क्या code mode सुरक्षित है?

Code mode यह बदलता है कि model अपने tools तक कैसे पहुँचता है, यह नहीं कि वह किन tools तक पहुँच सकता है: Octomind में script के पास न imports हैं, न filesystem, न network — tools ही बाहर जाने का एकमात्र रास्ता हैं, और हर call उन्हीं guardrails से गुज़रती है जो direct call पर लगती हैं। लेकिन sandbox ख़ुद code है, और code में bugs होते हैं। Check Point Research ने 2026 में अंदरूनी workerd runtime की vulnerabilities के ज़रिए Cloudflare के Code Mode sandbox से बाहर निकलकर host पर code execution तक पहुँच बनाई। Guardrails यह बाँधते हैं कि script क्या करने की अनुमति रखता है; वह क्या कर सकता है, यह सिर्फ़ patched, ठीक से चलाया गया sandbox बाँधता है। Runtime को updated रखिए और उसे वही security boundary मानिए जो वह है।

अगर आपका agent वाला काम ज़्यादातर multi-step है — और ज़्यादातर असली काम है — तो यह pattern जहाँ भी मौजूद है, चालू करने लायक है। Research कहती है कि agents इसके साथ ज़्यादा बार सफल हो सकते हैं, ख़ासकर जटिल tasks पर। Vendor के आँकड़े कहते हैं कि workload फ़िट होने पर token बचत बड़ी है। हमारा benchmark कहता है कि इसके इर्द-गिर्द बना harness बराबर solve rate काफ़ी कम लागत पर दे सकता है। किसी agent architectural फ़ैसले के लिए इससे बेहतर समर्थन मिलना मुश्किल है।

संदर्भ