AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Sourcegraph Cody with Local Ollama for Air-Gapped Autocomplete and Private Chat

Ong Lay Hoon · 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

Corporate compliance policies in defense, healthcare, and fintech often create an agonizing dilemma: ban cloud-connected AI coding tools to protect proprietary code, or watch developer velocity crawl at a snail's pace. At 365Finds, we consider an outright ban on AI assistants to be an operational mistake. Software engineering teams do not have to choose between severe IP leakage risks and productivity stagnation.

Sourcegraph Cody provides a native, fully offline path. By coupling Cody with an on-premises or workstation-local Ollama runtime, you can run zero-egress inline autocompletions and multi-turn contextual chat inside Visual Studio Code. The entire pipeline operates without a single byte escaping to Anthropic, OpenAI, or Sourcegraph cloud servers.

Making this architecture viable in daily development hinges on one crucial design choice: model separation. Trying to force a single 7-billion-parameter model to handle both chat and real-time typing completion ruins the developer experience.

Below is 365Finds' definitive configuration guide for deploying Sourcegraph Cody with local Ollama models in strictly air-gapped environments.


1. The Core Architecture: Dual-Model Routing

Local AI coding fails most often because teams overload their hardware. Autocomplete and chat demand fundamentally different compute dynamics.

+-----------------------------------------------------------------------+
| VS Code Editor (Air-Gapped Workstation)                               |
|                                                                       |
|  [ Typing Keystrokes ] --------> cody.autocomplete.experimental       |
|                                    | (FIM / Ghost Text, <300ms)       |
|                                    v                                  |
|                              +-----------------------------+          |
|                              | Ollama: deepseek-coder:1.3b |          |
|                              | (VRAM footprint: ~1.5 GB)   |          |
|                              +-----------------------------+          |
|                                                                       |
|  [ Chat / @-Mentions ] --------> cody.experimental.ollamaChat         |
|        ^                           | (Multi-turn AST Reasoning)       |
|        |                           v                                  |
|   symf Local Search          +-----------------------------+          |
|   (Disk AST / Symbols)       | Ollama: deepseek-coder:6.7b |          |
|                              | (VRAM footprint: ~5.5 GB)   |          |
|                              +-----------------------------+          |
+-----------------------------------------------------------------------+

Autocomplete: Low-Latency FIM (Fill-In-The-Middle)

Code autocompletion happens as you type. If ghost text takes longer than 300 milliseconds to appear, engineers instinctively type over it, rendering the assistant useless. For autocomplete, 365Finds strongly recommends lightweight, specialized FIM models:

Chat & Codebase Queries: High-Param Reasoning

Chat conversations, automated unit test generation, and refactoring require larger context windows and instruction-following capability. Here, latency of 2 to 4 seconds for the first token is completely acceptable.


2. Preparing the Air-Gapped Ollama Runtime

In a true SCIF or air-gapped network, your target workstation cannot run ollama pull directly over the public internet. You must stage binaries and weights via an approved transfer medium or internal package registry.

Step 2.1: Transfer and Install Ollama

Download the appropriate Ollama binary and the required model weights on an authorized staging machine:

# Pull models on the staging workstation
ollama pull deepseek-coder:1.3b
ollama pull deepseek-coder:6.7b

Ollama stores model manifests and layer blobs in:

Archive these directories alongside the Ollama standalone binary, complete your organization's air-gap scanning protocol, and extract them onto the offline target workstation.

Step 2.2: Bind the Ollama Daemon

Start the local server daemon. By default, Ollama listens exclusively on loopback 127.0.0.1:11434.

If you run Ollama locally on the developer machine:

ollama serve

If your air-gapped subnet uses a centralized on-premises inference server (e.g., a shared GPU box in the local rack), bind Ollama to all network interfaces by editing the system environment:

# Linux systemd service override:
sudo systemctl edit ollama.service

# Add:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_ORIGINS=*"

Verify that the local API responds:

curl http://127.0.0.1:11434/api/tags

You should see JSON listing both deepseek-coder:1.3b and deepseek-coder:6.7b.


3. Configuring VS Code Settings for Sourcegraph Cody

Install the Sourcegraph Cody extension in VS Code. In an air-gapped environment, download the .vsix package from the Visual Studio Marketplace on an internet-connected computer and install it via Extensions: Install from VSIX....

Open your VS Code user configuration (settings.json):

Paste the following configuration block:

{
  /* -----------------------------------------------------------
     Sourcegraph Cody: Local Air-Gapped Ollama Routing
     ----------------------------------------------------------- */
  // 1. Route Autocomplete to Local Ollama
  "cody.autocomplete.advanced.provider": "experimental-ollama",
  "cody.autocomplete.experimental.ollamaOptions": {
    "url": "http://127.0.0.1:11434",
    "model": "deepseek-coder:1.3b"
  },

  // 2. Enable Local Chat Integration
  "cody.experimental.ollamaChat": true,

  // 3. Diagnostics and Debugging
  "cody.debug.verbose": true,

  // 4. Hard Privacy & Zero Cloud Exfiltration Guards
  "cody.telemetry.level": "off",
  "telemetry.telemetryLevel": "off"
}

Note on Alternative Configuration Formats

Depending on your installed Sourcegraph Cody extension version, discrete keys may also be recognized:

"cody.autocomplete.advanced.provider": "experimental-ollama",
"cody.autocomplete.advanced.serverEndpoint": "http://127.0.0.1:11434",
"cody.autocomplete.advanced.model": "deepseek-coder:1.3b"

365Finds prefers the structured ollamaOptions object because it isolates endpoint parameters cleanly and prevents parameter collision during version upgrades.


4. Booting Offline Mode & Selecting Models in Cody

Starting with Cody for VS Code v1.26, Sourcegraph introduced a native Offline Mode that eliminates the requirement to authenticate against sourcegraph.com.

  1. Launch VS Code in your air-gapped environment.
  2. Open the Cody sidebar tab. Cody detects the absence of internet connectivity and displays an offline splash screen featuring the Ollama logo.
  3. Click the Enter Offline Mode button beneath the Ollama badge. This bypasses account authentication tokens entirely.
  4. Open the Cody Chat panel (Alt + L or Option + L).
  5. Click the model selection dropdown at the top of the chat panel.
  6. Any model pulled into your local Ollama runtime will appear with the "by Ollama" suffix. Select your heavier reasoning model: deepseek-coder:6.7b (by Ollama).

Now, typing code in any editor buffer automatically queries deepseek-coder:1.3b for fast ghost completions, while side-panel prompts and @-file references route to deepseek-coder:6.7b.


5. Local Codebase Context via Symf

The primary reason to use Sourcegraph Cody over bare-bones Ollama terminal wrappers is Cody's context-fetching engine. In cloud mode, Cody uses remote vector embeddings. In an air-gapped environment, Cody shifts context retrieval to symf.

symf is Sourcegraph's local symbolic search tool. It compiles Tree-sitter parsers directly on the developer's machine:


6. Verifying Zero Data Exfiltration

For defense and financial security audits, "trusting" client settings is insufficient. You must verify network isolation empirically.

Run packet analysis during active Cody usage:

# Monitor external network interfaces (e.g., eth0) while writing code and prompting Cody Chat
sudo tcpdump -i eth0 -n "port 80 or port 443"

Next, monitor the local loopback interface:

sudo tcpdump -i lo -n "port 11434"

What You Should Observe:

  1. When typing code, the loopback capture (lo) immediately captures POST /api/generate requests containing the prefix and suffix of your cursor location.
  2. When submitting a chat prompt, lo logs a POST /api/chat request containing the user query combined with local symbol context retrieved by symf.
  3. The physical interface (eth0) remains completely silent. Zero packets leave the workstation.

365Finds Engineering Judgment

Evaluation DimensionCloud-Connected Cody (Claude 3.5 Sonnet)Air-Gapped Cody + Ollama (Local Dual-Model)
Data Privacy & IP ProtectionRelies on vendor zero-retention contractual guaranteesMathematically air-gapped; zero egress packets
Autocomplete Latency250–450ms (dependent on network ping)120–220ms (near-zero network latency via 1.3B model)
Deep Architectural RefactoringIndustry-leading multi-file synthesisModerate; competent for single-file, limited on complex multi-hop logic
Hardware OverheadNegligible workstation loadRequires dedicated GPU (minimum 8 GB VRAM recommended)
Regulatory & SCIF ClearanceProhibited in strict environmentsFully compliant with zero-trust and air-gap mandates

365Finds' verdict is straightforward: local open-weights models will not equal Claude 3.5 Sonnet on deep, multi-repository architectural overhauls. However, pretending that developers in air-gapped defense or banking labs should work without AI is an outdated mindset.

By dedicating a sub-2B parameter model to autocomplete and a 7B model to chat through Sourcegraph Cody's native Ollama endpoint, engineering organizations achieve an 80% productivity gain while maintaining 100% data sovereignty.


References