Build an Offline-First AI Code Autocomplete VS Code Extension with Bun.js, WebAssembly, and Llama 3.2 1B: 2026 Step-by-Step Guide for Developers
Learn how to build a privacy-focused, offline-first AI code autocomplete VS Code extension in 2026 using Bun.js, WebAssembly, and the lightweight Llama 3.2 1B model—no cloud API required, full control over your development workflow.
Agentic Academy Labs
Author
In 2026, AI code autocomplete is no longer a luxury—it's a core part of every developer's workflow. But cloud-dependent tools come with major drawbacks: privacy risks for proprietary code, latency from round-trip API calls, recurring subscription costs, and complete failure when you're offline. Today, we'll walk through building a fully offline, privacy-first AI autocomplete VS Code extension using Bun.js, WebAssembly, and the lightweight Llama 3.2 1B model—no cloud APIs, no monthly fees, and full control over your development experience.
Why Offline-First AI Autocomplete Matters in 2026
The shift toward offline-first dev tools is driven by three non-negotiable needs for modern developers:
- Privacy: Your code never leaves your machine, eliminating risks of leaking proprietary logic, customer data, or internal tooling to third-party AI providers.
- Zero latency: No round-trip to cloud servers means suggestions appear instantly, even on slow or unreliable internet connections.
- Zero ongoing cost: Unlike cloud autocomplete tools that charge $10–$20 per user per month, this extension is 100% free after initial setup, with no subscriptions or usage limits.
Llama 3.2 1B is the perfect model for this use case: its 1 billion parameter count is small enough to run smoothly on consumer hardware, even when quantized to 4-bit (which shrinks the model to ~600MB). Paired with WebAssembly (WASM) for near-native performance in the VS Code extension host, and Bun.js for lightning-fast build and runtime operations, this stack delivers a seamless autocomplete experience that rivals cloud tools.
Prerequisites for This Build
Before you start, make sure you have the following installed:
- VS Code 1.85 or later (with WASM SIMD support enabled by default in 2026)
- Bun 1.1 or later
- Node.js 20+ (for VS Code extension tooling)
- A quantized Llama 3.2 1B GGUF file (we recommend the 4-bit quantized version from TheBloke's Hugging Face repo for optimal speed/accuracy balance)
- Basic familiarity with the VS Code Extension API
Step 1: Scaffold Your Extension Project with Bun.js
First, we'll use Bun to set up a new VS Code extension project, skipping the slow npm install step entirely:
# Install the VS Code extension generator globally with Bun
bun install -g yo generator-code
# Scaffold a new TypeScript extension
yo code
# Follow the prompts: name it "offline-llama-autocomplete", select "New Extension (TypeScript)"
cd offline-llama-autocomplete
# Replace npm install with Bun for 10-100x faster dependency installation
bun install
# Install required dependencies for WASM integration and testing
bun install @vscode/test-electron llama-wasm
Bun's native speed cuts down project setup time from minutes to seconds, and its built-in TypeScript support means no extra transpilation config is needed out of the box.
Step 2: Integrate WebAssembly for Local Llama 3.2 1B Inference
Next, we'll set up the WASM runtime to run Llama 3.2 1B entirely locally. First, add the quantized GGUF model file to your project's media folder (create it if it doesn't exist) so it bundles with your extension.
We'll use the llama-wasm package, which provides prebuilt WASM bindings for llama.cpp optimized for VS Code's extension host. Create a src/llama-wasm.ts file to handle model loading and inference:
// src/llama-wasm.ts
import { LlamaContext } from 'llama-wasm';
export class LocalLlama {
private context: LlamaContext | undefined;
async load(modelPath: string) {
this.context = await LlamaContext.load(modelPath, {
contextLength: 512, // Limit context to 512 tokens for low autocomplete latency
gpuLayers: 0, // Disable GPU layers for broad compatibility; enable if WASM SIMD is supported
threads: navigator.hardwareConcurrency || 4, // Use all available CPU cores
});
}
async complete(prompt: string, options: { maxTokens: number; temperature: number }) {
if (!this.context) throw new Error('Model not loaded');
return this.context.complete(prompt, options);
}
dispose() {
this.context?.dispose();
}
}
This wrapper handles model loading once on extension activation, and exposes a simple complete method for generating autocomplete suggestions.
Step 3: Implement the VS Code Autocomplete Provider
VS Code's CompletionItemProvider API lets us hook into the editor's autocomplete system. Update your src/extension.ts file to register the provider and trigger local inference when the user types:
// src/extension.ts
import * as vscode from 'vscode';
import { LocalLlama } from './llama-wasm';
let llama: LocalLlama | undefined;
export async function activate(context: vscode.ExtensionContext) {
// Initialize local Llama model once on extension startup
llama = new LocalLlama();
const modelPath = context.asAbsolutePath('media/llama-3.2-1b-q4.gguf');
await llama.load(modelPath);
// Register autocomplete provider for popular programming languages
const provider = vscode.languages.registerCompletionItemProvider(
['javascript', 'typescript', 'python', 'rust', 'go'],
{
async provideCompletionItems(document, position) {
// Add 300ms debounce to avoid running inference on every keystroke
await new Promise(resolve => setTimeout(resolve, 300));
// Get code context leading up to the cursor
const range = new vscode.Range(new vscode.Position(0, 0), position);
const fullContext = document.getText(range);
const truncatedContext = fullContext.slice(-2048); // Trim to ~512 tokens for speed
// Run local inference with low temperature for deterministic, relevant code
const completion = await llama!.complete(truncatedContext, {
maxTokens: 32, // Limit to short autocomplete snippets
temperature: 0.2,
});
// Return formatted completion item to VS Code
return [
new vscode.CompletionItem(completion, vscode.CompletionItemKind.Snippet),
];
},
},
100 // Trigger after typing space, dot, or other common code delimiters
);
context.subscriptions.push(provider);
}
export function deactivate() {
llama?.dispose();
}
The 300ms debounce and 32-token limit ensure inference runs in <100ms on most modern laptops, making suggestions feel instant. The low temperature setting ensures the model generates consistent, relevant code rather than random variations.
Step 4: Optimize and Bundle with Bun.js
Bun's built-in bundler makes it trivial to package your extension with the WASM binary and model file, with zero extra configuration. Create a bunfig.toml file in your project root:
# bunfig.toml
[build]
entrypoints = ["./src/extension.ts"]
outdir = "./dist"
minify = true
splitting = false
# Bundle the WASM model and GGUF file with the extension for offline use
assets = ["./media/llama-3.2-1b-q4.gguf"]
Run bun build to generate a bundled, minified extension in the dist folder. Bun's native WebAssembly support cuts down WASM module instantiation time by 2-3x compared to Node.js, making the extension feel snappier on startup.
Step 5: Test and Package Your Extension
First, test the extension locally by pressing F5 in VS Code to launch an Extension Development Host window. Open a supported language file, start typing code, and you'll see local autocomplete suggestions appear instantly—even if you turn off your wifi.
Once you're happy with the performance, package the extension into a shareable .vsix file using the official VS Code packaging tool, installed via Bun:
# Install the VS Code packaging tool globally
bun install -g @vscode/vsce
# Package the extension
vsce package
You can install the .vsix file locally by opening VS Code, navigating to the Extensions panel, clicking the three-dot menu, and selecting "Install from VSIX...".
Key Considerations for Production Use
If you want to share this extension with your team or release it publicly, keep these tips in mind:
- Model quantization: Use 2-bit or 3-bit quantized versions of Llama 3.2 1B for even smaller file sizes and faster inference, with minimal accuracy loss for autocomplete use cases.
- Context window tuning: For most autocomplete scenarios, a 256–512 token context window is more than enough, and keeps latency under 100ms. Reserve the full 8k context window for more advanced features like code refactoring.
- WASM SIMD support: Ensure your extension enables WASM SIMD (enabled by default in VS Code 2026) for 2-3x faster inference on modern CPUs.
- Custom model support: Let users upload their own fine-tuned Llama 3.2 1B models trained on their team's codebase for more relevant, context-aware suggestions.
- Fallback behavior: Add a fallback to cloud autocomplete if the local model fails to load, for edge cases where the user's hardware can't run the model smoothly.
The Future of Offline-First AI Dev Tools
In 2026, the trend toward local, privacy-first AI tools is only accelerating. As small language models like Llama 3.2 1B get more capable, we'll see more developers ditching cloud-dependent AI tools for offline alternatives that give them full control over their data and workflow. This extension is just the starting point: you can extend it to add offline code explanation, refactoring, bug detection, and even full code generation, all without sending a single line of code to an external server.
With Bun.js, WebAssembly, and accessible small language models, building powerful offline AI dev tools has never been easier. Try building this extension today, and take back control of your AI-powered development workflow.
Enjoyed this article?
Read More Articles