GeminiLarge-context codeLevel 2: Context

How Much Code Fits in Gemini's Context Window?

In the app, it depends on your plan: 32k tokens with no plan, 128k on AI Plus and 1 million on AI Pro and Ultra. Google's limits page says 1 million is roughly 30,000 lines of code or 1,500 pages. Its API docs say 50,000 lines at 80 characters each, so treat either as an estimate.

Prompt to copy
Estimate your repo's size from its root (Mac, Linux or Git Bash). This counts tracked files only, so ignored folders like `node_modules` are left out:

git ls-files -z | xargs -0 cat | wc -c

Divide the result by 4 to estimate tokens. Then compare with your window.

For an exact count on the API (Python, from Google's token docs):

total_tokens = client.models.count_tokens(
    model="gemini-3.8-flash",
    contents=prompt
)
print("total_tokens:", total_tokens.total_tokens)
  • No plan32k
  • AI Plus128k
  • Deep Think192k
  • AI Pro and Ultra1 million
Context windows in the Gemini app, in tokens. Source: Google's limits and upload help pages, checked November 6, 2026.
  • 30,000Lines of codein 1 million tokens
  • 1,500Pages of textin 1 million tokens
  • 4Characters per tokenroughly
Google's own estimates. Its API docs say 50,000 lines for the same window. Source: Google's limits and token docs, checked November 6, 2026.

Try it now

  1. 1Run the git ls-files command in your project root, and divide the result by 4.
  2. 2Compare that with your plan: 32,000, 128,000 or 1,000,000.
  3. 3If it doesn't fit, repeat the command on one folder, for example git ls-files -z src/api | xargs -0 cat | wc -c, until you have a set that does.
  4. 4You'll know you have the right set when it fits with room to spare and still includes every file your question touches.

Use it when

Before you upload a repo or a stack of files, or when an answer ignores something you know you sent. It's a one-minute check, and it tells you whether to send the whole thing or only a part.

Skip it when

For a few short files. They fit on any plan, so counting is a waste of time. It's also not a measure of what you'll spend in the app, since plan limits are based on compute rather than tokens alone.

Why it works

A token is about 4 characters, according to Google's token docs, and 100 tokens is roughly 60 to 80 English words. Code varies in its line lengths, which probably explains the two figures. On the API the budget also works differently by model. For Gemini 4 Argon, the docs say the 1 million token window is shared across input, thinking and output. For Gemini 3 and 2.5, input and output have separate budgets of 1 million and 64K. So on Argon, a huge input leaves less room for the answer. If input plus max_output_tokens is more than 1,048,576, the API caps output at the space that's left.

Example

Say the command prints 9,600,000 bytes. Divided by 4, that's about 2.4 million tokens, as an estimate. It won't fit in any app plan's window, even though at under 100 MB it's within the upload limit. You could split out the src/api folder, which might be 600,000 bytes or 150,000 tokens. That wouldn't fit on Plus either, but it fits easily on Pro. These are made-up numbers to show the math, so run it on your own repo.

Going further

Images, video and audio count too. On the API, Google's docs say an image of 384 pixels or less on each side costs 258 tokens, and larger ones are cut into tiles at 258 tokens each. Audio is 32 tokens a second. Video is about 100 tokens a second at default resolution and about 300 at high resolution. So screenshots in a big prompt are usually cheap, and a long video isn't. count_tokens returns input tokens only, so leave room for the answer yourself.

Common mistakes

  • Believing that 100 MB of upload limit means 100 MB of context. By Google's own estimate of 4 characters per token, 1 million tokens is only about 4 MB of text.
  • Budgeting all 1 million for input on Argon. Thinking and output share the same window.
  • Counting a single file and forgetting the chat history, which also takes up space.
  • Expecting Plus to take a mid-sized repo. 128k tokens is about 3,840 lines by Google's 30,000-line figure (arithmetic, not a Google number).

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course