TR
GitHub
tutorial

OpenClaw + Gemma 4: Run a Free Local AI Agent With Ollama (2026)

Step-by-step guide to running OpenClaw with Gemma 4 via Ollama, completely free, no API key needed. Covers local setup and Ollama Cloud for low-RAM machines.

· 10 min read

Google dropped Gemma 4 on April 2, 2026. It’s the #3 open model in the world, runs entirely on your own hardware, and costs nothing per token. OpenClaw (the open-source AI agent with persistent memory and multi-channel support) connects to it in about five minutes via Ollama.

No API key. No monthly bill. A persistent AI agent that remembers your context, runs scheduled tasks, and responds over Telegram while you’re away from your machine.

As a developer, open source comes first. Before committing to any tool, I always look for an open-source alternative. OpenClaw + Gemma 4 is that answer for personal AI agents.

This is the complete setup guide: Gemma 4 + OpenClaw from zero to running. If Gemma 4 doesn’t fit your hardware, the guide covers Ollama’s other local models and the gemma4:31b-cloud tag for machines without a GPU.

What You’re Actually Installing

OpenClaw runs a local Gateway (a persistent process on your machine) that routes messages from your chat apps to an AI agent runtime. The runtime loads your context (identity, memory, workspace files), compiles it into a system prompt, and sends it to whichever LLM you’ve configured. If the model calls a tool (run shell command, browse a URL, read a file), the runtime executes it and loops.

The result: an assistant that knows who you are, remembers what you were working on last Tuesday, and can act on your behalf 24/7 via cron jobs.

System requirements:

  • Node 24 (recommended) or Node 22.14+
  • macOS, Linux, or Windows (native or WSL2, though WSL2 tends to be more stable)
  • 16GB RAM recommended for local models; 8GB works with smaller Ollama tags or gemma4:31b-cloud

Step 1: Install OpenClaw

Pick one install method, they all end up in the same place.

Option A: Ollama one-liner (easiest)

First, install Ollama if you haven’t already:

# macOS / Linux
curl -fsSL https://ollama.com/install.sh | sh

# macOS via Homebrew
brew install --cask ollama-app

Then run this single command. Ollama will install OpenClaw and configure it with Gemma 4:

ollama launch openclaw --model gemma4 --yes

The --yes flag confirms the npm install automatically. Without it, the command exits with an error asking for confirmation.

Done. Skip to Step 3.


Option B: Official installer script (recommended for everyone else)

Handles Node, dependencies, and first-run onboarding automatically:

# macOS / Linux / WSL2
curl -fsSL https://openclaw.ai/install.sh | bash

# Windows PowerShell
iwr -useb https://openclaw.ai/install.ps1 | iex

Option C: Manual npm install (if you manage Node yourself)

npm install -g openclaw@latest
openclaw onboard --install-daemon

The --install-daemon flag installs OpenClaw as a background service (LaunchAgent on macOS, systemd unit on Linux) so the Gateway starts on login.

If openclaw is not found after install, npm’s global bin directory may not be in your PATH:

export PATH="$(npm config get prefix)/bin:$PATH"

Add that line to your ~/.zshrc or ~/.bashrc to make it permanent.


Verify whichever option you used:

openclaw --version              # confirm the CLI is available
openclaw doctor                 # full health check, fix anything flagged here first
openclaw gateway status         # verify the Gateway is running
openclaw channels status --probe  # check all connected channels

If openclaw gateway status shows Runtime: running, you’re good. Move to Step 2.

If you see nvm warnings like “Gateway service uses Node from a version manager” — these are non-blocking. The gateway still runs fine. You can ignore them for now.

Onboarding walks you through picking a model provider and connecting your first chat channel. You can also do both manually, covered below.

Step 2: Choose Your Model

This guide uses Ollama throughout: local models, no API key, no cost per token. Pick your Gemma 4 size below, or use the cloud tag if your machine doesn’t have enough RAM.

Gemma 4 via Ollama (Free, No API Key)

Gemma 4 was released April 2, 2026 under an Apache 2.0 license, built on the same research as Gemini 3, completely open, zero cost per token. The 31B model currently ranks #3 among open models on the Arena AI leaderboard (lmarena.ai, April 2026), scoring above several closed models many times its size. Native function calling and a 256K context window make it purpose-built for agent workflows.

If you used Option B or C in Step 1, install Ollama now (Option A users already have it):

# macOS / Linux
curl -fsSL https://ollama.com/install.sh | sh

# macOS via Homebrew (also installs the menu bar app)
brew install --cask ollama-app

Pick your Gemma 4 size based on available RAM:

ModelDownloadRAM neededBest for
gemma4:e2b7.2 GB8GBMinimal footprint, CI environments
gemma4:e4b9.6 GB8GBLaptops, constrained hardware
gemma4:26b18 GB16-20GBDaily use, best speed/quality balance
gemma4:31b20 GB24GB+Maximum quality, complex reasoning
gemma4:31b-cloudnoneNoneNo local GPU, runs on Ollama’s cloud

