Context Builder

The context builder lets you select files from your repository, count their tokens, and export a structured context document for use with AI tools and LLM prompts.

Overview

When working with AI assistants you often need to provide repository context — relevant source files, configuration, and documentation. The context builder gives you a dedicated panel to curate that context: select files, see per-file and total token counts, and export everything as structured markdown.

Selecting Files

Navigate the file tree and add files to the context set. The panel shows each selected file with its path and estimated token count. You can reorder, add, or remove files at any time.

KeyAction
aAdd selected file to context
dRemove selected file from context
EnterPreview file contents
yCopy context to clipboard
EscClose context builder

Token Counting

Each file's token count is estimated using a word-based heuristic with a 1.3× multiplier to approximate subword tokenization. The total token count is displayed at the top of the panel so you can stay within your model's context window.

Token limits are configurable — set a maximum token budget and grüt warns you when the context exceeds it.

Export Format

When you copy or export the context, grüt produces structured markdown with a summary header and language-tagged code blocks:

# Context (3 files, 850 tokens)

## src/main.go
```go
package main
// ...
```

## internal/config/config.go
```go
package config
// ...
```

Security

File paths are validated against the repository root to prevent directory traversal. Only files within the current repository can be added to the context set.

Configuration Reference

[ai]
max_context_files = 20    # Maximum files in context set
max_context_tokens = 8000 # Maximum token budget
context_mode = "manual"   # Context selection mode: manual | smart
token_model = "gpt-4"     # Tokenizer model for estimation

Related