Most engineering teams approach AI coding assistants with a naive assumption: install an extension, paste an API key, and watch an LLM magically unravel a decade-old monolithic billing engine. In reality, pointing a vanilla code assistant at a legacy codebase yields polished, completely plausible hallucinations. The model assumes modern paradigms, imports nonexistent libraries, and misses subtle architectural landmines hidden across four different sub-repositories.
At 365Finds, we look at developer tools through a pragmatic lens: an AI coding assistant is only as good as its context retrieval pipeline. Sourcegraph Cody stands out because it does not attempt to brute-force a five-million-line legacy repo into an LLM context window. Instead, it anchors generation to Sourcegraph's mature code graph and search infrastructure.
If your team wants Sourcegraph Cody to reliably navigate, document, and explain technical debt rather than invent modern fairy tales, you must do the groundwork. Here is the operational blueprint 365Finds recommends for setting up Sourcegraph Cody across enterprise legacy systems.
Step 1: Connect and Index Repositories on Sourcegraph Server
Cody operates in two tiers: local workspace indexing and remote instance indexing. For a sprawling legacy architecture—often split across monoliths, microservices, or multiple code hosts (GitHub Enterprise, GitLab, Bitbucket Server, Perforce)—local IDE indexing alone is insufficient.
- Code Host Sync: In your Sourcegraph instance management console, add external connections to your code hosts. Grant read access to the relevant legacy repositories.
- Search Indexing (Zoekt): Ensure Sourcegraph completes trigram search indexing across default and active maintenance branches. This handles high-speed keyword and pattern retrieval when engineers query Cody.
- Handle Repository Limits: Legacy codebases frequently exceed standard repository size guidelines due to deep commit histories or embedded dependencies. Adjust search timeout and repository clone limits in the site configuration (
search.limits.maxTimeoutSeconds) so queries do not drop large directories mid-search.
Step 2: Prune the Noise with .sourcegraph/ignore
If you feed garbage context into Cody, you get hallucinated garbage back. Legacy systems are notoriously cluttered with generated stubs, ancient build outputs, third-party vendor directories, minified bundles, and abandoned documentation.
To prevent Cody from indexing low-signal files that poison retrieval:
- Add a
.sourcegraph/ignorefile to the root of your primary legacy repositories. - Specify glob patterns for directories that should never inform AI explanations:
# Exclude legacy build outputs and vendor bundles
dist/
build/
vendor/
node_modules/
*.min.js
legacy_backups/
test_data_dumps/
- Commit this file to the default branch. Sourcegraph respects
.sourcegraph/ignoreacross both Code Search and Cody's context retrieval engine, ensuring that context windows prioritize production logic over auto-generated noise.
Step 3: Implement Precise Code Navigation (SCIP / LSIF)
Fuzzy keyword matching works for simple scripts, but fails miserably when reverse-engineering complex object-oriented hierarchies in Java 8, C++, or older Python codebases. If a legacy module calls an abstract interface implemented in twelve different packages, Cody needs compiler-grade symbol resolution.
- Select the SCIP Indexer: Sourcegraph provides SCIP (Standard Code Interchange Protocol) indexers for core enterprise languages (
scip-java,scip-python,scip-typescript,scip-ruby,scip-go,scip-clang). - Add Indexing to CI/CD: Configure a step in your build pipeline using the Sourcegraph CLI (
src) to generate and upload SCIP indexes:
# Example: Upload SCIP index via Sourcegraph CLI
src code-intel upload -github-token=$GITHUB_TOKEN
- Outcome: When an engineer asks Cody, "Where is this database session committed in the legacy transaction pipeline?", Cody consults precise "Go to Definition" and "Find References" graphs rather than guessing based on word similarity.
Step 4: Configure IDE Clients and Scope Context with @-mentions
Once the backend is configured, equip your developers with the Cody extension in Visual Studio Code, JetBrains IDEs, or Visual Studio. Connect each client to your central Sourcegraph Enterprise URL and personal access token.
When dealing with legacy code, engineers should avoid generic prompts like "Explain this project". Broad questions force the model into wide, shallow retrievals that dilute precision. Instead, train the team to use targeted @-mentions:
- File & Directory Scoping (
@file,@folder): Point Cody explicitly to the entry point and configuration files:
@src/legacy/billing/BillingProcessor.java Explain how retry backoffs are handled here. - Symbol Scoping (
@symbol): Query specific structures across modules:
@LegacyAuthSessionToken What legacy endpoints still validate against this struct? - Multi-Repository Scoping (
@repo): Trace logic spanning separate codebases:
@core-monolith @legacy-auth-api How does authentication token generation pass between these two services?
Step 5: Leverage Cody's "Explain Code" and Custom Instructions
Legacy code often lacks tests and documentation. Cody provides built-in tools to accelerate codebase comprehension, but they must be constrained by rules.
- The Built-in "Explain Code" Prompt: Highlight an obscure 400-line legacy method, right-click, and select Cody > Explain Code. Cody breaks down the control flow, identifies potential failure modes, and outlines side effects.
- Enforce Legacy-Specific Context in Prompt Templates: If your legacy system requires archaic frameworks or strict architectural rules, define workspace instructions or custom prompts in
.vscode/cody.jsonor Sourcegraph's Prompt Library:
{
"cody.projectInstructions": "This repository relies on Java 8 and a proprietary in-house RPC framework. Do not suggest Java 17 features, lambdas that break serialization, or external third-party libraries not already present in the pom.xml."
}
- Bridge External Tribal Knowledge via OpenCtx: Legacy code logic is often explained only in old Jira tickets, Notion pages, or Confluence docs. Configure OpenCtx providers to allow Cody to pull context from issue trackers and internal documentation directly into the chat session.
365Finds Judgment: Where Teams Go Wrong
At 365Finds, we strongly recommend Sourcegraph Cody for enterprise engineering teams tackling massive legacy codebases. Its architecture is fundamentally sound: by coupling state-of-the-art LLMs to Zoekt search, SCIP code graphs, and multi-repo indexing, it solves context discovery better than single-repo, autocomplete-centric tools.
However, our recommendation comes with an explicit warning: Sourcegraph Cody is not a plug-and-play shortcut. If your infrastructure team does not prune legacy clutter with .sourcegraph/ignore or invest the time to configure SCIP indexers in CI/CD, Cody's explanations will frequently hallucinate plausible modern abstractions that fail in production. Treat Cody as the analytical front-end of a rigorous code intelligence pipeline—not a silver bullet.