The 26B is a Mixture of Experts that only activates 3.8B parameters during inference, so it’s faster than the size suggests.

# Pull your chosen size (16GB machine, 26b is the sweet spot)
ollama pull gemma4:26b

# Verify it loaded and check GPU acceleration
ollama list
ollama ps

Configure OpenClaw to use it:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "ollama/gemma4:26b"
      }
    }
  },
  "providers": {
    "ollama": {
      "baseUrl": "http://localhost:11434"
    }
  }
}

On an M-series Mac with 16GB RAM, gemma4:26b responds in 2-4 seconds for most tasks. On 8GB, use gemma4:e4b, quality drops on complex reasoning but holds well for automation and day-to-day queries.


More Options

Don’t have the hardware for Gemma 4? Other Ollama models work on lower-spec machines:

ollama pull llama3.1        # 8GB RAM, solid general purpose
ollama pull mistral         # 8GB RAM, faster responses
ollama pull phi3:mini       # 4GB RAM, minimal footprint

Config is identical, just swap the model name:

{
  "agents": { "defaults": { "model": { "primary": "ollama/llama3.1" } } },
  "providers": { "ollama": { "baseUrl": "http://localhost:11434" } }
}

No local GPU? Run Gemma 4 in Ollama’s cloud:

Ollama now offers cloud-hosted versions of its models. gemma4:31b-cloud is the full 31B model running on Ollama’s infrastructure with no download, no RAM requirement, no credit card for personal use. Pull and run it exactly like a local model:

ollama run gemma4:31b-cloud

Then point OpenClaw at it. The config is identical to local, just use the cloud tag:

{
  "agents": {
    "defaults": { "model": { "primary": "ollama/gemma4:31b-cloud" } }
  },
  "providers": {
    "ollama": { "baseUrl": "http://localhost:11434" }
  }
}

The local Ollama daemon handles routing to the cloud, you still use http://localhost:11434 as the base URL.

Step 3: Verify With the Dashboard First

Before connecting any chat app, confirm your core setup (model, auth, gateway) is working. Run this command:

openclaw dashboard

This generates a tokenized URL and opens it in your browser automatically. Do not open http://127.0.0.1:18789 directly — you’ll land on a login screen asking for a gateway token. The openclaw dashboard command handles the token for you.

Once the dashboard opens, you’ll see the chat UI with gemma4 · ollama shown in the model selector. Send a message. If you get a response, everything is wired up correctly.

Memory search warnings are normal. Running openclaw doctor will flag that no embedding provider is configured (OpenAI, Google, etc.). This only affects semantic memory recall — basic chat, tools, and automation all work fine without it. You can ignore these warnings when using Ollama locally.

Do this before Telegram, Discord, or anything else. It takes 30 seconds and saves you from debugging the wrong layer. When a channel later stops responding, you can open the dashboard, confirm it works there, and know immediately the problem is the channel config, not the gateway or model.

Keep the dashboard on localhost. It has admin access to your entire setup. For remote access, use Tailscale or an SSH tunnel rather than exposing port 18789 publicly.

Step 4: Connect a Chat Channel

The Gateway routes messages from wherever you chat to the agent runtime. Connect Telegram first, it’s the simplest setup.

Telegram:

  1. Open Telegram and message @BotFather
  2. Create a bot: /newbot, follow the prompts, copy the API token
  3. Add to ~/.openclaw/openclaw.json:
{
  "channels": {
    "telegram": {
      "enabled": true,
      "botToken": "YOUR_BOT_TOKEN",
      "dmPolicy": "pairing"
    }
  }
}
  1. Restart the gateway: openclaw gateway restart

dmPolicy: "pairing" means the bot requires your approval before accepting messages from a new contact. The right default for personal use. Without it, anyone who finds your bot can message it.

Discord:

  1. Create an application at discord.com/developers
  2. Add a bot, copy the token
  3. Enable Message Content Intent in the Bot settings
  4. Add to config:
{
  "channels": {
    "discord": {
      "enabled": true,
      "botToken": "YOUR_DISCORD_BOT_TOKEN",
      "dmPolicy": "pairing"
    }
  }
}
  1. Restart: openclaw gateway restart

Slack: Needs both a bot token (xoxb-) and an app token (xapp-) for socket mode. Create a Slack app at api.slack.com/apps, enable Socket Mode, add scopes chat:write, channels:history, im:history, app_mention, then add both tokens to your config.

Step 5: Configure Your Identity Files

OpenClaw loads a few Markdown files at the start of every session. These are what make the agent actually know who you are.

workspace/
├── SOUL.md          # agent personality and behavior rules
├── IDENTITY.md      # who the agent is
├── USER.md          # who you are, your preferences, context, stack
├── HEARTBEAT.md     # scheduled/periodic tasks (cron)
├── memory/          # persistent memory written by the agent
└── skills/          # skill files for extra capabilities

Edit USER.md first, it is the highest-leverage file:

# User Profile

