Six Codebases, 8.5M Tokens: What Fits in a 200k Window

🔧 AI Tools 2026-11-26 7 min read
Six Codebases, 8.5M Tokens: What Fits in a 200k Window

Pasting a repository into a coding agent usually spends the window on changelogs, translated docs and vendored test data before it reaches a single source file.

📜 Table of Contents

📖 Keep reading

Six well-known Python codebases, 7,609 text files, 8,465,030 tokens counted with cl100k_base. A 200k-token window swallows requests (144,568 tokens) and httpx (184,822) whole, covers 76% of Flask, half of Typer, 7.4% of Pydantic and 4.2% of FastAPI. Strip tests, documentation and changelogs and five of the six fit inside the same window.

None of that is about context length. It is about what a repository actually contains, which is rarely what the person pasting it expects.

How it was counted

The six repos

repositorytext filestokenscodetestsdocschangelog
psf/requests81144,56837.2%28.1%20.0%11.4%
encode/httpx97184,82234.5%37.8%19.1%7.6%
pallets/flask191263,09330.4%23.7%37.3%7.0%
tiangolo/typer754388,73832.7%30.2%21.9%12.3%
pydantic/pydantic3,4742,718,73751.8%33.6%6.9%3.9%
fastapi/fastapi3,0124,765,0725.3%14.8%73.4%4.6%

Two of the six are only a couple of hundred thousand tokens of actual code. FastAPI is 4.77 million tokens and 5.3% of them are Python: the repository is mostly translated documentation, and a person who says "paste the FastAPI repo" is mostly pasting prose in twenty languages.

Documentation is the biggest pile in three of six

FastAPI 73.4%, Flask 37.3%, Typer 21.9%. Pydantic inverts it: 51.8% code, 6.9% documentation. If you are trying to give an agent the implementation, the ratio decides whether the window is spent on behaviour or on usage examples.

File counts tell a different story from tokens. FastAPI's docs are 54.6% of its files but 73.4% of its tokens; Pydantic's 3.2% of files carry only 6.9% of tokens.

One file can be bigger than the window

filetokens
fastapi docs/en/docs/release-notes.md219,660
pydantic HISTORY.md105,241
fastapi fastapi/routing.py52,770
typer docs/release-notes.md47,640
flask CHANGES.rst18,385
requests tests/test_requests.py25,274

FastAPI's release notes are 219,660 tokens on their own, more than a 200k window and 4.6% of the entire repository. A recursive glob that grabs every .md file will pick up that one file first, and the session ends before the source code shows up. Excluding changelogs lifts Flask's coverage from 76.0% to 81.7%; for FastAPI it barely moves, 4.2% to 4.4%, because the docs are the bulk, not the changelog.

Tests are a third of two repos

httpx 37.8%, Pydantic 33.6%, Typer 30.2%, requests 28.1%, Flask 23.7%, FastAPI 14.8%. Test code is valuable when you are changing behaviour and dead weight when you are asking "how does this module work". The bucket is cheap to exclude: path matching on test, tests or conftest catches nearly all of it.

Pydantic is the extreme case. Its tests are 913,973 tokens, and one file inside them, tests/benchmarks/corpus/google-genai/google/genai/types.py, is 90,030 tokens of vendored generated code. That single file is 45% of a 200k window and has nothing to do with how Pydantic works.

What a 200k window covers

repositoryeverythingminus changelogscode only1M window, everything
psf/requests138.3%156.1%371.5%691.7%
encode/httpx108.2%117.1%313.3%541.1%
pallets/flask76.0%81.7%250.3%380.1%
tiangolo/typer51.4%58.6%157.3%257.2%
pydantic/pydantic7.4%7.7%14.2%36.8%
fastapi/fastapi4.2%4.4%78.8%21.0%

Read the code-only column and the picture changes completely. Five of the six codebases fit inside 200k tokens once tests, docs, changelogs and config are dropped: requests at 53,835 tokens, httpx at 63,827, Flask at 79,889, Typer at 127,185, FastAPI at 253,681, which is 1.27 windows and needs one cut. Pydantic is the exception at 1,407,038 tokens of code, seven windows of source.

