Shoving a 3,500-line legacy monolith into an AI prompt is not an engineering workflow. It is wishful thinking.
When developers ask Sourcegraph Cody questions about large files, things tend to break down in two distinct ways. The obvious failure is an abrupt error: a red warning claiming the file is too large, or a backend timeout such as 500 context deadline exceeded. The insidious failure is silent context truncation. Cody quietly clips the beginning or end of your file, drops surrounding type definitions, or purges earlier conversation turns to squeeze inside token limits. The model then hallucinates method signatures that do not exist or suggests changes that break unread dependencies.
At 365Finds, we evaluate developer tooling by how it behaves under real enterprise messiness, not pristine 50-line demos. Cody possesses one of the best code-graph context engines on the market, yet developers constantly bottleneck it by treating the chat prompt like a bulk file uploader.
Here is how to configure Sourcegraph Cody, tune your editor environment, and structure your queries to eliminate context truncation and cut unnecessary token consumption.
1. Stop Dumping Whole Files: Master Surgical @-Mentions
The single biggest source of token waste in Cody is referencing entire files when you only need a specific method or interface. Cody addresses this directly with targeted line-range syntax and symbol indexing.
The Line-Range Syntax
Instead of typing @largeService.ts, pin the context to the exact lines under scrutiny:
@src/services/billingService.ts:120-210
By appending :startLine-endLine to your @-mention, Cody bypasses the surrounding boilerplate, imports, and unrelated utilities. You inject 350 tokens into the prompt context instead of 8,500 tokens.
Symbol-Level Targeting
If you refactor a method buried inside a massive class, you do not even need to look up line numbers. Type @ followed by the function, class, or interface name:
@processRecurringPayment
Cody extracts the symbol’s AST definition and immediate signature directly from the workspace index. This leaves your input token budget available for what actually matters: detailed instructions and the model's reasoning buffer.
┌─────────────────────────────────────────────────────────────┐
│ Full File Mention (Wasteful) │
│ Imports (400 tok) + Helpers (2,500 tok) + Target Logic │
│ (350 tok) + Unrelated Classes (4,000 tok) = ~7,250 Tokens │
├─────────────────────────────────────────────────────────────┤
│ Surgical @file:line-range (Optimized) │
│ Target Logic (350 tok) = ~350 Tokens (95% Token Savings) │
└─────────────────────────────────────────────────────────────┘
2. Configure Editor Exclusions to Stop Context Pollution
Cody’s local retriever scans your workspace to find relevant context chips. If your project contains minified bundles, build outputs, database migration dumps, or generated API stubs, Cody can waste valuable retrieval slots pulling meaningless tokens into the prompt payload.
VS Code and JetBrains Exclusion Settings
Cody natively honors standard editor exclusion rules. To prevent runaway token consumption, configure .vscode/settings.json at the root of your workspace:
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/node_modules": true,
"**/dist": true,
"**/build": true,
"**/*.min.js": true,
"**/*.bundle.js": true
},
"search.exclude": {
"**/node_modules": true,
"**/dist": true,
"**/build": true,
"**/coverage": true,
"**/*.generated.*": true,
"**/vendor": true
}
}
Files matching search.exclude and .gitignore are excluded from Cody’s automated codebase search and local heuristic retrieval.
The Status of .cody/ignore vs Context Filters
Many legacy guides still advise creating a .cody/ignore file in your repository. At 365Finds, we advise against relying on this: Sourcegraph has deprecated experimental .cody/ignore support in favor of repository-level and instance-level controls.
If your team runs Sourcegraph Enterprise (version 5.4.0 or later with client extension versions >= 1.20.0 for VS Code or >= 6.0.0 for JetBrains), ask your site administrator to configure Cody Context Filters via site configuration:
{
"cody.contextFilters": {
"include": [
{ "repoNamePattern": "^github\\.com\\/your-org\\/.*" }
],
"exclude": [
{ "repoNamePattern": ".*-generated-schemas$" },
{ "repoNamePattern": ".*-analytics-dumps$" }
]
}
}
This enforces token-efficient context isolation at the infrastructure level, preventing developers from inadvertently pulling gigabyte-scale datasets into Cody prompts.
3. Choose the Right Model Tier for the Job
Not all Cody models share the same context architecture. If you use a budget model for complex queries on large files, context truncation is inevitable.
| Model Tier | Representative Models | User-Defined Context (@-Mentions) | Rolling Conversation Context | 365Finds Recommended Use Case |
|---|---|---|---|---|
| Tier-1 Advanced | Claude 3.5 Sonnet; Claude 3.7 Sonnet; Gemini 1.5 Pro | 30,000 – 45,000 tokens (~4,000 lines of code) | ~15,000 tokens | Multi-file refactors; navigating large complex files; architectural questions |
| Tier-2 Lightweight | Claude 3.5 Haiku; GPT-4o mini; Gemini 2.0 Flash | Shared 7,000 token limit across context and chat history | Shared with context (7,000 total) | Quick inline edits; single-function docstrings; localized unit tests |
When inspecting a large file, switch your Cody chat model selector to Claude 3.5 Sonnet or Gemini 1.5 Pro. Standard models collapse when user context and conversation history exceed 7,000 tokens, aggressively slicing away earlier prompt context to maintain continuity.
4. Enforce Session Hygiene to Protect the 15,000-Token Buffer
Cody reserves roughly 15,000 tokens for continuous chat history when running on premium models. In a long, rambling conversation, your back-and-forth debugging exchanges eat away at that window. Once the chat history saturates, Cody begins truncating older context chips.
We follow a strict rule at 365Finds: one task, one thread.
- If you finish debugging a utility function and move to modifying the core file, hit
Ctrl+L(orCmd+L) to launch a clean chat session. - Clearing accumulated chat context immediately restores your full context allocation for new
@-mentions. - When you need references from earlier discussion, summarize the decision into a single concise prompt rather than dragging along 30 turns of diagnostic chatter.
5. Audit Real Payloads Using Verbose Debugging
If Cody produces generic responses or appears to miss parts of your file, stop guessing. Check what Cody actually sent to the backend LLM.
Add this flag to your editor settings:
{
"cody.debug.verbose": true
}
Next, open your editor's output pane:
- In VS Code: Navigate to View > Output and select Cody by Sourcegraph from the channel dropdown.
- In JetBrains: Open the Cody tool window log tab.
The verbose log displays the exact JSON payload dispatched to the LLM, including:
- The character and token count of each referenced file snippet.
- Whether any
@-mentionwas truncated or omitted due to window limits. - The retrieved search chunks and embeddings attached automatically by Cody's context engine.
If you see file snippets truncated mid-class or notice that secondary files were silently dropped, that is your immediate trigger to narrow your @-mention ranges.
The 365Finds Take: Precision Trumps Window Size
The AI industry is obsessed with million-token context windows. In practice, feeding 200,000 tokens of raw source code to a frontier model triggers severe latency penalties, increases operational costs, and induces "lost-in-the-middle" attention degradation.
Cody works best when used as an intelligent surgical scalpel, not a dump truck. By combining line-range @-mentions (@file:start-end), rigorous editor search.exclude settings, premium model tier selection, and clean chat session boundaries, you eliminate context truncation entirely.
One final hard constraint to keep in mind: Cody hard-caps output generation at approximately 4,000 tokens across all models. That yields roughly 500 to 600 lines of generated code. Asking Cody to "rewrite this entire 2,000-line file" will always result in output truncation at line 600, regardless of how much input context headroom remains.