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

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

Leader ●5 ●29 ●86
calendar_today • schedule2 min read
— Originally published at dev.to

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

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


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
    


* **If you have ChatGPT Plus/Pro / OpenAI Codex:**
```bash
npx -y opencode-openai-codex-auth@latest


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}"
      }
    }
  }
}

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"

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

  • 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!

2 Comments

0 votes
2
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

The Sovereign Vault — A Comprehensive Guide to Protocol-Driven AI

Ken W. Algerverified - Jun 4

Attention-Free Score: How Domain Reports Show Which Pages Need Work

ApogeeWatcherverified - Sep 1

Everyone says DeepSeek is cheaper, but I got tired of guessing the exact math. So I built a calculat

abarth23 - Apr 27
chevron_left
6.3k Points • 120 Badges
Cameroon, Douala
22Posts
76Comments
9Connections
Senior Frontend Engineer (4+ Years) | M.Sc. Software Project Management | Frontend Trainer

Related Jobs

View all jobs →

Commenters (This Week)

9 comments
5 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!