Every codebase search and multi-file read contributes to the "Context Tax." In this lesson, we will learn how to budget tokens, estimate costs, and split giant system rules into lean, modular domain files.
When an AI agent scans a repository, it feeds the content of relevant files into the prompt context window. Because modern models charge per input token, reading 10 files recursively can easily consume 20,000 to 50,000 tokens per action.
Context tax is cumulative. As the chat grows longer, the agent re-sends the entire conversation history along with all read files:
Cost estimates are based on an average LLM developer pricing of $3.00 per million input tokens.
Instead of stuffing all style requirements, component guidelines, database schemas, and testing instructions into a single, massive AGENT.md file, adopt a **modular domain structure**:
AGENT.md): Keep this brief. Include general directives, build scripts, and pointers to domain rules..rules/ui-style.md): Detail Tailwind styles, CSS conventions, and React layout parameters. The agent only reads this when changing front-end assets..rules/database.md): Outline ORM setups, column schemas, and migration steps. The agent loads this only when executing database changes.How can a developer reduce the context tax and token cost when working with multi-file repository-level agents?
Let's code a workspace context estimator in Python! Write a helper function that reads a list of files with their sizes in characters, estimates the total token count (assuming 4 characters equal 1 token), and calculates the financial cost at a rate of $3.00 per 1 million tokens.
{ 'main.py': 800, 'style.css': 3400, 'schema.db': 12000 }).0.000003 ($3.00 / 1,000,000) to find the cost.$0.0123).Write this token budget calculator script in the workspace editor on the right!