Large-context code
Find out how much code fits on your plan, import a repo instead of pasting it, put your question last, and cut repeat costs on the API.
- How Do You Cut the Cost of Repeat Questions About a Large Codebase? On the Gemini API, put the large code at the very start of each request and keep it identical, so you hit Gemini's implicit cache. Level 4: Multi-tool systems
- 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. Level 2: Context
-
Can You Paste a Whole Codebase into Gemini? Only on some plans, and pasting isn't the best way. Level 3: Workflows
- 1Repo or folder per chat
- 5,000Files at most
- 100 MBTotal size at most
-
Where Should Your Question Go in a Long Gemini Prompt? At the end, after all the material. Level 3: Workflows
- 1Role, rules, output formatat the very start or in the system instruction
- 2All the code or documentswrapped in consistent tags
- 3"Based on the information above"a bridge to the question
- 4One specific questionlast
Big window, real limits
A 1 million token window lets you ask questions that cross a whole service, but a successful upload doesn't mean all of it was used. Google's upload limit of 100 MB is far more text than 1 million tokens, which is only about 4 MB at Google's estimate of 4 characters per token. So measure first. This lesson shows how to estimate your repo's size, how to arrange a long prompt, and what to do when you're asking many questions.
App or API?
In the app, you import a folder and your plan's limits apply. On the API, you pay per token, you can count tokens exactly with count_tokens, and caching can reduce the cost of repeat questions. Budgets differ by model too. On Gemini 4 Argon, input, thinking and output share one 1 million token window, while Gemini 3 and 2.5 have separate input and output budgets.
How big is Gemini's context window?
In the app, 32k tokens with no plan, 128k on Google AI Plus, and 1 million on Google AI Pro and Ultra. On the API, Gemini 4 Argon has a 1 million token window shared across input, thinking and output.
How many lines of code fit in Gemini?
Google's estimates differ. Its app help says 1 million tokens is roughly 30,000 lines of code, and its API docs say 50,000 lines at 80 characters each. Measure your own code by dividing its size in bytes by 4.
Does Gemini read my whole codebase?
Only what fits in the context window. Google warns that going over can cause answers to miss details spread through large files, and an upload can succeed even if it's too big for your plan's window. Ask Gemini which folders it didn't read.