AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How Sourcegraph Cody Uses Multi-Repository Context for Autocomplete and Bug Fixing

Daniel Kräher · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Most AI coding assistants suffer from tunnel vision. When an engineer writes code in an isolated microservice or attempts to fix a breaking API error across distributed services, tools like standard GitHub Copilot treat the active editor tab as the entire universe. If your function depends on a data contract defined in a shared library three repositories over, the model simply guesses. It hallucinates parameters, invents non-existent methods, and leaves developers cleaning up phantom syntax.

Sourcegraph Cody takes a fundamentally different engineering path. By wiring large language models directly into Sourcegraph’s centralized Code Graph and search infrastructure, Sourcegraph Cody pulls multi-repository context into both real-time code completion and root-cause bug fixing. At 365Finds, we tested and analyzed how this architecture operates, where it delivers massive productivity gains, and where its technical boundaries lie.


The Architecture: Why Multi-Repo Context Matters

Modern software development rarely lives in a single folder. Organizations split systems across microservices, private package registries, design systems, and shared schema repositories (Protobuf, GraphQL, OpenAPI). A bug appearing in a frontend React client often originates from a schema drift in an upstream Go service.

Standard AI assistants attempt to solve this using local workspace indexing or shallow vector search across open tabs. This fails when dependencies live in separate Git repositories that aren't even cloned to the developer's local machine.

Sourcegraph Cody solves this through Sourcegraph’s distributed search index:

[ Developer IDE (VS Code / JetBrains) ]
          │                  ▲
   Prompt │ Context          │ Relevant Snippets &
   + Edit │ Requests         │ Exact Symbol Definitions
          ▼                  │
[ Sourcegraph Enterprise / Cloud Engine ]
   ├── Zoekt Trigram Search Index (Sub-millisecond keyword lookup)
   ├── SCIP Code Intelligence Graph (Precise cross-repo symbol navigation)
   └── Semantic Embeddings & Context Filters
          │
          ▼
[ Multi-Repo Context Window -> LLM (Claude 3.5 Sonnet / GPT-4o) ]

Instead of uploading massive codebases into prompt windows, Sourcegraph Cody queries a remote Sourcegraph instance that has already indexed your organization's entire repository fleet. It extracts precise symbol definitions, type signatures, and usage examples across multiple repositories, formatting them into a compact context bundle before invoking the underlying LLM.


Multi-Repo Context in Code Completion: Low Latency vs. Deep Scope

Code completion operates under severe constraints: developers expect inline ghost text suggestions within 150 to 250 milliseconds. Deep vector retrieval across dozens of remote repositories during every keystroke is physically impossible over standard network latency.

To balance speed and accuracy, Sourcegraph Cody splits autocomplete context into a tiered retrieval pipeline:

Pipeline LayerContext SourceLatency BudgetRole in Completion
Immediate LocalActive document, cursor prefix/suffix, recent clipboard< 30msPreserves local syntactic continuity and variable names
Workspace Graph (BFG)Tree-sitter AST parsing, locally open tabs, Jaccard similarity< 60msResolves intra-project helper functions and local types
Remote Multi-Repo IndexCentral Sourcegraph Code Search & symbol indexBackground / CachedPulls proprietary APIs and shared module definitions across enterprise repos

When you import an internal utility library—for example, @company/auth-client—Cody does not need the source code cloned locally. When autocomplete triggers on authClient.verifyToken(, Sourcegraph Cody resolves the type definitions and method signatures cached from the remote repository's index. The result is inline completion that correctly suggests your internal parameter contracts rather than public, generic authentication patterns.


Multi-Repo Context in Bug Fixing: Tracing Errors Across Boundaries

While autocomplete must sacrifice retrieval depth for sub-second speed, bug fixing in Cody Chat and inline commands enjoys a much larger context budget. This is where multi-repository awareness proves its worth.

1. Diagnosing Cross-Service Payload Drifts

Consider a common production failure: Service A calls Service B, but Service B recently updated its JSON payload schema, throwing an unhandled parsing exception in Service A.

In isolated tools, pasting the stack trace into chat yields generic advice: "Check if the payload contains null." With Sourcegraph Cody, developers explicitly bridge the repositories:

  1. Open Cody Chat in the IDE (VS Code, JetBrains, or Visual Studio).
  2. Type @ to invoke the context picker and select Remote Repositories.
  3. Add both the consuming repository (@org/order-service) and the upstream producer (@org/payment-gateway).
  4. Paste the stack trace and prompt Cody: Find why handlePaymentWebhook fails on deserialization against the latest payment gateway contract.

Sourcegraph Cody queries the remote index of both repositories simultaneously, compares the deserialization model in order-service with the struct definitions in payment-gateway, highlights the field mismatch, and writes the corrected adapter code.

2. Using Inline Fixes (/fix) Across Repositories

Cody's /fix command leverages cross-repo context to generate targeted diffs. When an internal dependency deprecates a utility function, Cody inspects how other repositories in the organization refactored that exact deprecation, copying proven migration patterns directly into your file.


Step-by-Step Guide: Configuring Multi-Repository Context

To unlock cross-repository intelligence, teams must properly link their client extension to an indexed Sourcegraph instance.

Step 1: Connect Your IDE Extension to Sourcegraph Enterprise

Multi-repo remote context requires Cody Enterprise or an indexed Sourcegraph team instance.

  1. Install the Sourcegraph Cody extension in VS Code or JetBrains.
  2. In the extension settings, sign in using your Sourcegraph Instance URL (e.g., https://sourcegraph.company.com) and your Access Token.
  3. Confirm connection status in the Cody sidebar indicator.

Step 2: Verify Server-Side Indexing

Ensure target repositories are fully indexed on the Sourcegraph instance. Repository administrators must verify that:

Step 3: Configure Context Filters

Enterprise administrators should establish context boundaries using Sourcegraph's context filters to prevent unauthorized code mixing:

{
  "cody.contextFilters": {
    "include": [
      { "repoName": "github.com/organization/core-*" },
      { "repoName": "github.com/organization/shared-libs" }
    ],
    "exclude": [
      { "repoName": "github.com/organization/proprietary-crypto" }
    ]
  }
}

Step 4: Actively Target Repositories in Chat

In daily development, use explicit @-mentions to build your context scope:


365Finds Evaluation: Strengths, Trade-Offs, and Verdict

365Finds considers Sourcegraph Cody's multi-repo context the most technically sound architecture for enterprise development currently on the market. Most AI tools attempt to emulate codebase awareness by jamming thousands of vector chunks into huge context windows, resulting in "lost-in-the-middle" hallucinations. Cody relies on Sourcegraph's decade of code-search infrastructure to fetch exact code graphs before the LLM generates a single token.

However, 365Finds also stresses the operational trade-offs:

For engineering teams operating complex polyrepos, microservices, and internal libraries, 365Finds recommends Sourcegraph Cody over single-workspace assistants. When debugging cross-service failures, having an assistant that reads both sides of an API boundary transforms hours of manual repo-hopping into a single prompt.

References