DEV Community

Cover image for How I Built a Free, Multi-Model AI Coding Assistant in My Terminal
Waffeu Rayn
Waffeu Rayn

Posted on

How I Built a Free, Multi-Model AI Coding Assistant in My Terminal

If you spend a lot of time writing code, you’ve probably noticed how fast API costs add up when using AI coding tools. And relying on just one model often leaves you hitting rate limits right when you’re in the middle of a flow state.

To fix this, I set up OpenCode—an open-source CLI agent that lets you pair-program with multiple AI models right from your terminal.

The best part? You can plug in your existing $20/month ChatGPT or Claude subscriptions alongside zero-cost API tiers (like Google AI Studio and OpenRouter) to route tasks intelligently without paying per-token API bills.

Here’s how to set it up, enable Language Server Protocol (LSP) for code awareness, and configure smart routing.


1. Grab OpenCode

First, get the OpenCode CLI installed on your machine:

# Recommended script for macOS/Linux
curl -fsSL https://opencode.ai/install | bash

# Or via Homebrew / NPM
brew install anomalyco/tap/opencode
# npm install -g opencode-ai@latest

Enter fullscreen mode Exit fullscreen mode

You can check out their official docs or GitHub repo if you want to inspect the source code first.


2. Link Your Existing Subscriptions

Instead of paying per-token API rates for heavy coding models, you can hook up the subscriptions you already pay for:

  • If you have Claude ($20/mo):
npm install -g @anthropic-ai/claude-code
claude auth login

Enter fullscreen mode Exit fullscreen mode
  • If you have ChatGPT Plus/Pro / OpenAI Codex:
npx -y opencode-openai-codex-auth@latest

Enter fullscreen mode Exit fullscreen mode

3. The Strategy: Don't Waste Heavy Models on Easy Edits

The key to a zero-cost workflow is delegating tasks based on difficulty:

  1. Heavy Coder (model): Directs complex feature work and multi-file refactoring to Claude Sonnet or OpenAI Codex (via your subscription).
  2. Quick Helper (@fast): Offloads simple edits—like tweaking CSS or renaming variables—to Gemini 2.5 Flash on Google AI Studio's free tier.
  3. Planner (plan): Offloads architecture reviews and task breakdowns to free reasoning models like DeepSeek R1 or Kimi on OpenRouter.

4. Setting Up Your Config & Enabling LSP

OpenCode can connect directly to your project's Language Server Protocol (LSP) so the AI actually understands your TypeScript or Vue errors in real time.

Create your global config file at ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "lsp": true,
  "permission": {
    "lsp": "allow"
  },
  "plugin": [
    "opencode-claude-auth@latest",
    "opencode-openai-codex-auth@latest"
  ],
  "model": "anthropic/claude-sonnet-5",
  "small_model": "gemini-direct/gemini-2.5-flash",
  "agents": {
    "plan": {
      "mode": "primary",
      "model": "openrouter/moonshotai/kimi-k2.6:free",
      "description": "Architectural planning and logic design."
    },
    "fast": {
      "mode": "subagent",
      "model": "gemini-direct/gemini-2.5-flash",
      "description": "Quick code edits, variable renaming, and styling tweaks."
    },
    "codex": {
      "mode": "subagent",
      "model": "openai/gpt-5.2-codex",
      "description": "Heavy algorithmic coding tasks."
    }
  },
  "providers": {
    "openrouter": {
      "npm": "@ai-sdk/openrouter",
      "name": "OpenRouter",
      "options": {
        "apiKey": "{env:OPENROUTER_API_KEY}"
      }
    },
    "gemini-direct": {
      "npm": "@ai-sdk/google",
      "name": "Google AI Studio Direct",
      "options": {
        "apiKey": "{env:GEMINI_API_KEY}"
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Next, throw your free API keys into your ~/.zshrc or ~/.bashrc:

export OPENROUTER_API_KEY="sk-or-v1-your-key-here"
export GEMINI_API_KEY="AQ.your-google-ai-studio-key"
export GOOGLE_GENERATIVE_AI_API_KEY="$GEMINI_API_KEY"

Enter fullscreen mode Exit fullscreen mode

Don't forget to run source ~/.zshrc to load them up!


5. Daily Workflow

Navigate to your repo and start OpenCode:

cd ~/projects/my-app
opencode

Enter fullscreen mode Exit fullscreen mode
  • Standard Chat: Type normally to ask your heavy-hitter primary model (Claude or Codex) to handle big tasks.
  • Fast Edits: Type @fast rename user_data to userProfile across this component to let Gemini handle it for free without eating into your subscription caps.
  • Planning Mode: Press Tab or type /models to switch to your planning agent when you want to map out a feature before writing code.

Give it a shot and see how much faster (and cheaper) your terminal coding workflow gets!

Top comments (0)