Adam Bandel


Code Context Builder

Aug 2025
Type: desktop
Code: 5k lines
Files: 35
Active: May 2025 to Aug 2025
Stack:
TypeScriptReactRustTauriSQLitetree-sitter
Tags:
aideveloper-toolsprompt-engineering

Overview

Code Context Builder is a keyboard-driven desktop app for building prompts out of source code for LLMs such as GPT-4 and Claude. You scan and index a project folder, pick files from the tree, and copy them out as one formatted prompt in one of several output formats, with a token count. Optional compression uses tree-sitter to parse the code and cut the token count while keeping its structure: function bodies collapse, and signatures stay.

Screenshots

Main Interface

Settings Modal

File Viewer

Problem

Once models could write several hundred lines of code across multiple files, getting accurate output out of them meant feeding them a lot of your codebase. This was before the CLI coding tools, so that meant going through the codebase, working out which files to include, and pasting them into a chat window one by one. Copying files by hand, it is easy to lose track of what is included and to go over the token limit without noticing.

I started with basic scripts that concatenated the codebase, and they turned into a Python and Tkinter tool I called Code_Formatter, with ignore and allow patterns, a view of the file tree, and token counting. I used that for about six months. It then went into PDK, and once I realized it was more useful on its own, I took it out again and made it this standalone Tauri app.

Approach

React handles the interface, and Rust does the file reading, parsing and token counting. The Tauri version is much faster than the Python one.

Stack

Challenges

Outcomes

It was the tool I used for about a year and a half to get code into models, using the top models through their chat interfaces instead of Cursor or the CLI tools of the time. I still use it, though not for coding. Now it is mostly for attaching the right personal and work notes to a prompt, and occasionally for getting code into high-end tools that have no CLI, such as GPT-5 Pro. For coding, it has run its course.

Implementation Notes

The compression system uses tree-sitter to parse source files into ASTs, then walks the tree to find the regions it can collapse:

// Compressor trait allows extensible language support
pub trait Compressor: Send + Sync {
    fn compress(&self, content: &str, options: &CompressionOptions) -> String;
}

// Python implementation collapses function bodies while preserving signatures
fn collapse_body(source: &str, node: Node, options: &CompressionOptions) -> String {
    // Preserve docstrings, collapse implementation
    // Result: def process(data: List[str]) -> Dict: ...
}

The file tree exposes its controls through useImperativeHandle, so parent components can expand, collapse and search it without prop drilling:

export interface FileTreeRef {
  expandAll: () => void;
  collapseAll: () => void;
  expandToLevel: (level: number) => void;
  focusSearch: () => void;
}

State is split between SQLite (projects, file cache, settings) and localStorage (UI preferences, selected files, expanded paths).

View on GitHub →


Related Posts