Skip to content

saurabh-oss/code-bridge

Repository files navigation

✈ CodeBridge — Universal AI Coding Co-pilot

One extension. Every AI model. Zero vendor lock-in.

CodeBridge is an open-source VS Code extension that gives you a single, unified interface to every major AI coding provider — Anthropic Claude, OpenAI GPT, Google Gemini, and local models via Ollama. Instead of juggling separate subscriptions and extensions, CodeBridge intelligently routes each task to the optimal model based on complexity, cost, and your preferences.


The Problem

Today's developers face a fragmented AI tooling landscape:

Pain Point What Happens
Vendor lock-in You pay for Copilot, then need Claude for complex refactoring, then Gemini for long-context tasks
Cost blindness No visibility into how much you're spending across providers
Manual model selection You constantly decide "which AI should I use for this?"
Multiple extensions Each provider has its own extension, keybindings, and UX

CodeBridge's Solution

CodeBridge solves all four problems with two core innovations:

1. Intelligent Task Router

Every request is classified by complexity (1–10 scale) and automatically routed to the best model. A simple variable rename doesn't need GPT-4 — it goes to a fast, cheap model. A complex multi-file refactor gets escalated to a premium model. You never think about model selection again.

2. Unified Cost Tracking & Budget Management

Real-time cost tracking across all providers, with monthly budgets and automatic downgrade when limits are hit. See exactly where your money goes — by provider, by task type, by day.


Features

Intelligent Routing Engine

  • 5 routing strategies: Balanced, Cost-Optimized, Quality-First, Local-First, Manual
  • Automatic complexity classification based on code structure, language, and task type
  • Tier-based model selection: Economy → Standard → Premium based on what the task needs
  • Budget-aware fallback: Automatically routes to cheapest model when budget is exceeded

Multi-Provider Support

  • Anthropic Claude — Sonnet 4, Haiku 4.5, Opus 4.6
  • OpenAI — GPT-4.1, GPT-4.1 Mini, o3
  • Google Gemini — 2.0 Flash, 2.5 Pro
  • Ollama — Any local model (CodeLlama, DeepSeek Coder, Qwen 2.5 Coder)
  • OpenAI-compatible APIs — Azure OpenAI, LM Studio, LocalAI, vLLM

Code Actions (Right-click menu)

  • Explain Code — Clear breakdown of what selected code does
  • Refactor Code — Clean code improvements with one click
  • Generate Tests — Comprehensive unit tests with edge cases
  • Code Review — Structured feedback with severity ratings
  • Add Documentation — JSDoc/docstrings/inline comments
  • Fix Error — Root cause analysis and auto-fix

Chat Interface

  • Streaming responses in a VS Code sidebar panel
  • Routing info badge on every response (which model, why)
  • Per-message cost display
  • Code context from active editor automatically included

Inline Completions

  • Ghost-text suggestions as you type
  • Debounced to avoid excessive API calls
  • Routed to fastest/cheapest model for low-latency

Cost Dashboard

  • Real-time monthly spend in the status bar
  • Breakdown by provider, task type, and time period
  • Configurable monthly budget with warning thresholds
  • Automatic cost-saving mode when budget is exceeded

Quick Start

Prerequisites

  • VS Code 1.85+
  • At least one API key (or Ollama installed locally)

Installation

# Clone the repository
git clone https://github.com/saurabh-oss/code-bridge.git
cd code-bridge

# Install dependencies
npm install

# Compile
npm run compile

# Option A: Run in development mode
# Press F5 in VS Code to launch Extension Development Host

# Option B: Package and install
npm run package
# Then install the .vsix: Extensions → ⋯ → Install from VSIX

One-Time Setup

  1. Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P)
  2. Run "CodeBridge: Run Setup Wizard"
  3. Select your providers and enter API keys
  4. Choose a routing strategy (Balanced recommended)
  5. Done — start coding!

Getting API Keys

Provider Where to get it
Anthropic console.anthropic.com
OpenAI platform.openai.com/api-keys
Google aistudio.google.com/apikey
Ollama No key needed — install Ollama and pull a model

Architecture

┌──────────────────────────────────────────────────────┐
│                    VS Code Extension                  │
│                                                       │
│  ┌─────────┐  ┌──────────────┐  ┌──────────────────┐ │
│  │  Chat    │  │   Commands   │  │    Inline        │ │
│  │  Panel   │  │  (Actions)   │  │  Completions     │ │
│  └────┬─────┘  └──────┬───────┘  └────────┬─────────┘ │
│       │               │                   │           │
│       └───────────────┼───────────────────┘           │
│                       ▼                               │
│          ┌────────────────────────┐                    │
│          │   Intelligent Router   │ ◄── Routing       │
│          │   ┌────────────────┐   │     Strategy      │
│          │   │ Task Classifier│   │                   │
│          │   └────────────────┘   │                   │
│          └───────────┬────────────┘                    │
│                      │                                │
│          ┌───────────▼────────────┐                    │
│          │   Provider Registry    │                    │
│          └───┬─────┬─────┬───┬───┘                    │
│              │     │     │   │                        │
│          ┌───▼┐ ┌──▼┐ ┌─▼┐ ┌▼────┐                   │
│          │ An │ │ OA│ │Go│ │Olla │                    │
│          │thro│ │ I │ │og│ │ ma  │                    │
│          └────┘ └───┘ └──┘ └─────┘                    │
│                                                       │
│          ┌────────────────────────┐                    │
│          │    Cost Tracker        │ ◄── Budget        │
│          │  (persist to global)   │     Management    │
│          └────────────────────────┘                    │
└──────────────────────────────────────────────────────┘