Name: Tarik
Role: Product engineer, solo founder
Stack: Astro, TypeScript, Cloudflare Workers, Bun
Current projects: tarikrazine.com (portfolio + blog)
Preferences:
- Concise responses, no filler
- Show the code first, explain after
- Prefer bun over npm
Communication: Telegram (primary), Discord (team)

The agent reads this at the start of every conversation. You’ll never re-explain your setup again.

These aren’t set by default. Add them to ~/.openclaw/openclaw.json, they make a real difference once you start running automation:

{
  "agents": {
    "defaults": {
      "compaction": { "mode": "safeguard" },
      "maxConcurrent": 4,
      "subagents": { "maxConcurrent": 8 }
    }
  },
  "messages": { "ackReactionScope": "group-mentions" }
}

What each setting does:

  • compaction: safeguard: prevents silent context loss when conversations get long. Without this, the agent can hit token limits and quietly drop earlier context mid-task. Critical for HEARTBEAT automation.
  • maxConcurrent: 4: limits parallel tasks. Raise it for heavy parallel workloads, lower it on constrained hardware.
  • ackReactionScope: group-mentions: in group chats, the bot only reacts when directly mentioned. Prevents it from responding to every message in a shared channel.

Step 6: Your First Automated Task

HEARTBEAT.md defines scheduled tasks. The gateway runs it every 30 minutes by default. This is where the “agent that works while you sleep” part comes from.

A simple daily briefing:

# HEARTBEAT

## Daily Dev Briefing
Schedule: every weekday at 08:00

1. Run `git log --oneline --since="24 hours ago"` in my project directories
2. Check if any GitHub Actions failed yesterday
3. Fetch the top 3 items from my RSS feeds
4. Send a summary to Telegram

Keep it under 200 words. Bullet points only.

Restart the gateway after editing HEARTBEAT:

openclaw gateway restart

From this point on, you get a morning briefing every weekday without lifting a finger.

Step 7: Install a Skill

Skills are Markdown files in your skills/ folder that teach the agent when and how to use tools for specific tasks. Think of them as persistent system prompt additions for a particular capability.

The ClawHub marketplace has thousands of community skills. Install one:

# Browse and install from ClawHub
openclaw skills search github
openclaw skills install github-summary

Or write your own. Drop a Markdown file in skills/:

# Skill: Deployment Monitor

When asked about deployment status or when a deployment alert arrives:
1. Run `wrangler tail --format=json` to check recent errors
2. Check the last 5 deployments with `wrangler deployments list`
3. Summarize the status and flag any errors
4. If there are errors, suggest likely causes based on the error message

The agent now knows how to check your Cloudflare deployments when you ask, or when a monitoring hook fires.

Security: What to Know Before Running This

OpenClaw runs on your machine with shell access, file access, and browser control. That power is what makes it useful. It’s also a real attack surface.

Lock down the gateway config. Verify your ~/.openclaw/openclaw.json has these settings, onboarding should set them, but check:

{
  "gateway": {
    "mode": "local",
    "bind": "loopback",
    "auth": { "mode": "token" }
  }
}

"bind": "loopback" means the gateway only listens on 127.0.0.1. If this gets changed to 0.0.0.0, your gateway is exposed to your entire network. "auth": { "mode": "token" } ensures every request authenticates. Turning it off lets anything on your machine talk to the agent.

Vet skills before installing. Early 2026 brought the ClawHavoc campaign with 1,467 malicious skills distributed through ClawHub using typosquatted names. ClawHub now requires code signing and partners with VirusTotal for scanning, but the registry is safer, not safe. Before installing any skill: check the VirusTotal scan on the listing page, stick to verified authors, and read the source if it executes shell commands.

Run it in a container for production use. For personal use on your own machine, running natively is fine if you’re careful. For anything serving a team or exposed to the internet, containerize it:

docker run -d \
  --name openclaw \
  -v ~/.openclaw/workspace:/workspace \
  -p 18789:18789 \
  openclaw/openclaw:latest

Key Takeaways

  • OpenClaw is a local gateway, not a model. It gives any LLM persistent memory, real tool access, and multi-channel presence across Telegram, Discord, Slack, and WhatsApp.
  • Gemma 4 + Ollama is the best free setup. gemma4:26b on 16GB RAM, zero cost, fully offline, currently #3 open model on the Arena AI leaderboard. Start here.
  • No local GPU? Use gemma4:31b-cloud, the same Gemma 4 model, runs on Ollama’s infrastructure, no RAM requirement, no API key needed.
  • On 8GB RAM? gemma4:e4b runs locally. Quality drops on complex reasoning but holds well for automation and day-to-day queries.
  • USER.md is the highest-leverage config file, write it before anything else.
  • HEARTBEAT.md is how you get an agent that runs without you. Start with one morning briefing task.
  • Always verify with the dashboard (openclaw dashboard) before connecting any channel.
  • Vet every ClawHub skill before installing, check the VirusTotal scan and read the source.

If you’re already running automation with n8n, OpenClaw layers on top as the ambient agent, the thing that handles everything conversational and context-dependent that doesn’t fit a rigid workflow node. They complement each other well.