Back to home

How to Run Claude Code on Raspberry Pi 4 for Free with OpenRouter

5 min read
Homelab

I’ve always loved the idea of having an AI pair programmer living directly in my terminal. While tools like GitHub Copilot are great, there’s something uniquely satisfying about running a lightweight, CLI-based agent on an always-on device like a Raspberry Pi 4 (4GB). This specific Pi model has enough memory to handle Node-based environments smoothly while keeping the setup isolated and the host system clean—a philosophy I apply to all my homelab services, from Pi-hole to Vaultwarden.

Why Claude Code is My New "Homelab Engineer"

On my Pi, Claude Code has become my dedicated homelab engineer. It has revolutionized my workflow by allowing me to set up my desired homelab in minutes instead of hours. Here is how I’m currently putting it to work:

  • Hermes Agent Management: I use it to spin up my Hermes Agent and install new skills. It even writes custom scripts for specific skills that I later pass to the agent.
  • Rapid Infrastructure Deployment: Whether it's configuring Docker containers or managing complex network bridges, I describe the stack, and Claude Code handles the heavy lifting.
  • Web Scraping: I use it to write scripts for web scraping projects that eventually feed data into my wider homelab ecosystem.
  • Always free: Because it lives on the Pi, I can SSH in from anywhere to start a coding session without worrying about running out of credits.

What You'll Need

  • Raspberry Pi 4 (4GB model) running Raspberry Pi OS or Ubuntu
  • OpenRouter Account with an API Key
  • Official Documentation: Refer to the Claude Code Quickstart and the OpenRouter Integration Guide.

Step-by-Step: The Setup

  1. Install Claude Code

The cleanest way to install the tool on a Pi is through the official script.

⚠️ Be Patient: When you first run the installation and initialization, there might be no immediate response. Just trust the process that something is happening.

curl -fsSL https://claude.ai/install.sh | bash
  1. Configure the OpenRouter Bridge

To route Claude Code through OpenRouter, you must set your environment variables to point to their API. You will need to edit your shell profile to make these persistent.

# Open your shell profile in nano
nano ~/.zshrc  # or ~/.bashrc for Bash users

# Add these lines to the file:
export OPENROUTER_API_KEY="<your-openrouter-api-key>"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty

# After saving, restart your terminal for changes to take effect
source ~/.bashrc
  1. Launch and Initialize

Once your environment is configured, simply type claude to start your session and let your new engineer get to work.

The "Free" Setup: Rate Limits and Models

While you can run this entirely for free, the rate limits for free models can be restrictive. Here is my personal strategy for a smoother experience:

The $10 Hack": I highly recommend adding $10 to your OpenRouter account. This unlocks a significantly higher rate limit (up to 1000 requests/day as of today), making the agent much more usable for real homelab tasks.

Budget Safety: You can generate an API key with a spend limit of $0 to ensure you keep your $10 deposit intact while enjoying the higher free-tier limits.

Model Recommendations:

  • My Daily Driver: openai/gpt-oss-120b:free — it has been working great for my scripting needs.
  • One to Try: deepseek/deepseek-v4-flash:free.

Final Thoughts

By combining the low-power reliability of a Raspberry Pi with the agentic power of Claude Code, you can build a sophisticated development environment entirely for free. It keeps your main host system clean and gives you a powerful, "on-call" homelab engineer ready to deploy your next service in minutes.