A 1M window covers four of six repositories completely and 21% of FastAPI. It does not cover Pydantic, which is 2.72M tokens, and it does not cover the case where the answer lives in a file that was never opened.

The workflow that holds up

  1. Count before pasting. The script below prints per-file tokens and a bucket summary, and takes about two seconds on a 3,000-file repository.
  2. Drop changelogs and generated code first. That is the largest single win per line deleted, and both are trivially identifiable by filename.
  3. Drop tests when the question is "how does this work", keep them when the question is "why does this fail".
  4. Paste by file, not by directory, on anything past 200k tokens of code. FastAPI's largest source file is 52,770 tokens; you can hold a whole module and still have room to talk.
  5. Leave headroom. A 200k window holding 190k tokens of repo leaves nothing for the conversation, the tool output or the patch the model writes back.

The counting script

import os, sys, tiktoken
enc = tiktoken.get_encoding("cl100k_base")
EXT = {".py",".js",".ts",".tsx",".go",".rs",".java",".rb",".c",".h",".cpp",
       ".md",".rst",".txt",".toml",".cfg",".yml",".yaml"}
SKIP = {"node_modules", ".git", "vendor", "dist", "build", ".venv"}

def bucket(rel):
    p = rel.lower()
    if any(k in os.path.basename(p) for k in ("changelog","changes","history","release-notes","news")):
        return "changelog"
    if any(k in p for k in ("/test","test_","_test","/tests/","conftest")):
        return "tests"
    if p.endswith((".md",".rst",".txt")) or "/docs/" in p:
        return "docs"
    return "code"

totals, per_file = {}, {}
for root, dirs, files in os.walk(sys.argv[1]):
    dirs[:] = [d for d in dirs if d not in SKIP]
    for f in files:
        if os.path.splitext(f)[1].lower() not in EXT:
            continue
        path = os.path.join(root, f)
        rel = os.path.relpath(path, sys.argv[1])
        try:
            text = open(path, encoding="utf-8", errors="ignore").read()
        except OSError:
            continue
        n = len(enc.encode(text, disallowed_special=()))
        b = bucket(rel)
        totals[b] = totals.get(b, 0) + n
        per_file[rel] = n

total = sum(totals.values())
print("total tokens", total, "files", len(per_file))
for b, n in sorted(totals.items(), key=lambda x: -x[1]):
    print("  %-9s %8d  %5.1f%%" % (b, n, 100.0 * n / total))
print("top files")
for rel, n in sorted(per_file.items(), key=lambda x: -x[1])[:10]:
    print("  %8d  %s" % (n, rel))

Same rules as the measurement above, and the top-files list is what finds the trap. On FastAPI it starts with release-notes.md at 219,660 tokens; on Pydantic with HISTORY.md at 105,241 and that vendored Google types file at 90,030.

Caveats worth stating

All counts use cl100k_base. Under a different tokenizer the totals and the fit percentages move by roughly 10 to 20%, which does not reorder the repositories but does change whether Typer lands at 51% or 60%.

Tarball contents are the published source, not a working checkout: no virtualenv, no build artefact, no data directory. A real developer's copy of these repositories carries more, sometimes much more, so treat these as lower bounds.

And none of this says a 1M window is unnecessary. It says the first move is not a bigger window but a smaller paste, and that the number deciding between them is countable in two seconds.

Related

Related Articles
2026-08-17
Best AI Coding Assistant for WordPress Developers 2026: 6 Tools for PHP, Hooks and Headless Builds
2026-07-24
Best Free AI Video Generators Without Watermark in 2026
2026-08-24
Best AI Coding Assistant for Freelancers in 2026: 6 Tools for Client Projects
2026-10-14
Best AI Answering Service for Dental Practices 2026: 5 Tools That Cover the Front Desk
2026-10-18
Best AI Meeting Notetaker in Eindhoven 2026: Dutch and English Standups
2026-08-20
Midjourney vs DALL-E vs Flux in 2026: Which AI Image Generator Should You Actually Pay For

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment