{
  "source_file": "0930",
  "source_platform": "Ghost",
  "author": "Avi Chawla / Daily Dose of Data Science",
  "title_listed": "How We Cut Our Claude Code Token Usage 2 8x",
  "keywords": "",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/",
  "publish_date": "2026-05-08",
  "corpus_stage": "",
  "notes": "",
  "id": "dbde7b68a879",
  "collected_at": "2026-10-02T13:48:29",
  "title": "How We Cut Our Claude Code Token Usage 2.8x!",
  "body_markdown": "[ Skip to main content  ](https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/#sx-main)\n[ ![Daily Dose of Data Science](https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2025/12/dailyds-logo-transparent-1.png) ](https://www.dailydoseofds.com)\n  * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n  * [ Archive ](https://www.dailydoseofds.com/archive/)\n  * Guidebooks \n    * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n[ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n[ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n[ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n[ Courses ](https://www.dailydoseofds.com/)\n[ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n[ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n[ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n[ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n  * Courses \n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n[ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n[ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n[ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n[ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n[ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n[ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n  *     * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n[ Archive ](https://www.dailydoseofds.com/archive/)\nGuidebooks \n      * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n      * [ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n      * [ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n      * [ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n      * [ Courses ](https://www.dailydoseofds.com/)\n      * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n      * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n      * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n      * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n      * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\nCourses \n      * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n      * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n      * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n      * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n      * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n      * [ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n      * [ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n      * [ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n\n\nSign In  [ Get Started ](https://www.dailydoseofds.com/membership)\n/\n  * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n  * [ Archive ](https://www.dailydoseofds.com/archive/)\n  * Guidebooks \n    * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n    * [ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n    * [ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n    * [ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n    * [ Courses ](https://www.dailydoseofds.com/)\n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n    * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n    * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n    * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n    * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n  * Courses \n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n    * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n    * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n    * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n    * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n    * [ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n    * [ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n    * [ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n  * Sign In \n\n\nApr 21, 2026  Claude \n#  How We Cut Our Claude Code Token Usage 2.8x! \n...using Karpathy's context engineering principles! \n![Avi Chawla](../images/000.jpg)\nAvi Chawla \n👉\n* * *\nMCPMark V2 benchmarks revealed something counterintuitive.\nWhen Claude moved from Sonnet 4.5 to Sonnet 4.6, backend token usage through Supabase’s MCP server went up, from 11.6M to 17.9M tokens across 21 database tasks.\nThe model got smarter, but the backend token usage actually increased.\n![](../images/001.png)\nThe reason is subtle, and it has nothing to do with the model.\nInstead, it has to do with how the backend exposes info to the agent. When context is incomplete, a more capable model doesn’t just skip the gap.\nIt spends more tokens reasoning about the gap, runs more discovery queries, and retries more frequently. So the missing context doesn’t disappear with a better model. It gets more expensive.\nLet’s look at why backends are a token sink for agents, what an alternative architecture looks like, and what the cost difference is on a real project.\n* * *\n### **Why Supabase’s MCP server wastes tokens**\nSupabase is a great backend. But it wasn’t designed to be operated by AI agents, and the MCP server that was added later inherits that limitation.\nThree specific mechanisms cause the token bloat.\n#### **1) Documentation retrieval returns everything**\nWhen CC needs to set up Google OAuth through Supabase, it invokes the `search_docs` MCP tool.\nSupabase’s implementation returns full GraphQL schema metadata on every call, which has 5-10x more tokens than the agent actually needs.\n![](../images/002.png)\nIf the agent asked for OAuth setup instructions, it got the entire authentication docs, including sections on email/password, magic links, phone auth, SAML, and SSO.\nThis happens on every `search_docs` call, like database queries, storage configuration, and edge function deployment.\nEach call dumps the full metadata for that entire domain. Across a session where the agent sets up auth, database, storage, and functions, the docs overhead alone can account for thousands of wasted tokens.\n#### **2) No visibility into backend state**\nWhen you use Supabase as a human dev, you open the dashboard and see everything at a glance, like active auth providers, tables, RLS policies, configure storage buckets, deployed edge functions, etc.\nAn agent can’t see the dashboard.\nSupabase’s MCP server does expose some state through individual tools like `list_tables` and `execute_sql`, but there’s no way to ask “what does my entire backend look like right now?” and get one structured response.\n![](../images/016.png)\nSo the agent pieces it together through multiple calls, each call returns a partial view, and some info (like which auth providers are configured) isn’t available through MCP at all.\nThis fragmented discovery process costs tokens, and the agent often needs several attempts because the information comes back incomplete or in a format that requires further queries to interpret.\n#### **3) No structured error context**\nWhen something goes wrong (and it will, because the agent is guessing), Supabase returns raw error messages. It could be a 403 from an RLS denial, a 500 from a misconfigured edge function, etc.\nA human dev would look at it, check the Supabase dashboard, cross-reference with the logs, and fix the issue.\nThe agent doesn’t have that path. It gets the error message, reasons about what might have caused it, and tries a fix.\nIf the fix is wrong, it retries. Each retry re-sends the entire conversation history and compounds the token cost.\n* * *\nThese three mechanisms (doc overhead, state discovery, error retry loops) compound fast.\nA model that reasons more extensively, like Sonnet 4.6, makes each exploration step more thorough and more expensive.\nThat’s why the token gap widened from Sonnet 4.5 to 4.6, and it’ll likely widen further with each new model release.\n* * *\n### **What “backend context engineering” should look like**\nThe fix isn’t switching to a worse model.\nIt’s giving the agent a structured backend context so it doesn’t have to explore and guess.\nThis is what Karpathy means by context engineering: “the delicate art and science of filling the context window with just the right information for the next step.”\nHe explicitly includes tools and state as part of that context. Most people apply the idea to prompts and RAG retrieval.\nBut the backend is part of the context window too, and right now, it’s the part almost nobody is optimizing.\nTo see what this looks like in practice, [**InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com) (open source, Apache 2.0) implements exactly this approach.\n![](../images/004.png)\nIt provides the same primitives as Supabase (Postgres with pgvector, auth, storage, edge functions, and realtime) but structures the information layer so agents can consume it efficiently.\nThe key architectural difference is how it delivers context to Claude Code.\nThree layers work together:\n  * Skills for static knowledge.\n  * CLI for direct backend operations.\n  * MCP for live state inspection\n\n\nEach layer solves a different problem and reduces tokens for a different reason.\n#### **1) Skills: static knowledge with zero round-trips**\nInsForge’s primary approach for knowledge is Skills. They load directly into the agent’s context at session start, so the SDK patterns, code examples, and edge cases for every backend operation are available without any tool calls.\nSkills also use progressive disclosure, wherein only the metadata (name, description, ~70-150 tokens per skill) loads initially.\nThe full skill content loads only when the agent determines it matches the current task. This means you can have 100+ skills installed without context bloat, which isn’t possible with MCP’s all-or-nothing schema loading.\nFour skills cover the full stack, each scoped to a specific domain:\n![](../images/005.png)\n  * `insforge` for frontend code that talks to the backend.\n  * `insforge-cli` for backend infrastructure management\n  * `insforge-debug` for structured error diagnosis across common failures like auth errors, slow queries, edge function failures, RLS denials, deployment issues, and performance degradation)\n  * `insforge-integrations` for third-party auth providers (Clerk, Auth0, WorkOS, Kinde, Stytch).\n\n\nInstall all four with one command:\n\n```\nnpx skills add insforge/insforge-skills\n```\n\n#### **2) CLI for direct execution**\nFor actually executing backend operations (creating tables, running SQL, deploying functions, managing secrets), the InsForge CLI is the primary interface.\nEvery command supports `--json` for structured output, `-y` to skip confirmation prompts, and returns semantic exit codes so agents can detect auth failures, missing projects, or permission errors programmatically.\nThis is helpful because Claude Code can pipe CLI output through `jq`, `grep`, and `awk` in ways that would require multiple sequential MCP tool calls.\nThese are some example operations the agent actually runs:\n\n```\n# Inspect backend state (run first to discover what's configured)\nnpx @insforge/cli metadata --json\n\n# Database operations\nnpx @insforge/cli db query \"CREATE TABLE posts (...)\" --json\nnpx @insforge/cli db policies  # inspect existing RLS policies\n\n# Edge functions\nnpx @insforge/cli functions deploy my-handler\nnpx @insforge/cli functions invoke my-handler --data '{\"action\":\"test\"}' --json\n\n# Storage\nnpx @insforge/cli storage create-bucket documents --json\nnpx @insforge/cli storage upload ./file.pdf --bucket documents\n\n# Frontend deployment\nnpx @insforge/cli deployments env set VITE_INSFORGE_URL https://...\nnpx @insforge/cli deployments deploy ./dist --json\n\n# Diagnostics\nnpx @insforge/cli diagnose db --check connections,locks,slow-queries\n```\n\nThe agent parses the JSON and handles errors based on exit codes.\n#### **3) MCP tools for live backend state**\nMCP is still useful, but for a narrower purpose, like inspecting the current state of your backend when that state is changing.\nInsForge’s MCP server exposes a lightweight `get_backend_metadata` tool that returns a structured JSON with the full backend topology in a single call:\n\n```\n{\n  \"auth\": {\n    \"providers\": [\"google\", \"github\"],\n    \"jwt_secret\": \"configured\"\n  },\n  \"tables\": [\n    {\"name\": \"users\", \"columns\": [\"id\", \"email\", \"created_at\"], \"rls\": \"enabled\"},\n    {\"name\": \"posts\", \"columns\": [\"id\", \"title\", \"body\", \"author_id\"], \"rls\": \"enabled\"}\n  ],\n  \"storage\": { \"buckets\": [\"avatars\", \"documents\"] },\n  \"ai\": { \"models\": [{\"id\": \"gpt-4o\", \"capabilities\": [\"chat\", \"vision\"]}] },\n  \"hints\": [\"Use RPC for batch operations\", \"Storage accepts files up to 50MB\"]\n}\n```\n\nIn one call and ~500 tokens, the agent knows the full backend topology. The `hints` field provides agent-specific guidance that reduces incorrect API usage.\nThe key design choice here is that MCP is used for state inspection (which changes as the agent works), not for documentation retrieval (which doesn’t).\nThis inverts the typical usage pattern and is the main reason InsForge consumes far fewer tokens than Supabase on equivalent tasks.\n* * *\n### Supabase vs Insforge: Build DocuRAG with Claude Code\nTo make this concrete, we built the same DocuRAG app using Claude Code.\nUsers sign in via Google OAuth, upload PDFs, the system chunks and embeds the text (text-embedding-3-small, 1536 dimensions), stores the vectors in pgvector, and users ask natural-language questions answered via GPT-4o.\nThis touches nearly every backend primitive at once: user auth, file storage, a documents table, vector embeddings, embedding generation, chat completion, a retrieval edge function, and RLS to isolate each user’s documents.\nHere's the setup for each.\n#### Supabase\n  * Create a Supabase account and create a new project.\n  * Connect the MCP server to Claude Code and authenticate:\n\n\n```\nclaude mcp add --scope project --transport http supabase \\\n  \"https://mcp.supabase.com/mcp?project_ref=<your-project-ref>\"\n\nclaude /mcp\n```\n\n  * Install Supabase's Agent Skills (marked as “Optional” in Supabase's official setup):\n\n\n```\nnpx skills add supabase/agent-skills\n```\n\nThis installs two skills:\n  * `supabase`: broad catch-all skill covering Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues, client libraries (supabase-js, @supabase/ssr), SSR integrations (Next.js, React, SvelteKit, Astro, Remix), CLI, MCP, schema changes, migrations, and Postgres extensions\n  * `supabase-postgres-best-practices`: Postgres performance optimization across 8 categories\n\n\nSupabase ships one broad skill that triggers on \"any task involving Supabase,\" plus a specialized Postgres optimization skill. When the `supabase` skill activates, all its content loads because the trigger conditions cover almost the entire product surface.\n#### Insforge\n  * Create an Insforge account and create a new project (you can also self-host and run it fully locally using Docker Compose).\n  * Install all four Skills (primary documentation and diagnostic layer):\n\n\n```\nnpx skills add insforge/insforge-skills\n```\n\nThis installs `insforge` (SDK patterns), `insforge-cli` (infrastructure commands), `insforge-debug` (failure diagnostics), and `insforge-integrations` (third-party auth providers). Total metadata cost: ~714 tokens at session start.\n  * Link the CLI to your project (primary execution layer):\n\n\n```\nnpx @insforge/cli link --project-id <project-id>\n```\n\nInsForge ships four narrowly scoped skills, each covering a specific domain.\n  * When you're writing frontend code, only `insforge` activates.\n  * When you're creating tables, only `insforge-cli` activates.\n  * When something breaks, only `insforge-debug` activates.\n\n\n* * *\nThe prompt is nearly identical for both sessions, with one key difference.\n  * Supabase:\n\n\n```\nBuild a chat with document app called DocuRAG.\nIt will be a typical RAG setup where a user\ncan upload a document. It will be chunked, embedded,\nand stored in a vector DB. Once done, a user can ask\nquestions about the document. The engine will retrieve\nthe relevant chunks after embedding the query. Finally,\nit will generate a coherent response using GPT-4o based\non the query and the retrieved context. Add Google OAuth.\nUse Supabase as the backend and LLMs/embedding models via\nthe OpenAI API. Build frontend in next.js.\n```\n\n  * InsForge:\n\n\n```\nBuild a chat with document app called DocuRAG.\nIt will be a typical RAG setup where a user\ncan upload a document. It will be chunked,\nembedded, and stored in a vector DB. Once done,\nA user can ask questions about the document.\nThe engine will retrieve the relevant chunks\nafter embedding the query. Finally, it will\ngenerate a coherent response using GPT-4o based on\nthe query and the retrieved context. Add Google OAuth.\nUse Insforge as the backend and also for the model\ngateway. Build the front-end in Next.js.\n```\n\nThe Supabase prompt says \"LLMs/embedding models via the OpenAI API\" (two systems to wire). The InsForge prompt says \"also for the model gateway\" (one system).\nWe ran both sessions side by side and recorded the full build. Here’s the side-by-side video showing what happened from prompt to working app.\nIt also showcases the final output from both sessions, built on two different backends.\n> _One important thing: Supabase required manual Google OAuth setup outside of Claude Code. We had to navigate to Google Cloud Console, create an OAuth 2.0 client ID, configure the consent screen, add our email as a test user, copy the Client ID and Client Secret, then paste it into Supabase’s dashboard. This was not required in Insforge._\nBefore diving into the session-specific details, here’s what the numbers looked like at the end:\n![](../images/006.png)\n  * **Supabase:** 10.4M tokens; $9.21 Cost with 12 user messages (10 error reports)\n  * **InsForge:** 3.7M tokens; $2.81 Cost, with 1 user messages (0 error reports)\n\n\nNow let’s look at what actually happened in each session.\n> To analyze both sessions objectively, we exported the full Claude Code session history from both runs (as JSONL files) and fed them to a separate Claude instance. The analysis below, including tool call counts, error sequences, and token breakdowns, comes from parsing those session logs.\n* * *\n#### Supabase (consumed 10.4M tokens with $9.21 cost)\nThe initial build went smoothly.\nThe agent loaded the `supabase` skill, discovered the backend state via MCP tools (`list_tables`, `list_extensions`, `execute_sql`), scaffolded the Next.js project, created the database schema, wrote two edge functions (`ingest-document` and `query-document`), and deployed everything. The build passed.\n![](../images/007.png)\n##### **First problem: login didn’t work**\nWhen we tried to sign in with Google OAuth, the app threw an error. The agent had wired the authentication using the wrong Supabase client library for Next.js.\n![](../images/008.png)\nIn Next.js, the OAuth callback runs on the server, but the agent used a client-side library that stores login state in the browser. The browser state isn’t available on the server, so the login flow broke.\nThe agent fixed this by switching to a different library (`@supabase/ssr`), rewriting how the app handles login sessions, and rebuilding.\n![](../images/009.png)\n##### **Document upload failed (took 8 turns to fix)**\nAfter the login was fixed, we tried uploading a document. The edge function returned an error, we reported it, it tried a fix, failed, then we tried again, and it returned the same error. This cycle repeated 8 times:\n![](../images/010.png)\n  * The agent tried adding auth headers manually → Same error.\n  * Redeployed with extra logging to see what was happening → Same error.\n  * Tried showing the real error message instead of the generic one → Different error (now a network/CORS issue).\n  * Fixed the CORS issue → Back to the original error.\n  * Tried a different way of reading the user’s login token → Same error.\n  * Tried yet another authentication approach → Same error.\n\n\nIn plain terms, Supabase has a security layer that checks login tokens before the edge function code even starts. The new auth library the agent installed (to fix the first problem) was sending a token format that this security layer didn’t recognize.\nSo every request was getting rejected at the door before the function code had a chance to run. That’s why none of the code-level fixes worked.\n![](../images/011.png)\nThe agent spent 8 rounds fixing code-level issues when the problem was upstream of the code entirely.\nThe solution was simple: turn off the platform’s automatic token checking and handle authentication inside the function code instead.\nIt took 8 attempts because every time, it saw a 401 (unauthorized) error, but nothing told it where the rejection was coming from. Without that signal, it kept attempting to fix the code.\nBut during this debugging process, the edge function was redeployed 8 times (on top of 2 initial deploys during the build). Each redeployment, log check, and retry re-sent the entire growing conversation history, compounding the token cost.\nFinal session stats involved:\n  * 12 user messages (10 were error reports)\n  * 135 tool calls\n  * 30+ MCP tool calls.\n  * 10.4M tokens\n  * $9.21 Cost\n\n\n#### Insforge (consumed 3.7M tokens with $2.81 cost)\nThe InsForge session completed without any errors.\nThe agent started by inspecting the backend state.\nIts first action was `npx @insforge/cli metadata --json`, which returned a structured overview of the project, including the configured auth providers, existing tables, storage buckets, available AI models, and real-time channels.\n![](../images/012.png)\nThis gave the agent a complete picture of what it was working with before it wrote any code.\nIn the Supabase session, the agent needed multiple MCP calls (`list_tables`, `list_extensions`, `execute_sql`) to piece together a similar understanding, and even then, it missed critical details like the `verify_jwt` behavior.\nThe schema setup ran through 6 CLI commands, all of which succeeded.\n![](../images/013.png)\nThe agent enabled pgvector, created the `documents` and `chunks` tables (with a `vector(1536)` column), enabled Row Level Security on both, created the access policies, and set up the `match_chunks` similarity search function.\nEach command returned structured output confirming what happened, so the agent could verify each step before moving to the next.\nThe auth and edge function problems from the Supabase session didn't occur here.\nThe `insforge` skill included the correct client library patterns for Next.js, so the agent wired authentication correctly on the first attempt.\nAnd the two edge functions (`embed-chunks` and `query-rag`) both deployed and ran without errors because the model gateway for embeddings and chat completion was part of the same backend.\n![](../images/014.png)\nThe agent didn't need to integrate OpenAI separately, manage a second API key, or deal with cross-service authentication.\nThe metadata response already listed `text-embedding-3-small` and `gpt-4o` as available models, so the agent called them directly through the InsForge SDK.\nFinal session stats involved:\n  * 1 user message\n  * 77 tool calls\n  * 0 MCP tool calls.\n  * 3.7M tokens\n  * $2.81 Cost\n\n\nWe asked Claude to generate a side-by-side summary and here’s what it produced:\n![](../images/015.png)\nThe Supabase session’s token cost was driven by the error retry loop.\nEach of the 8 edge functions redeploys re-sent the entire conversation history (which grew with each attempt).\nThe agent checked logs 6 times, redeployed functions 8 times, and tried 6 different authentication strategies before finding the root cause.\nNone of this was the agent’s fault. The Supabase platform’s `verify_jwt` gate was rejecting the token before the function code ran, and the logs didn’t distinguish between platform-level and code-level rejections.\nThe Insforge session avoided these problems because the skills loaded the correct auth patterns from the start, and the CLI gave structured feedback on every operation.\n* * *\nThis comparison highlights a problem that goes beyond Supabase specifically.\nMost backends were designed for human developers who can read dashboards, interpret ambiguous errors, and mentally track state across multiple services.\nWhen an agent takes over that workflow, the assumptions break. The agent can’t see the dashboard. It can’t tell where an error came from if the logs don’t say. And every time it guesses wrong, the token cost compounds.\n![](../images/016.png)\n[**InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com) is built around a different set of assumptions.\n  * The backend exposes its state through structured metadata and the CLI gives the agent programmatic control with clear success/failure signals.\n  * The skills encode the correct patterns so the agent doesn’t have to discover them through trial and error.\n  * And the model gateway keeps LLM operations inside the same backend, which removes the cross-service integration issues that caused most of the Supabase session's debugging.\n\n\nInsForge is fully open source under Apache 2.0 and you can self-host it via Docker. The code, the skills, and the CLI are all on its GitHub repo: [**https://github.com/InsForge/InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com)**.**\nThanks for reading!\nPublished on Apr 21, 2026 \nComments \nShare \nCopy link [ Share to X ](https://x.com/intent/tweet?url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F&text=How%20We%20Cut%20Our%20Claude%20Code%20Token%20Usage%202.8x!) [ Share to Facebook ](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F) [ Share to Linkedin ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F)\nCopied \n[ Previous  Diffusion LLMs from the Ground Up: Training, Inference, and Practical Engineering  ](https://www.dailydoseofds.com/diffusion-models-part-2/) [ Next  Foundations of Reinforcement Learning  ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ ![Daily Dose of Data Science](https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2025/12/dailyds-logo-transparent-1.png) ](https://www.dailydoseofds.com)\nA daily column with insights, observations, tutorials and best practices on python and data science. Read by industry professionals at big tech, startups, and engineering students. \n  * Menu \n  * [ Contact ](https://www.dailydoseofds.com/contact/)\n  * [ FAQ ](https://www.dailydoseofds.com/faq/)\n\n\n[Daily Dose of Data Science](https://www.dailydoseofds.com) © 2026 \n[ ](https://x.com/_avichawla \"X \\(Formerly Twitter\\)\")\n",
  "metadata": {
    "title": "How We Cut Our Claude Code Token Usage 2.8x!",
    "description": "...using Karpathy's context engineering principles!",
    "keywords": null,
    "author": null,
    "og:site_name": "Daily Dose of Data Science",
    "og:type": "article",
    "og:title": "How We Cut Our Claude Code Token Usage 2.8x!",
    "og:description": "...using Karpathy's context engineering principles!",
    "og:url": "https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/",
    "og:image": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2026/05/videoframe_0--1-.png",
    "og:image:width": "1080",
    "og:image:height": "822",
    "twitter:card": "summary_large_image",
    "twitter:title": "How We Cut Our Claude Code Token Usage 2.8x!",
    "twitter:description": "...using Karpathy's context engineering principles!",
    "twitter:url": "https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/",
    "twitter:image": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2026/05/videoframe_0--1-.png",
    "twitter:label1": "Written by",
    "twitter:data1": "Avi Chawla",
    "twitter:label2": "Filed under",
    "twitter:data2": "Claude",
    "twitter:site": "@_avichawla",
    "article:published_time": "2026-04-20T19:45:00.000Z",
    "article:modified_time": "2026-05-08T19:45:52.000Z",
    "article:tag": "Claude"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_000.txt",
      "chars": 40
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_001.txt",
      "chars": 748
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_002.txt",
      "chars": 494
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_003.txt",
      "chars": 136
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_004.txt",
      "chars": 37
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_005.txt",
      "chars": 40
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_006.txt",
      "chars": 49
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_007.txt",
      "chars": 523
    },
    {
      "language": "txt",
      "file": "attachments/dbde7b68a879/code/block_008.txt",
      "chars": 514
    }
  ],
  "images": [
    {
      "src": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/size/w400/2026/03/avi-google.jpg",
      "alt": "Avi Chawla",
      "local_path": "attachments/dbde7b68a879/images/000.jpg",
      "bytes": 11344,
      "downloaded": true,
      "status": "ok",
      "url": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/size/w400/2026/03/avi-google.jpg",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!9IL1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81acd452-663f-4b8f-a688-367aa08bf46e_1346x615.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/001.png",
      "bytes": 348756,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!9IL1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81acd452-663f-4b8f-a688-367aa08bf46e_1346x615.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!Dqs9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0eb100fd-2464-4705-b406-0c427e4d3cef_1317x657.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/002.png",
      "bytes": 375267,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!Dqs9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0eb100fd-2464-4705-b406-0c427e4d3cef_1317x657.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/003.png",
      "bytes": 413623,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!PEUl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda0a801f-cb14-48b6-b5d7-a2c35541fd54_910x847.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/004.png",
      "bytes": 34808,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!PEUl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda0a801f-cb14-48b6-b5d7-a2c35541fd54_910x847.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!6aBy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1957045d-15e4-4db8-a7f8-c93282290b66_1128x650.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/005.png",
      "bytes": 113440,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!6aBy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1957045d-15e4-4db8-a7f8-c93282290b66_1128x650.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!mNxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ad82dc-4322-4a05-a9de-7aaa3b39ab96_1491x526.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/006.png",
      "bytes": 69410,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!mNxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ad82dc-4322-4a05-a9de-7aaa3b39ab96_1491x526.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!O-Um!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ebb77a-eadc-416a-af93-37dcd27e063e_895x503.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/007.png",
      "bytes": 39140,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!O-Um!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ebb77a-eadc-416a-af93-37dcd27e063e_895x503.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!EkBQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdce4221f-cad3-4f4b-8a57-139c284cc06a_899x358.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/008.png",
      "bytes": 28516,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!EkBQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdce4221f-cad3-4f4b-8a57-139c284cc06a_899x358.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!jS6F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd00cc-1593-48d0-840e-8ded923c38fa_920x742.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/009.png",
      "bytes": 110937,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!jS6F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd00cc-1593-48d0-840e-8ded923c38fa_920x742.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!2gie!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5d3e19b-67b7-4f57-97a7-03d6d2826bf3_1330x976.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/010.png",
      "bytes": 132209,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!2gie!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5d3e19b-67b7-4f57-97a7-03d6d2826bf3_1330x976.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!arYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ab298da-ad23-4619-9382-ad80c0ce9430_1008x445.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/011.png",
      "bytes": 208066,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!arYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ab298da-ad23-4619-9382-ad80c0ce9430_1008x445.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!l2tM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fecf1abce-4368-4c05-8796-86243a419818_962x739.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/012.png",
      "bytes": 80317,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!l2tM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fecf1abce-4368-4c05-8796-86243a419818_962x739.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!39CU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F155e5f22-a4fc-47ac-89b3-3fd888e68a3b_942x896.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/013.png",
      "bytes": 126403,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!39CU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F155e5f22-a4fc-47ac-89b3-3fd888e68a3b_942x896.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!t9Us!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84b43039-c9e9-457f-83f7-cbe36d3ed9bd_1133x858.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/014.png",
      "bytes": 135871,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!t9Us!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84b43039-c9e9-457f-83f7-cbe36d3ed9bd_1133x858.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!rIU2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33ba5d8a-940e-4328-b0c5-0dae6fa1690e_1528x1188.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/015.png",
      "bytes": 107218,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!rIU2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33ba5d8a-940e-4328-b0c5-0dae6fa1690e_1528x1188.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    },
    {
      "src": "https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png",
      "alt": "",
      "local_path": "attachments/dbde7b68a879/images/003.png",
      "bytes": 413623,
      "downloaded": true,
      "status": "ok",
      "url": "https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png",
      "reused": true,
      "retried_at": "2026-10-18T17:08:50Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/media/2026/05/insforge-vs-supabase-final-demo.mp4",
      "quality": "unavailable",
      "local_path": "attachments/dbde7b68a879/videos/repair-56f6dd2067d41162868d.mp4",
      "note": "无1080p且无720p，未交付更低清晰度",
      "url": "https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/media/2026/05/insforge-vs-supabase-final-demo.mp4",
      "title": "",
      "status": "invalid_or_wrong_resolution",
      "bytes": 4853657,
      "reused": true,
      "content_type": "video/mp4",
      "valid": true,
      "height": 822,
      "width": 1080,
      "duration": "51.166667",
      "retried_at": "2026-10-20T17:40:15Z"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/archive/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/what-is-mcp/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/mlops-crash-course-part-1/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/rl-course-part-1/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/membership"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/diffusion-models-part-2/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/contact/"
    },
    {
      "type": "internal",
      "href": "https://www.dailydoseofds.com/faq/"
    },
    {
      "type": "external",
      "href": "https://dailydoseofds.github.io/ai-engg-book/"
    },
    {
      "type": "external",
      "href": "https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view"
    },
    {
      "type": "external",
      "href": "https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view"
    },
    {
      "type": "external",
      "href": "https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view"
    },
    {
      "type": "external",
      "href": "https://github.com/InsForge/InsForge"
    },
    {
      "type": "external",
      "href": "https://x.com/intent/tweet?text=How+We+Cut+Our+Claude+Code+Token+Usage+2.8x%21&url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/_avichawla"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:24:45Z",
  "source_url": "https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/",
  "delivery_status": "unverified",
  "discovery_status": "short_or_dynamic",
  "missing_reason": "正文过短或动态页面，未确认完整",
  "source_body_markdown": "[ Skip to main content  ](https://www.dailydoseofds.com/p/how-we-cut-our-claude-code-token-usage-2-8x/#sx-main)\n[ ![Daily Dose of Data Science](https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2025/12/dailyds-logo-transparent-1.png) ](https://www.dailydoseofds.com)\n  * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n  * [ Archive ](https://www.dailydoseofds.com/archive/)\n  * Guidebooks \n    * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n[ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n[ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n[ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n[ Courses ](https://www.dailydoseofds.com/)\n[ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n[ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n[ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n[ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n  * Courses \n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n[ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n[ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n[ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n[ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n[ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n[ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n  *     * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n[ Archive ](https://www.dailydoseofds.com/archive/)\nGuidebooks \n      * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n      * [ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n      * [ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n      * [ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n      * [ Courses ](https://www.dailydoseofds.com/)\n      * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n      * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n      * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n      * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n      * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\nCourses \n      * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n      * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n      * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n      * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n      * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n      * [ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n      * [ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n      * [ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n\n\nSign In  [ Get Started ](https://www.dailydoseofds.com/membership)\n/\n  * [ Newsletter ](https://dailydoseofds.github.io/ai-engg-book/)\n  * [ Archive ](https://www.dailydoseofds.com/archive/)\n  * Guidebooks \n    * [ MCP Guidebook ](https://www.dailydoseofds.com/what-is-mcp/)\n    * [ Agents Guidebook ](https://drive.google.com/file/d/1Th8mN_IF7Ttc8bI_OLtUuQ7Mjx3aJ6Hi/view)\n    * [ AI Engineering Guidebook ](https://drive.google.com/file/d/1_s2UaD7tEPECjgC5YMOa1LIOB9HUWFO-/view)\n    * [ DS Guidebook ](https://drive.google.com/file/d/1ZunUHwkD2Ut0_LrgDTDmlQRQkfT2lkVf/view)\n    * [ Courses ](https://www.dailydoseofds.com/)\n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n    * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n    * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n    * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n    * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n  * Courses \n    * [ MLOps/LLMOps Course ](https://www.dailydoseofds.com/mlops-crash-course-part-1/)\n    * [ Reinforcement Learning Course ](https://www.dailydoseofds.com/rl-course-part-1/)\n    * [ AI Agents Course ](https://www.dailydoseofds.com/ai-agents-crash-course-part-1-with-implementation/)\n    * [ MCP Course ](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-1/)\n    * [ RAG Systems Course ](https://www.dailydoseofds.com/a-crash-course-on-building-rag-systems-part-1-with-implementations/)\n    * [ LLM and Fine-tuning ](https://www.dailydoseofds.com/bi-encoders-and-cross-encoders-for-sentence-pair-similarity-scoring-part-1/)\n    * [ Classical ML and Deep Learning ](https://www.dailydoseofds.com/where-did-the-assumptions-of-linear-regression-originate-from/)\n    * [ Engineering Best Practices ](https://www.dailydoseofds.com/8-fatal-yet-non-obvious-pitfalls-and-cautionary-measures-in-data-science/)\n  * Sign In \n\n\nApr 21, 2026  Claude \n#  How We Cut Our Claude Code Token Usage 2.8x! \n...using Karpathy's context engineering principles! \n![Avi Chawla](https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/size/w400/2026/03/avi-google.jpg)\nAvi Chawla \n👉\n* * *\nMCPMark V2 benchmarks revealed something counterintuitive.\nWhen Claude moved from Sonnet 4.5 to Sonnet 4.6, backend token usage through Supabase’s MCP server went up, from 11.6M to 17.9M tokens across 21 database tasks.\nThe model got smarter, but the backend token usage actually increased.\n![](https://substackcdn.com/image/fetch/$s_!9IL1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81acd452-663f-4b8f-a688-367aa08bf46e_1346x615.png)\nThe reason is subtle, and it has nothing to do with the model.\nInstead, it has to do with how the backend exposes info to the agent. When context is incomplete, a more capable model doesn’t just skip the gap.\nIt spends more tokens reasoning about the gap, runs more discovery queries, and retries more frequently. So the missing context doesn’t disappear with a better model. It gets more expensive.\nLet’s look at why backends are a token sink for agents, what an alternative architecture looks like, and what the cost difference is on a real project.\n* * *\n### **Why Supabase’s MCP server wastes tokens**\nSupabase is a great backend. But it wasn’t designed to be operated by AI agents, and the MCP server that was added later inherits that limitation.\nThree specific mechanisms cause the token bloat.\n#### **1) Documentation retrieval returns everything**\nWhen CC needs to set up Google OAuth through Supabase, it invokes the `search_docs` MCP tool.\nSupabase’s implementation returns full GraphQL schema metadata on every call, which has 5-10x more tokens than the agent actually needs.\n![](https://substackcdn.com/image/fetch/$s_!Dqs9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0eb100fd-2464-4705-b406-0c427e4d3cef_1317x657.png)\nIf the agent asked for OAuth setup instructions, it got the entire authentication docs, including sections on email/password, magic links, phone auth, SAML, and SSO.\nThis happens on every `search_docs` call, like database queries, storage configuration, and edge function deployment.\nEach call dumps the full metadata for that entire domain. Across a session where the agent sets up auth, database, storage, and functions, the docs overhead alone can account for thousands of wasted tokens.\n#### **2) No visibility into backend state**\nWhen you use Supabase as a human dev, you open the dashboard and see everything at a glance, like active auth providers, tables, RLS policies, configure storage buckets, deployed edge functions, etc.\nAn agent can’t see the dashboard.\nSupabase’s MCP server does expose some state through individual tools like `list_tables` and `execute_sql`, but there’s no way to ask “what does my entire backend look like right now?” and get one structured response.\n![](https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png)\nSo the agent pieces it together through multiple calls, each call returns a partial view, and some info (like which auth providers are configured) isn’t available through MCP at all.\nThis fragmented discovery process costs tokens, and the agent often needs several attempts because the information comes back incomplete or in a format that requires further queries to interpret.\n#### **3) No structured error context**\nWhen something goes wrong (and it will, because the agent is guessing), Supabase returns raw error messages. It could be a 403 from an RLS denial, a 500 from a misconfigured edge function, etc.\nA human dev would look at it, check the Supabase dashboard, cross-reference with the logs, and fix the issue.\nThe agent doesn’t have that path. It gets the error message, reasons about what might have caused it, and tries a fix.\nIf the fix is wrong, it retries. Each retry re-sends the entire conversation history and compounds the token cost.\n* * *\nThese three mechanisms (doc overhead, state discovery, error retry loops) compound fast.\nA model that reasons more extensively, like Sonnet 4.6, makes each exploration step more thorough and more expensive.\nThat’s why the token gap widened from Sonnet 4.5 to 4.6, and it’ll likely widen further with each new model release.\n* * *\n### **What “backend context engineering” should look like**\nThe fix isn’t switching to a worse model.\nIt’s giving the agent a structured backend context so it doesn’t have to explore and guess.\nThis is what Karpathy means by context engineering: “the delicate art and science of filling the context window with just the right information for the next step.”\nHe explicitly includes tools and state as part of that context. Most people apply the idea to prompts and RAG retrieval.\nBut the backend is part of the context window too, and right now, it’s the part almost nobody is optimizing.\nTo see what this looks like in practice, [**InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com) (open source, Apache 2.0) implements exactly this approach.\n![](https://substackcdn.com/image/fetch/$s_!PEUl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda0a801f-cb14-48b6-b5d7-a2c35541fd54_910x847.png)\nIt provides the same primitives as Supabase (Postgres with pgvector, auth, storage, edge functions, and realtime) but structures the information layer so agents can consume it efficiently.\nThe key architectural difference is how it delivers context to Claude Code.\nThree layers work together:\n  * Skills for static knowledge.\n  * CLI for direct backend operations.\n  * MCP for live state inspection\n\n\nEach layer solves a different problem and reduces tokens for a different reason.\n#### **1) Skills: static knowledge with zero round-trips**\nInsForge’s primary approach for knowledge is Skills. They load directly into the agent’s context at session start, so the SDK patterns, code examples, and edge cases for every backend operation are available without any tool calls.\nSkills also use progressive disclosure, wherein only the metadata (name, description, ~70-150 tokens per skill) loads initially.\nThe full skill content loads only when the agent determines it matches the current task. This means you can have 100+ skills installed without context bloat, which isn’t possible with MCP’s all-or-nothing schema loading.\nFour skills cover the full stack, each scoped to a specific domain:\n![](https://substackcdn.com/image/fetch/$s_!6aBy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1957045d-15e4-4db8-a7f8-c93282290b66_1128x650.png)\n  * `insforge` for frontend code that talks to the backend.\n  * `insforge-cli` for backend infrastructure management\n  * `insforge-debug` for structured error diagnosis across common failures like auth errors, slow queries, edge function failures, RLS denials, deployment issues, and performance degradation)\n  * `insforge-integrations` for third-party auth providers (Clerk, Auth0, WorkOS, Kinde, Stytch).\n\n\nInstall all four with one command:\n\n```\nnpx skills add insforge/insforge-skills\n```\n\n#### **2) CLI for direct execution**\nFor actually executing backend operations (creating tables, running SQL, deploying functions, managing secrets), the InsForge CLI is the primary interface.\nEvery command supports `--json` for structured output, `-y` to skip confirmation prompts, and returns semantic exit codes so agents can detect auth failures, missing projects, or permission errors programmatically.\nThis is helpful because Claude Code can pipe CLI output through `jq`, `grep`, and `awk` in ways that would require multiple sequential MCP tool calls.\nThese are some example operations the agent actually runs:\n\n```\n# Inspect backend state (run first to discover what's configured)\nnpx @insforge/cli metadata --json\n\n# Database operations\nnpx @insforge/cli db query \"CREATE TABLE posts (...)\" --json\nnpx @insforge/cli db policies  # inspect existing RLS policies\n\n# Edge functions\nnpx @insforge/cli functions deploy my-handler\nnpx @insforge/cli functions invoke my-handler --data '{\"action\":\"test\"}' --json\n\n# Storage\nnpx @insforge/cli storage create-bucket documents --json\nnpx @insforge/cli storage upload ./file.pdf --bucket documents\n\n# Frontend deployment\nnpx @insforge/cli deployments env set VITE_INSFORGE_URL https://...\nnpx @insforge/cli deployments deploy ./dist --json\n\n# Diagnostics\nnpx @insforge/cli diagnose db --check connections,locks,slow-queries\n```\n\nThe agent parses the JSON and handles errors based on exit codes.\n#### **3) MCP tools for live backend state**\nMCP is still useful, but for a narrower purpose, like inspecting the current state of your backend when that state is changing.\nInsForge’s MCP server exposes a lightweight `get_backend_metadata` tool that returns a structured JSON with the full backend topology in a single call:\n\n```\n{\n  \"auth\": {\n    \"providers\": [\"google\", \"github\"],\n    \"jwt_secret\": \"configured\"\n  },\n  \"tables\": [\n    {\"name\": \"users\", \"columns\": [\"id\", \"email\", \"created_at\"], \"rls\": \"enabled\"},\n    {\"name\": \"posts\", \"columns\": [\"id\", \"title\", \"body\", \"author_id\"], \"rls\": \"enabled\"}\n  ],\n  \"storage\": { \"buckets\": [\"avatars\", \"documents\"] },\n  \"ai\": { \"models\": [{\"id\": \"gpt-4o\", \"capabilities\": [\"chat\", \"vision\"]}] },\n  \"hints\": [\"Use RPC for batch operations\", \"Storage accepts files up to 50MB\"]\n}\n```\n\nIn one call and ~500 tokens, the agent knows the full backend topology. The `hints` field provides agent-specific guidance that reduces incorrect API usage.\nThe key design choice here is that MCP is used for state inspection (which changes as the agent works), not for documentation retrieval (which doesn’t).\nThis inverts the typical usage pattern and is the main reason InsForge consumes far fewer tokens than Supabase on equivalent tasks.\n* * *\n### Supabase vs Insforge: Build DocuRAG with Claude Code\nTo make this concrete, we built the same DocuRAG app using Claude Code.\nUsers sign in via Google OAuth, upload PDFs, the system chunks and embeds the text (text-embedding-3-small, 1536 dimensions), stores the vectors in pgvector, and users ask natural-language questions answered via GPT-4o.\nThis touches nearly every backend primitive at once: user auth, file storage, a documents table, vector embeddings, embedding generation, chat completion, a retrieval edge function, and RLS to isolate each user’s documents.\nHere's the setup for each.\n#### Supabase\n  * Create a Supabase account and create a new project.\n  * Connect the MCP server to Claude Code and authenticate:\n\n\n```\nclaude mcp add --scope project --transport http supabase \\\n  \"https://mcp.supabase.com/mcp?project_ref=<your-project-ref>\"\n\nclaude /mcp\n```\n\n  * Install Supabase's Agent Skills (marked as “Optional” in Supabase's official setup):\n\n\n```\nnpx skills add supabase/agent-skills\n```\n\nThis installs two skills:\n  * `supabase`: broad catch-all skill covering Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues, client libraries (supabase-js, @supabase/ssr), SSR integrations (Next.js, React, SvelteKit, Astro, Remix), CLI, MCP, schema changes, migrations, and Postgres extensions\n  * `supabase-postgres-best-practices`: Postgres performance optimization across 8 categories\n\n\nSupabase ships one broad skill that triggers on \"any task involving Supabase,\" plus a specialized Postgres optimization skill. When the `supabase` skill activates, all its content loads because the trigger conditions cover almost the entire product surface.\n#### Insforge\n  * Create an Insforge account and create a new project (you can also self-host and run it fully locally using Docker Compose).\n  * Install all four Skills (primary documentation and diagnostic layer):\n\n\n```\nnpx skills add insforge/insforge-skills\n```\n\nThis installs `insforge` (SDK patterns), `insforge-cli` (infrastructure commands), `insforge-debug` (failure diagnostics), and `insforge-integrations` (third-party auth providers). Total metadata cost: ~714 tokens at session start.\n  * Link the CLI to your project (primary execution layer):\n\n\n```\nnpx @insforge/cli link --project-id <project-id>\n```\n\nInsForge ships four narrowly scoped skills, each covering a specific domain.\n  * When you're writing frontend code, only `insforge` activates.\n  * When you're creating tables, only `insforge-cli` activates.\n  * When something breaks, only `insforge-debug` activates.\n\n\n* * *\nThe prompt is nearly identical for both sessions, with one key difference.\n  * Supabase:\n\n\n```\nBuild a chat with document app called DocuRAG.\nIt will be a typical RAG setup where a user\ncan upload a document. It will be chunked, embedded,\nand stored in a vector DB. Once done, a user can ask\nquestions about the document. The engine will retrieve\nthe relevant chunks after embedding the query. Finally,\nit will generate a coherent response using GPT-4o based\non the query and the retrieved context. Add Google OAuth.\nUse Supabase as the backend and LLMs/embedding models via\nthe OpenAI API. Build frontend in next.js.\n```\n\n  * InsForge:\n\n\n```\nBuild a chat with document app called DocuRAG.\nIt will be a typical RAG setup where a user\ncan upload a document. It will be chunked,\nembedded, and stored in a vector DB. Once done,\nA user can ask questions about the document.\nThe engine will retrieve the relevant chunks\nafter embedding the query. Finally, it will\ngenerate a coherent response using GPT-4o based on\nthe query and the retrieved context. Add Google OAuth.\nUse Insforge as the backend and also for the model\ngateway. Build the front-end in Next.js.\n```\n\nThe Supabase prompt says \"LLMs/embedding models via the OpenAI API\" (two systems to wire). The InsForge prompt says \"also for the model gateway\" (one system).\nWe ran both sessions side by side and recorded the full build. Here’s the side-by-side video showing what happened from prompt to working app.\nIt also showcases the final output from both sessions, built on two different backends.\n> _One important thing: Supabase required manual Google OAuth setup outside of Claude Code. We had to navigate to Google Cloud Console, create an OAuth 2.0 client ID, configure the consent screen, add our email as a test user, copy the Client ID and Client Secret, then paste it into Supabase’s dashboard. This was not required in Insforge._\nBefore diving into the session-specific details, here’s what the numbers looked like at the end:\n![](https://substackcdn.com/image/fetch/$s_!mNxY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98ad82dc-4322-4a05-a9de-7aaa3b39ab96_1491x526.png)\n  * **Supabase:** 10.4M tokens; $9.21 Cost with 12 user messages (10 error reports)\n  * **InsForge:** 3.7M tokens; $2.81 Cost, with 1 user messages (0 error reports)\n\n\nNow let’s look at what actually happened in each session.\n> To analyze both sessions objectively, we exported the full Claude Code session history from both runs (as JSONL files) and fed them to a separate Claude instance. The analysis below, including tool call counts, error sequences, and token breakdowns, comes from parsing those session logs.\n* * *\n#### Supabase (consumed 10.4M tokens with $9.21 cost)\nThe initial build went smoothly.\nThe agent loaded the `supabase` skill, discovered the backend state via MCP tools (`list_tables`, `list_extensions`, `execute_sql`), scaffolded the Next.js project, created the database schema, wrote two edge functions (`ingest-document` and `query-document`), and deployed everything. The build passed.\n![](https://substackcdn.com/image/fetch/$s_!O-Um!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ebb77a-eadc-416a-af93-37dcd27e063e_895x503.png)\n##### **First problem: login didn’t work**\nWhen we tried to sign in with Google OAuth, the app threw an error. The agent had wired the authentication using the wrong Supabase client library for Next.js.\n![](https://substackcdn.com/image/fetch/$s_!EkBQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdce4221f-cad3-4f4b-8a57-139c284cc06a_899x358.png)\nIn Next.js, the OAuth callback runs on the server, but the agent used a client-side library that stores login state in the browser. The browser state isn’t available on the server, so the login flow broke.\nThe agent fixed this by switching to a different library (`@supabase/ssr`), rewriting how the app handles login sessions, and rebuilding.\n![](https://substackcdn.com/image/fetch/$s_!jS6F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd00cc-1593-48d0-840e-8ded923c38fa_920x742.png)\n##### **Document upload failed (took 8 turns to fix)**\nAfter the login was fixed, we tried uploading a document. The edge function returned an error, we reported it, it tried a fix, failed, then we tried again, and it returned the same error. This cycle repeated 8 times:\n![](https://substackcdn.com/image/fetch/$s_!2gie!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5d3e19b-67b7-4f57-97a7-03d6d2826bf3_1330x976.png)\n  * The agent tried adding auth headers manually → Same error.\n  * Redeployed with extra logging to see what was happening → Same error.\n  * Tried showing the real error message instead of the generic one → Different error (now a network/CORS issue).\n  * Fixed the CORS issue → Back to the original error.\n  * Tried a different way of reading the user’s login token → Same error.\n  * Tried yet another authentication approach → Same error.\n\n\nIn plain terms, Supabase has a security layer that checks login tokens before the edge function code even starts. The new auth library the agent installed (to fix the first problem) was sending a token format that this security layer didn’t recognize.\nSo every request was getting rejected at the door before the function code had a chance to run. That’s why none of the code-level fixes worked.\n![](https://substackcdn.com/image/fetch/$s_!arYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ab298da-ad23-4619-9382-ad80c0ce9430_1008x445.png)\nThe agent spent 8 rounds fixing code-level issues when the problem was upstream of the code entirely.\nThe solution was simple: turn off the platform’s automatic token checking and handle authentication inside the function code instead.\nIt took 8 attempts because every time, it saw a 401 (unauthorized) error, but nothing told it where the rejection was coming from. Without that signal, it kept attempting to fix the code.\nBut during this debugging process, the edge function was redeployed 8 times (on top of 2 initial deploys during the build). Each redeployment, log check, and retry re-sent the entire growing conversation history, compounding the token cost.\nFinal session stats involved:\n  * 12 user messages (10 were error reports)\n  * 135 tool calls\n  * 30+ MCP tool calls.\n  * 10.4M tokens\n  * $9.21 Cost\n\n\n#### Insforge (consumed 3.7M tokens with $2.81 cost)\nThe InsForge session completed without any errors.\nThe agent started by inspecting the backend state.\nIts first action was `npx @insforge/cli metadata --json`, which returned a structured overview of the project, including the configured auth providers, existing tables, storage buckets, available AI models, and real-time channels.\n![](https://substackcdn.com/image/fetch/$s_!l2tM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fecf1abce-4368-4c05-8796-86243a419818_962x739.png)\nThis gave the agent a complete picture of what it was working with before it wrote any code.\nIn the Supabase session, the agent needed multiple MCP calls (`list_tables`, `list_extensions`, `execute_sql`) to piece together a similar understanding, and even then, it missed critical details like the `verify_jwt` behavior.\nThe schema setup ran through 6 CLI commands, all of which succeeded.\n![](https://substackcdn.com/image/fetch/$s_!39CU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F155e5f22-a4fc-47ac-89b3-3fd888e68a3b_942x896.png)\nThe agent enabled pgvector, created the `documents` and `chunks` tables (with a `vector(1536)` column), enabled Row Level Security on both, created the access policies, and set up the `match_chunks` similarity search function.\nEach command returned structured output confirming what happened, so the agent could verify each step before moving to the next.\nThe auth and edge function problems from the Supabase session didn't occur here.\nThe `insforge` skill included the correct client library patterns for Next.js, so the agent wired authentication correctly on the first attempt.\nAnd the two edge functions (`embed-chunks` and `query-rag`) both deployed and ran without errors because the model gateway for embeddings and chat completion was part of the same backend.\n![](https://substackcdn.com/image/fetch/$s_!t9Us!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84b43039-c9e9-457f-83f7-cbe36d3ed9bd_1133x858.png)\nThe agent didn't need to integrate OpenAI separately, manage a second API key, or deal with cross-service authentication.\nThe metadata response already listed `text-embedding-3-small` and `gpt-4o` as available models, so the agent called them directly through the InsForge SDK.\nFinal session stats involved:\n  * 1 user message\n  * 77 tool calls\n  * 0 MCP tool calls.\n  * 3.7M tokens\n  * $2.81 Cost\n\n\nWe asked Claude to generate a side-by-side summary and here’s what it produced:\n![](https://substackcdn.com/image/fetch/$s_!rIU2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33ba5d8a-940e-4328-b0c5-0dae6fa1690e_1528x1188.png)\nThe Supabase session’s token cost was driven by the error retry loop.\nEach of the 8 edge functions redeploys re-sent the entire conversation history (which grew with each attempt).\nThe agent checked logs 6 times, redeployed functions 8 times, and tried 6 different authentication strategies before finding the root cause.\nNone of this was the agent’s fault. The Supabase platform’s `verify_jwt` gate was rejecting the token before the function code ran, and the logs didn’t distinguish between platform-level and code-level rejections.\nThe Insforge session avoided these problems because the skills loaded the correct auth patterns from the start, and the CLI gave structured feedback on every operation.\n* * *\nThis comparison highlights a problem that goes beyond Supabase specifically.\nMost backends were designed for human developers who can read dashboards, interpret ambiguous errors, and mentally track state across multiple services.\nWhen an agent takes over that workflow, the assumptions break. The agent can’t see the dashboard. It can’t tell where an error came from if the logs don’t say. And every time it guesses wrong, the token cost compounds.\n![](https://substackcdn.com/image/fetch/$s_!yYN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc43dc6d5-a696-45d5-8407-14c626bc0cc8_1346x692.png)\n[**InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com) is built around a different set of assumptions.\n  * The backend exposes its state through structured metadata and the CLI gives the agent programmatic control with clear success/failure signals.\n  * The skills encode the correct patterns so the agent doesn’t have to discover them through trial and error.\n  * And the model gateway keeps LLM operations inside the same backend, which removes the cross-service integration issues that caused most of the Supabase session's debugging.\n\n\nInsForge is fully open source under Apache 2.0 and you can self-host it via Docker. The code, the skills, and the CLI are all on its GitHub repo: [**https://github.com/InsForge/InsForge**](https://github.com/InsForge/InsForge?ref=dailydoseofds.com)**.**\nThanks for reading!\nPublished on Apr 21, 2026 \nComments \nShare \nCopy link [ Share to X ](https://x.com/intent/tweet?url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F&text=How%20We%20Cut%20Our%20Claude%20Code%20Token%20Usage%202.8x!) [ Share to Facebook ](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F) [ Share to Linkedin ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.dailydoseofds.com%2Fp%2Fhow-we-cut-our-claude-code-token-usage-2-8x%2F)\nCopied \n[ Previous  Diffusion LLMs from the Ground Up: Training, Inference, and Practical Engineering  ](https://www.dailydoseofds.com/diffusion-models-part-2/) [ Next  Foundations of Reinforcement Learning  ](https://www.dailydoseofds.com/rl-course-part-1/)\n[ ![Daily Dose of Data Science](https://storage.ghost.io/c/3f/df/3fdf6ed2-17ac-4b12-a693-8078bd13e748/content/images/2025/12/dailyds-logo-transparent-1.png) ](https://www.dailydoseofds.com)\nA daily column with insights, observations, tutorials and best practices on python and data science. Read by industry professionals at big tech, startups, and engineering students. \n  * Menu \n  * [ Contact ](https://www.dailydoseofds.com/contact/)\n  * [ FAQ ](https://www.dailydoseofds.com/faq/)\n\n\n[Daily Dose of Data Science](https://www.dailydoseofds.com) © 2026 \n[ ](https://x.com/_avichawla \"X \\(Formerly Twitter\\)\")\n",
  "body_base_path": "attachments/dbde7b68a879/pages/",
  "body_markdown_path": "attachments/dbde7b68a879/pages/archived-body.md",
  "local_html": "attachments/dbde7b68a879/pages/archived-body.html",
  "body_source": "prior_capture"
}