Key Design Decisions

Plugin Architecture — Each provider is a self-contained class implementing IAiProvider. Adding a new provider (Mistral, Cohere, etc.) means creating one file with ~150 lines of code.

Strategy Pattern for Routing — The router applies different strategies without changing core logic. Strategies are swappable at runtime via the status bar.

Zero-Dependency Core — The extension uses no npm runtime dependencies. All HTTP calls use Node's built-in fetch. This keeps the bundle small and eliminates supply-chain risk.

Persistent Cost Tracking — Cost records are stored in VS Code's globalState (survives restarts). Records older than 90 days are auto-pruned.


Configuration Reference

All settings are under codeBridge.* in VS Code settings:

Provider Keys

Setting Description
providers.anthropic.apiKey Anthropic API key
providers.anthropic.enabled Enable/disable Anthropic
providers.openai.apiKey OpenAI API key
providers.openai.enabled Enable/disable OpenAI
providers.openai.baseUrl Custom base URL (Azure, LM Studio)
providers.google.apiKey Google AI API key
providers.google.enabled Enable/disable Google
providers.ollama.enabled Enable/disable Ollama
providers.ollama.baseUrl Ollama server URL
providers.ollama.model Default Ollama model

Routing

Setting Default Description
routing.strategy balanced Routing strategy
routing.maxComplexityForCheapModel 3 Complexity threshold for economy models

Cost & Budget

Setting Default Description
cost.monthlyBudget 0 Monthly budget in USD (0 = unlimited)
cost.warningThreshold 80 Warning at this % of budget

Completions

Setting Default Description
completion.enabled true Enable inline completions
completion.debounceMs 500 Debounce delay

Keyboard Shortcuts

Action Windows/Linux macOS
Open Chat Ctrl+Shift+A Cmd+Shift+A
Inline Complete Ctrl+Shift+Space Cmd+Shift+Space
Explain Code Ctrl+Shift+E Cmd+Shift+E

How Routing Works

When you trigger any AI action, the router follows this pipeline:

1. CLASSIFY    → Analyze code structure, language, task type → complexity score (1-10)
2. STRATEGIZE  → Apply your chosen routing strategy to pick the target model tier
3. BUDGET      → Check if monthly budget allows this tier, downgrade if over budget
4. EXECUTE     → Call the selected provider's API
5. TRACK       → Record tokens, cost, and latency

Complexity Scoring Example

Signal Weight Example
Task type difficulty 35% inline-completion = 2, refactor = 7
Code length 20% 10 lines = 1, 300+ lines = 9
Structural complexity 20% Few control flows = 2, many nested = 8
Language difficulty 15% Python = 3, Rust = 5, Haskell = 6
Multi-file context 10% Few imports = 1, many imports = 7

Adding a New Provider

CodeBridge is designed for extensibility. To add a new provider:

  1. Create src/providers/yourprovider.ts
  2. Extend BaseProvider
  3. Implement complete(), completeStream(), validateConnection()
  4. Register it in src/providers/registry.ts
  5. Add configuration entries in package.json
// src/providers/mistral.ts
export class MistralProvider extends BaseProvider {
  readonly id: ProviderId = 'mistral'; // Add to ProviderId union type
  readonly name = 'Mistral AI';
  readonly models: ProviderModel[] = [
    // ... define models with pricing
  ];

  async complete(request: AiRequest): Promise<AiResponse> {
    // Call Mistral API
  }
  // ...
}

Roadmap

  • Multi-turn chat memory — Maintain conversation context across messages
  • Project-level context — Automatically include relevant files from the workspace
  • Custom routing rules — "Always use Claude for Python, GPT for TypeScript"
  • Response caching — Cache identical requests to avoid duplicate API calls
  • Team sharing — Share cost dashboards and routing configs across a team
  • Provider health monitoring — Auto-failover when a provider is down
  • VS Code Marketplace publishing — One-click install
  • Telemetry dashboard — Latency percentiles, error rates, model comparison

Contributing

Contributions welcome! This is an open-source project and we value community input.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development

# Watch mode (auto-recompile on changes)
npm run watch

# Run in Extension Development Host
# Press F5 in VS Code

# Lint
npm run lint

License

Apache License 2.0 — See LICENSE for details.


Built with the conviction that AI coding tools should be open, interoperable, and cost-transparent.

About

One extension, every AI model. Intelligent routing, cost tracking, and seamless multi-provider AI coding — without vendor lock-in.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors