TypeScript Bash Implementation Cuts AI Token Costs by 95%
JustBash runs Bash commands in TypeScript without infrastructure, reducing AI agent token usage from 133,000 to 6,000 in real-world tests.
Written by AI. Bob Reynolds
February 7, 2026

Photo: Better Stack / YouTube
The problem with giving AI agents shell access has always been infrastructure. You need containers, servers, sandboxes—the whole stack. Then you need to secure it, monitor it, and hope nothing breaks loose. A new package called JustBash sidesteps this entirely by implementing Bash commands in TypeScript with an in-memory file system. No real shell required.
I've watched developers solve this problem for decades. In the 1990s, we built elaborate CGI scripts with careful sanitization. In the 2000s, we containerized everything. In the 2010s, we added orchestration layers. Each solution traded simplicity for safety. JustBash suggests we might not need that trade-off anymore.
How It Actually Works
JustBash converts Bash commands into JavaScript functions on the fly. When you write echo hello > greeting.txt, it's not invoking a real shell—it's running TypeScript that mimics what echo does. The file doesn't exist on any file system; it lives in memory.
The implementation is straightforward. Each Bash command maps to a JavaScript function that handles the command's flags and behavior. The echo command, for instance, becomes a function that parses echo-specific flags and returns an object with standard output, standard error, and an exit code—exactly what a real shell would produce.
The package supports more than trivial commands. It includes cat, grep, awk, jq for JSON processing, sqlite for database queries, and even python3 for scripting. Network requests work through curl with whitelist controls. Shell features like pipes, redirections, and command chaining all function as expected.
"This is literally a version of those bash commands written in TypeScript," the Better Stack team explains in their demonstration. "It's simply converting the command that we give it into a JavaScript function which it then runs, which means that it doesn't need a real shell."
The Token Economics
The practical benefit shows up in token usage. In a test using a large JSON file with thousands of records, the conventional approach—dumping the entire file into the AI's context window—consumed 133,000 tokens. The JustBash approach used 6,000 tokens for the same query.
That's not a marginal improvement. It's a 95% reduction.
The savings compound. With traditional context loading, every query against that data file burns through another 133,000 tokens. With JustBash, the AI agent runs actual commands against the data—grep, awk, jq—and only the results enter the context window. Ask for records matching specific criteria, and the agent executes the filter rather than searching through the entire dataset in its memory.
This matters because AI inference costs scale with tokens. At current GPT-4 pricing, that difference between 133,000 and 6,000 tokens translates to real money at scale. More importantly, it changes what's practical. Complex data analysis that would exhaust context windows or cost prohibitively suddenly becomes routine.
What Gets Simpler
The infrastructure reduction is the second benefit. Traditional approaches require either a RAG system with vector databases and chunking strategies, or a sandboxed shell environment with containers and security policies. Both add operational complexity.
JustBash requires neither. The demonstration shows integration with the AI SDK in about a dozen lines of code. Create a bash tool, pass it the files you want in the simulated environment, specify a virtual directory path, and hand it to your AI agent. No Docker, no security reviews, no infrastructure team.
"It's honestly just such a simple free value add that you can provide to your agents to make them more powerful with no additional infrastructure needed," the developers note.
The security model is simpler too. Because there's no real shell, there's no shell injection risk. Network requests run through a whitelist. File system access is contained to in-memory structures by default, though you can attach real file systems if needed.
The Gaps Worth Noting
No implementation of Bash in another language will be complete. Edge cases exist. Some commands will behave differently. Scripts that depend on specific shell quirks or system calls won't work.
The in-memory file system has obvious limits. Large datasets that don't fit in memory won't work. Persistence requires explicit handling. If your use case needs actual disk I/O or system-level operations, you're back to needing real infrastructure.
Performance characteristics differ too. JavaScript's execution model isn't Bash's execution model. For compute-intensive operations, a real shell might be faster. For I/O-bound operations, the in-memory file system might be faster. The trade-offs depend on your specific workload.
And there's the question of maintenance. Bash evolves. New commands appear, existing commands gain flags, behavior changes. Every update requires someone to write the TypeScript equivalent. That's ongoing work.
What This Enables
The interesting part isn't what JustBash does—it's what it makes trivial. AI agents that can analyze log files, process CSV data, query SQLite databases, transform JSON structures, all without leaving the JavaScript runtime. No Docker containers spinning up and down. No network calls to remote sandboxes. No token bloat from dumping everything into context.
The demonstration shows an agent that tries a jq command, gets an error, runs head to inspect the file format, then corrects its jq syntax and succeeds. That's an agent debugging itself using standard Unix tools. The entire interaction happens in memory, in TypeScript, with no real shell involved.
For developers building AI applications, this pattern might matter more than the specific implementation. The idea that you can give AI agents powerful capabilities through simulation rather than delegation—that you can trade infrastructure complexity for runtime simplicity—that's worth examining.
Whether JustBash becomes standard tooling or remains a niche solution depends on what developers build with it. The token savings alone justify attention. The infrastructure reduction makes it practical. What remains to be seen is whether the limitations prove manageable or fatal for real-world use cases.
—Bob Reynolds, Senior Technology Correspondent
Watch the Original Video
This Makes AI Agents WAY More Powerful (just-bash)
Better Stack
6m 31sAbout This Source
Better Stack
Since launching in October 2025, Better Stack has rapidly garnered a following of 91,600 subscribers by offering a compelling alternative to traditional enterprise monitoring tools such as Datadog. With a focus on cost-effectiveness and exceptional customer support, the channel has positioned itself as a vital resource for tech professionals looking to deepen their understanding of software development and cybersecurity.
Read full source profileMore Like This
AI Agents That Work While You Sleep: The Next Shift
Cloud-based AI coding agents now run scheduled tasks overnight. A developer built a news monitoring system in one afternoon that never sleeps.
Anthropic Bet on Teaching AI Why, Not What. It's Working.
Anthropic's 80-page Claude Constitution reveals a fundamental shift in AI design—teaching principles instead of rules. The enterprise market is responding.
Why Skills Are Flunking: Vercel's AI Agent Revelations
Vercel finds skills often unused by AI agents. Discover why agents.md might be the true MVP.
NVIDIA's PersonaPlex: Redefining AI Conversations
Explore NVIDIA's PersonaPlex, a groundbreaking AI model offering real-time, full-duplex conversations with near-zero latency.