Open-source tool turns codebases into token-cheap concept cards for AI agents

When an needs to understand a single function, it typically reads the entire file or greps the whole repo, which wastes a huge number of tokens — locating one in a 600-line file can cost around 14,000 tokens. RAG (splitting the repo into chunks, embedding them, and doing similarity search) was tried first, but chunk boundaries ignore code syntax: a function gets split across chunks, or a class definition ends up separated from its own methods. The agent received context, just not the right context, and sometimes invented call relationships that didn't actually exist.

The fix, called okf-generator, parses the AST (abstract syntax tree) instead of chunking raw text. Using across 18 s, it scans a codebase once and compiles it into typed 'concept cards' — one per function, class, or module — with resolved edges for calls, callers, and imports already attached. As a result, a single lookup needs only about 140 tokens of exact, typed context instead of roughly 14,000 tokens of raw file content.

Core extraction is and runs fully offline with no LLM call involved. It's released free under the MIT license, not for sale, shared in hopes it helps others building agent tooling, with feedback requested on where it breaks.

Key points

  • Reading a whole file to find one function/class can cost around 14,000 tokens
  • RAG's text-chunking approach ignores code syntax boundaries, splitting functions or separating classes from their methods
  • okf-generator instead parses the AST and precompiles 'concept cards' per function, class, and module
  • This cuts a typical lookup down to about 140 tokens of exact context — roughly a 100x reduction
  • Built on , supports 18 languages, runs offline and ally with no LLM call, released free under MIT
Read original