Why do coding agents repeat logic that already exists?

Coding agents repeat logic that already exists because they see a slice of the codebase at a time. An engineer carries a model of the whole codebase and knows where a piece of logic already lives. An agent without that model writes the logic again, often with different names and a different shape. Claktor finds repeated logic, even when it is not exact, so it can be written once. That makes the codebase smaller and cheaper to work on.

How much of a codebase fits in an agent's context?

Vendors advertise context windows of up to 1 million tokens. A codebase larger than the window cannot be read in one pass, and the window also has to hold the task, the tool output and the agent's own edits.

How big is your codebase in tokens?

13 open-source projects by lines of code and tokens 13 open-source projects by lines of code and tokens o200k tokens 100k 1M 10M 10k 100k 1M lines of code 1M token context window fd (Rust): 5,620 lines, 47,639 tokensfd httpx (Python): 8,827 lines, 64,070 tokenshttpx openauth (TS): 9,541 lines, 67,227 tokensopenauth flask (Python): 10,139 lines, 81,693 tokensflask fastify (JS): 12,681 lines, 106,444 tokensfastify llm (Python): 17,389 lines, 125,439 tokensllm just (Rust): 29,010 lines, 186,494 tokensjust hono (TS): 31,420 lines, 251,483 tokenshono ripgrep (Rust): 49,072 lines, 402,294 tokensripgrep sst (TS): 102,787 lines, 698,096 tokenssst opentui (TS): 240,615 lines, 2,068,588 tokensopentui rune (Rust): 286,574 lines, 3,506,393 tokensrune opencode (TS/TSX): 844,543 lines, 9,067,709 tokensopencode

Projects: fd, httpx, openauth, flask, fastify, llm, just, hono, ripgrep, sst, opentui, rune, opencode.

Measured on 14 November 2026 with claktor length 0.1.2. Production files only, as each repository's Claktor map defines them. Every line is counted, including blank lines and comments. Tokens are raw o200k tokens.

Across 13 open-source projects, a line is about 8 tokens. To estimate your codebase, multiply its line count by 8. A 1 million token window holds about 125,000 lines. Claude's tokenizer counts more, about 13 tokens for the same line, so a 1 million token Claude window holds about 75,000 lines.

Refactoring pays below that line too. Every agent task, CI run and pull request review reads code, and less code costs less each time.

Why not load more context?

More context costs more and works worse.

Input is billed per token, on every call. Accuracy also drops as input grows. Chroma tested 18 models and found their performance became less reliable as input length grew, even on simple tasks. In one test, prompts averaging about 113k tokens did worse than focused prompts of about 300.

Won't longer context windows fix this?

Transformers are built on attention, and no alternative has replaced it. Attention compares every token with every other token, so its cost grows with the square of the input (Attention Is All You Need, Table 1). Ten times the context is a hundred times the attention work. At about 8 tokens per line, a 10 million token window holds about 1.2 million lines.

How does that change the code agents write?

GitClear and GitKraken analyzed 623 million code changes from 2023 to 2026, reported by LeadDev. Duplicated blocks of five or more lines are up 81% on pre-AI levels. That count covers repeated lines only, so logic repeated with different names or syntax is on top of it. Changes that update code older than 12 months are down 74% since 2023. GitClear's CEO Bill Harding: "Every time you want something, AI creates a new package for it."

What does Claktor do about it?

Claktor parses the target and compares its syntax trees with fuzzy matching, so it finds logic that repeats even when names and syntax differ. A text search cannot find that. Claktor ranks what it finds by how much sharing would save and measures what each refactor removes. A smaller codebase costs less to read on every later task, for agents and for engineers.