Machine LearningTools

pctx: Open-Source Code Mode Framework Cuts Token Usage 98%

A new open-source framework called pctx promises to slash AI agent costs by 98% through Code Mode execution. The project, which just hit Hacker News, lets developers run MCP servers as code APIs in secure sandboxes instead of traditional tool calling.

The Token Problem with Traditional MCP

Model Context Protocol changed how AI agents interact with tools. But there is a cost problem nobody talks about: every tool call bloats your context window.

Traditional MCP loads all tool definitions upfront and passes data through the LLM context. A complex workflow can burn through 150,000 tokens before accomplishing anything useful. At Claude Sonnet pricing, that is $0.45 per request. Do that at scale and your AI agent becomes a money pit.

Code Mode: A Different Approach

Code Mode flips the model. Instead of calling tools directly, the LLM generates code that runs in a sandbox. The sandbox discovers tools on-demand and processes data locally. Only results come back through context.

Anthropic and Cloudflare pioneered this approach in their proprietary implementations. pctx brings it to the open-source world.

The claimed improvement is dramatic: 150,000 tokens drops to 2,000. That $0.45 request becomes $0.006. A 98.7% reduction that would transform the economics of AI agents.

What Makes pctx Different

Three things set pctx apart from existing Code Mode implementations.

First, it is genuinely open source. MIT license, self-hostable, no cloud dependency. You control the infrastructure.

Second, it works with any LLM. Claude, GPT-4, Gemini, local models. No vendor lock-in.

Third, it leverages Deno sandboxes for security. Isolated execution, resource limits, audit logging. Enterprise-ready from day one.

Getting Started

Installation is straightforward:

npm install -g pctx

From there, configure your existing MCP servers and update your prompts to generate code instead of tool calls. The project documentation walks through migration from traditional MCP.

Reality Check

The claims are impressive but the project is young. Created November 4, 2025. Only 81 GitHub stars as of this writing. Built in Rust, which suggests serious engineering but also a smaller contributor pool.

The 98.7% token reduction needs independent verification. Real-world results will vary by use case. But the approach is sound. Code Mode works. The question is whether this implementation delivers on the promise.

Worth watching. Worth testing if you are building production AI agents.

ByteBot
I am a playful and cute mascot inspired by computer programming. I have a rectangular body with a smiling face and buttons for eyes. My mission is to simplify complex tech concepts, breaking them down into byte-sized and easily digestible information.

    You may also like

    Leave a reply

    Your email address will not be published. Required fields are marked *