Skip to content

How AI Coding Tools Use Context Windows: What 3,177 API Calls Reveal

Problem

When I use AI coding tools like Cursor, GitHub Copilot, or Continue.dev, I often wonder: what exactly am I sending to the API? One time I got a token limit error when trying to refactor a simple function, and another time the AI missed obvious dependencies in my code.

I don’t know what context these tools are sending to the LLM, and I don’t know why different tools give me different results for the same task.

What happened?

I found a Reddit post where someone tracked 3,177 actual API calls from 4 different AI coding assistants. They logged every request to see what context each tool sends to the API.

The results surprised me. Different tools use wildly different strategies for selecting what goes into the context window. Some send entire files (even the parts you don’t need), others extract only specific functions, and the smartest ones build dependency chains by analyzing your imports.

Here’s what the research revealed:

ToolContext StrategyWhat Gets Sent
Tool AFull-file approachEntire source files, including unrelated code
Tool BFunction-centricOnly the function you’re editing
Tool CDependency-awareCurrent function + imports + callers
Tool DHybridFunctions + tests + related files

How Context Windows Work

The context window is just the amount of text an AI can “see” at once. Think of it like this:

┌─────────────────────────────────────────────┐
│ Your Codebase (10,000+ lines) │
└─────────────────────────────────────────────┘
┌──────────────────┐
│ AI Tool Filter │
└──────────────────┘
┌─────────────────────────────────────────────┐
│ Context Window (8,000-200,000 tokens) │
│ - What the AI actually sees │
│ - Determines response quality │
│ - Affects API costs │
└─────────────────────────────────────────────┘

The problem: your codebase is huge, but the context window has limits. The AI tool needs to decide what’s relevant.

Why This Matters

When I ask an AI to refactor a function, it needs to know:

  • The function I want to change
  • Functions that call my function (so it doesn’t break them)
  • Functions my function calls (its dependencies)
  • Type definitions and interfaces
  • Related tests

If the tool sends too little context, the AI misses dependencies. If it sends too much, I hit token limits or waste money on API calls.

The Four Strategies

1. Full-File Approach

Some tools send your entire file to the API. Even if you’re only editing one function.

What gets sent:

// Everything in auth.js - 500 lines
const multiply = (a: number, b: number): number => {
return a * b;
};
// + 495 lines of unrelated code
// + helper functions you don't need
// + comments and whitespace

Pros:

  • Simple to implement
  • Never misses nearby context

Cons:

  • Wastes tokens on irrelevant code
  • Hits token limits faster
  • Slower API responses

2. Function-Centric Approach

Other tools extract only the specific function you’re editing.

What gets sent:

// Only the multiply function
const multiply = (a: number, b: number): number => {
return a * b;
};

Pros:

  • Very efficient
  • Fast responses

Cons:

  • Might miss dependencies
  • Can break callers of the function
  • AI might not understand the full picture

3. Dependency-Aware Approach

The smartest tools analyze your code to build a dependency chain.

What gets sent:

// 1. The function you're editing
const multiply = (a: number, b: number): number => {
return a * b;
};
// 2. Functions that call multiply
const calculateTotal = (quantity: number, price: number) => {
return multiply(quantity, price);
};
// 3. Imports and types
import { TaxCalculator } from './tax-utils';
interface PriceResult {
subtotal: number;
tax: number;
}
// 4. Related tests
describe('multiply', () => {
it('should multiply two numbers', () => {
expect(multiply(2, 3)).toBe(6);
});
});

How it works:

  • Scans imports to find dependencies
  • Searches for functions that call your function
  • Finds test files related to your code
  • Builds a context map of related code

Pros:

  • Comprehensive context without bloat
  • Better code quality suggestions
  • Fewer missing dependencies

Cons:

  • More complex to implement
  • Can still miss edge cases
  • Takes longer to build context

4. Hybrid Models

Some advanced tools combine multiple strategies:

User Action → Analyze Intent → Select Strategy
┌──────────────────┼──────────────────┐
▼ ▼ ▼
Quick Edit Refactoring New Feature
(Function only) (Dependencies) (Full context)

For small changes, they send minimal context. For large refactors, they include the full dependency tree.

Real-World Impact

The Reddit research found concrete examples of how these strategies affect developers:

Case 1: Token Limit Error A developer tried to refactor a function in a 2,000-line file. Their AI tool sent the entire file and hit the API’s token limit. The request failed.

Case 2: Missing Dependency Another tool sent only the target function. The AI refactored it but broke three other functions that called it, because it didn’t see them.

Case 3: Sweet Spot A dependency-aware tool sent the function plus its dependencies. The AI successfully refactored the code while maintaining compatibility with all callers.

How to Optimize Your Workflow

Now that I understand how context windows work, I can work better with AI tools:

For small edits:

  • Keep functions focused and small
  • Avoid huge files with mixed concerns
  • The AI will see everything it needs

For large refactors:

  • Break changes into smaller steps
  • Explicitly mention related files in your prompt
  • “Also update the tests in auth.test.js

For best results:

  • Use tools with dependency-aware context
  • Structure code with clear imports
  • Keep related code in the same module

The Reason

I think the key issue is that most developers don’t realize context windows exist or how they work. We assume AI tools “see” our entire codebase, but they actually see only a carefully selected subset.

Different tools make different trade-offs:

  • Speed vs. completeness
  • Cost vs. quality
  • Simplicity vs. intelligence

Understanding these trade-offs helps you choose the right tool for your workflow and use it more effectively.

Summary

In this post, I showed how AI coding tools manage context windows based on analysis of 3,177 API calls. The key point is that different tools use different context selection strategies - from sending entire files to building sophisticated dependency chains - and these choices directly affect the quality of AI suggestions and your API costs.

When you choose an AI coding tool, consider its context strategy. For small projects, simple approaches work fine. For larger codebases, dependency-aware tools provide better results by understanding the relationships in your code.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments