📄 中文摘要
AI 编码代理在理解代码库时面临效率低下的问题,通常需要逐个文件进行探索,导致令牌消耗巨大。以 Claude Code、Codex 和 Gemini CLI 为例,简单的问题可能会消耗高达 45,000 个令牌。为了解决这一问题,开发了 codebase-memory-mcp 工具,它将代码库解析为持久的知识图谱,包括函数、类、调用链、导入和 HTTP 路由等信息,并通过 14 个 MCP 工具进行访问。现在,类似的问题只需约 200 个令牌,并且响应时间在 1 毫秒以内。
📄 English Summary
How I Cut My AI Coding Agent's Token Usage by 120x With a Code Knowledge Graph
AI coding agents face significant inefficiencies when understanding codebases, often exploring files one by one, leading to excessive token consumption. For instance, simple queries can consume up to 45,000 tokens with tools like Claude Code, Codex, and Gemini CLI. To address this issue, the codebase-memory-mcp tool was developed, which parses the codebase into a persistent knowledge graph that includes functions, classes, call chains, imports, and HTTP routes. This knowledge is then accessible through 14 MCP tools, allowing similar queries to cost around 200 tokens and respond in under 1 millisecond.