{"slug": "i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save", "title": "I built a CLI harness that strips JS/TS function bodies with Babel AST to save 80% context tokens", "summary": "Amanulla Shaikh built and open-sourced Apex Agents, a CLI harness that uses Babel's AST parser to strip JavaScript and TypeScript function bodies while preserving types, generics, parameters, and exports, compacting an approximately 13k-token codebase to about 1.4k tokens (88.5% reduction) in testing. The tool also ships a pre-commit hook that blocks AI agents from modifying or skipping tests and halts commits containing high-entropy API keys, 38 specialist persona rules for .cursor/rules, and a native MCP JSON-RPC stdio server for Claude Desktop and Cursor.", "body_md": "While working on large Next.js and TypeScript repositories, I noticed AI coding agents (Cursor, Claude Code) constantly burning through context limits. They were reading 500-line implementation files when all they really needed were the types, interfaces, and exported signatures.\n\nTo solve this mechanically, I engineered and open-sourced Apex Agents.\n\nHow It Works:\n\nBabel AST Compactor (`npx apex-agents compact`):\n\nParses TypeScript, JSX, and JavaScript using `@babel/parser` and replaces function bodies with `{}` while preserving all types, generics, parameters, and exports. In our tests, an ~13k token codebase compacted down to ~1.4k tokens (88.5% reduction) into an `APEX_CONTEXT.md` file.\n\nPre-Commit Anti-Cheat & Secret Guard (`.git/hooks/pre-commit`):\n\nDiff auditor physically prevents AI agents from modifying or skipping tests to fake a \"pass\", and halts any accidental commit containing high-entropy API keys.\n\n38 Specialist Personas (`.cursor/rules`):\n\nInjects domain-specific engineering rules directly into `.cursor/rules` for database performance, React 19 architecture, and Lighthouse optimization.\n\nNative MCP Server:\n\nBuilt-in JSON-RPC stdio server ready to plug into Claude Desktop or Cursor MCP settings.\n\nTry it in any repo:\n\nbash:\n\nnpx apex-agents init\n\nGitHub: [github.com/AmanullaShaikh/apex-agents](https://github.com/AmanullaShaikh/apex-agents)\n\nNPM: [npmjs.com/package/apex-agents](https://www.npmjs.com/package/apex-agents)\n\nFeedback and pull requests are welcome!", "url": "https://wpnews.pro/news/i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save", "canonical_source": "https://dev.to/shaikhamanulla/i-built-a-cli-harness-that-strips-jsts-function-bodies-with-babel-ast-to-save-80-context-tokens-1dak", "published_at": "2026-11-13 16:12:38+00:00", "updated_at": "2026-11-13 16:21:14.162729+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools", "agent-protocols", "ai-products"], "entities": ["Amanulla Shaikh", "Apex Agents", "Babel", "Cursor", "Claude Code", "Claude Desktop", "Next.js", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save", "markdown": "https://wpnews.pro/news/i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save.md", "text": "https://wpnews.pro/news/i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save.txt", "jsonld": "https://wpnews.pro/news/i-built-a-cli-harness-that-strips-js-ts-function-bodies-with-babel-ast-to-save.jsonld"}}