Run OpenClaw with Ollama Locally

Set up a private AI assistant on your Mac and chat with it via Telegram.

Introduction

30 Second Summary

Every conversation you send to a cloud AI service passes through someone else's servers. Running an AI assistant locally keeps everything on your own machine.

In this project, you will install OpenClaw through Ollama to run a personal AI assistant entirely on your Mac. You will connect it to Telegram so you can chat with your own private AI from your phone.

What You'll Build

A self-hosted AI assistant running on your Mac, powered by a local language model and accessible from your phone through a Telegram bot.

By the end of this project, you'll have:

  • A running OpenClaw gateway with gemma4 as the primary model.
  • A Telegram bot connected to your local assistant.
  • A verified end-to-end conversation from Telegram to your local LLM and back.
  • Secret Mission: Create a custom skill that teaches your assistant a personalized workflow.

Are there any prerequisites?

This project assumes you already have Ollama installed with the gemma4 model pulled, Node.js 22.19 or higher, and a Telegram account. Make sure all three are in place before starting Step 1.

Before We Start

Before We Start...

Set Up OpenClaw with Ollama

You have Ollama and gemma4 ready on your Mac. To turn that local model into a personal assistant you can message from other apps, you need a gateway to sit in front of it and manage conversations.

OpenClaw is an AI agent gateway built for exactly this. In this step, you'll install it through Ollama and launch it with your gemma4 model.

In this step, get ready to:
  • Launch OpenClaw through Ollama with the right context window settings.
  • Verify the gateway is running and gemma4 is loaded.
Set the context window and launch OpenClaw

Ollama defaults to a 4K token context window on machines with less than 24 GiB of memory. Your M1 Mac with 16 GB falls into this tier. OpenClaw needs at least 64K tokens for agent tasks, so you need to override this default before launching.

What is a context window?

A context window is the amount of text an LLM can process in a single conversation. Think of it as the model's short-term memory.

Without the override, your assistant would only remember about 4,000 tokens of conversation. Setting it to 64,000 gives OpenClaw enough room for agent tasks like web search and tool use.

  • Launch OpenClaw with the correct context window by running this command. This starts an interactive setup that walks you through a few prompts:
OLLAMA_CONTEXT_LENGTH=64000 ollama launch openclaw

What does this command do?

OLLAMA_CONTEXT_LENGTH=64000 tells Ollama to allocate 64,000 tokens of context for the model. Without this, your M1 Mac would default to only 4,000 tokens.

ollama launch openclaw installs OpenClaw through npm (if not already installed), configures it to use your local Ollama server, and starts the gateway.

The command starts an interactive setup flow. Follow these prompts as they appear:

  • If Ollama prompts you to install OpenClaw via npm, accept the installation.
  • A security notice about tool access appears on first launch. Read through it and accept.
  • When the model selector appears, choose gemma4 from the list.

After you select the model, Ollama configures the provider, installs the gateway daemon, and enables web search automatically. The OpenClaw TUI (terminal user interface) opens when setup is complete.

You should see a chat prompt in the TUI. The gateway is now active on port 18789.

OpenClaw didn't launch?

  • Make sure Ollama is running before you launch OpenClaw. You can check by running ollama ps in a separate terminal tab.
  • If the npm install fails, check that Node.js is installed by running node --version. You need version 22.19 or higher.
  • If you don't see gemma4 in the model selector, confirm the model is pulled by running ollama list in another terminal tab.

Help me troubleshoot why ollama launch openclaw failed.

Verify the gateway is running

The TUI is running in your current terminal tab. To run verification commands, you need a new tab.

  • Press Cmd+T to open a new terminal tab.
  • Check the gateway status by running this command:
ollama ps

You should see gemma4 in the output table with a CONTEXT column showing 64000 (or close to it) and the PROCESSOR column showing 100% GPU.

  • Verify OpenClaw itself by running:
openclaw --version

You should see a version number in the output.

Not seeing the right output?

  • If ollama ps shows nothing, your gateway may have stopped. Switch back to the terminal tab running OpenClaw and check for error messages.
  • If the CONTEXT column shows 4096 instead of 64000, stop the gateway and relaunch with OLLAMA_CONTEXT_LENGTH=64000 prepended to the command.
  • If openclaw --version returns 'command not found', the npm install during launch may not have completed. Try running npm install -g openclaw@latest manually.

Help me figure out why my OpenClaw gateway is not showing the right context window or version.

Your OpenClaw gateway is up and running with gemma4 loaded at the right context window. Next up, you'll test your assistant by chatting with it through the built-in browser dashboard.

Test Your Assistant via WebChat

In the previous step, you installed OpenClaw through Ollama and confirmed that gemma4 is loaded with a 64K context window. Now it is time to make sure your assistant can actually hold a conversation.

OpenClaw includes a built-in browser dashboard called the Control UI. The WebChat panel inside it connects directly to your local gateway, so you can test without setting up any messaging channels first.

In this step, get ready to:
  • Open the OpenClaw Control UI dashboard in your browser.
  • Send a test message and confirm gemma4 responds.
  • Review the bundled skills your assistant comes with.
Open the Control UI

The Control UI is a browser-based dashboard that lets you chat with your assistant without setting up any external channels first. It connects directly to your local gateway on port 18789.

  • Open the dashboard by running this command in your other terminal tab (the one not running the OpenClaw TUI):
openclaw dashboard
  • Confirm your default browser opens with the OpenClaw Control UI loaded. You should see a WebChat panel ready for input.

Browser didn't open?

If the browser did not launch automatically, open it manually and navigate to http://127.0.0.1:18789/.

If the page does not load, make sure the OpenClaw TUI is still running in your other terminal tab. The gateway must be active for the dashboard to connect.

Help me troubleshoot the Control UI connection

Send a test message

The WebChat panel talks directly to your local gemma4 model through the gateway. Sending a message here proves the entire pipeline works before you add Telegram.

  • In the WebChat panel, type or paste this message and press Enter:
What can you help me with? List 3 things you can do.

Watch the response stream back from gemma4. You should see a coherent reply listing capabilities your assistant can help with.

Response speed on M1

Since gemma4 is a 9.6 GB model running locally on 16 GB of RAM, expect responses to take a few seconds. This is completely normal for local inference on Apple Silicon.

Not getting a response?

Switch to the terminal tab running the OpenClaw TUI and confirm it still shows the gateway as running. If the TUI has exited, relaunch it with the same command from Step 1:

OLLAMA_CONTEXT_LENGTH=64000 ollama launch openclaw

You can also check that gemma4 is still loaded by running ollama ps in a separate terminal tab.

Help me fix the WebChat response issue

Check your skills

Skills are markdown instruction files that teach your assistant how and when to use its tools. OpenClaw comes with a set of bundled skills out of the box.

  • List the skills loaded in your assistant by running this command:
openclaw skills list

What does this command show?

The output lists every skill currently loaded by OpenClaw, including the skill name, a short description, and its file location. These bundled skills cover common workflows that your assistant can use right away.

Take note of the skills directory path shown in the output. You will use this path in the Secret Mission when you create a custom skill.

  • Confirm you see a list of skill names printed to the terminal.
  • Note the skills directory path from the output for later use.

No skills showing up?

Make sure the gateway is still running. Skills load when the gateway starts, so if the gateway has restarted or stopped, the list may be empty.

Try running openclaw --version to confirm the CLI is still accessible. If the command is not found, you may need to open a new terminal tab so the shell picks up the correct PATH.

Help me fix the skills list

Your assistant is confirmed working through the WebChat dashboard. Next up, you will create a Telegram bot and connect it to your local gateway so you can chat with your AI from your phone.

Create a Telegram Bot with BotFather

Your assistant is working. You tested it through the WebChat dashboard and confirmed that gemma4 responds to messages locally.

The WebChat dashboard is useful for quick tests, but it requires you to be at your computer. In this step, you will connect your assistant to Telegram so you can message it from your phone or any device.

In this step, get ready to:
  • Create a Telegram bot using BotFather and obtain your bot token.
  • Add the bot as a messaging channel in OpenClaw.
  • Approve DM pairing and verify messages flow from Telegram to your local model.
Create the bot in Telegram

Telegram bots are created through a special account called @BotFather. BotFather generates a unique token for each bot, and OpenClaw uses this token to send and receive messages through your bot.

  • Open Telegram on your phone or desktop.
  • Search for @BotFather in the search bar.
  • Confirm the handle shows exactly @BotFather with a verified checkmark.
  • Send /newbot to start creating your bot.
  • BotFather asks for a display name. Type My Local AI and send it.
  • BotFather asks for a username. This must end in bot and be 5 to 32 characters long. Type a unique name like mylocalai_bot and send it.
  • BotFather responds with your bot token. It looks like 123456789:ABCdefGhIjKlMnOpQrStUvWxYz.
  • Copy this token and keep it somewhere safe.

Keep your token private

Your bot token is like a password. Anyone with the token can control your bot. Do not share it publicly or commit it to version control.

The username you chose cannot be changed later, but the display name can be updated anytime through BotFather.

Username already taken?

Telegram bot usernames must be globally unique. Try adding numbers or your initials to make yours unique, for example mylocalai_2025_bot.

Make sure the username ends with bot and uses only Latin letters, numbers, and underscores. BotFather will reject it otherwise.

Help me create a Telegram bot username that BotFather accepts.

Configure the Telegram channel in OpenClaw

Now that you have a bot token, you can register it with OpenClaw. OpenClaw treats each messaging platform as a channel, which is a bridge between the platform and your local gateway.

  • In your terminal, add Telegram as a channel by running this command:
openclaw channels add --channel telegram --token your-bot-token-here
  • Replace your-bot-token-here with the actual token you copied from BotFather.

What does this command do?

The --channel telegram flag tells OpenClaw which messaging platform to configure. The --token flag passes your bot's authentication token so OpenClaw can connect to it.

OpenClaw also sets the DM policy to pairing by default. This means you will need to approve your first message before the bot starts responding. You will do this in the next substep.

  • You should see a confirmation message that Telegram has been configured.

Command not working?

Make sure the token has no extra spaces before or after it. Check that you copied the entire token, including the numbers before the colon.

If you see an error about OpenClaw not being found, make sure the gateway was launched at least once with ollama launch openclaw before running channel commands.

Help me troubleshoot why OpenClaw is not accepting my Telegram bot token.

Prefer an interactive wizard?

You can also configure Telegram through a guided wizard that walks you through each option. Run:

openclaw configure --section channels

The wizard prompts you to select Telegram and enter your token step by step.

Restart the gateway and approve pairing

The gateway loads channel configurations at startup. Adding a new channel while the gateway is running requires a restart for the change to take effect.

  • Restart the gateway by running these commands:
openclaw gateway stop
OLLAMA_CONTEXT_LENGTH=64000 ollama launch openclaw

What do these commands do?

The first command stops the running gateway. The second command relaunches it with the same 64K context window setting you used earlier.

Since OpenClaw is already installed and configured, you will not see the initial setup prompts again. The gateway starts directly with your existing settings, now including the Telegram channel.

Now you need to pair your Telegram account with the bot. OpenClaw uses DM pairing by default to prevent strangers from using your bot.

What is DM pairing?

The first time you message the bot, OpenClaw generates a one-time pairing code instead of responding. You approve this code through the terminal, and from then on your Telegram account is linked to the bot.

This keeps your assistant private. Only approved accounts can trigger responses from your local model.

  • Open Telegram and search for the bot username you created (e.g. mylocalai_bot).
  • Send /start to the bot.
  • Send a follow-up message like Hello!.

The bot will not respond yet. OpenClaw is waiting for you to approve the pairing.

  • Open a new terminal tab.
  • Check for the pairing code by running:
openclaw pairing list telegram
  • Find the pairing code in the output.
  • Approve the pairing by running this command:
openclaw pairing approve telegram [[PAIRING_CODE="your pairing code from above"]]
  • Return to Telegram and send another message to your bot, like What can you help me with?.
  • You should see a response from your local gemma4 model appear in the Telegram chat.

Bot not responding after approving?

Make sure the gateway is running. Check the terminal tab where you relaunched OpenClaw for any error messages.

If you do not see a pairing code when you run openclaw pairing list telegram, try sending another message to the bot in Telegram first. The pairing code is only generated after the bot receives a message.

You can also verify gemma4 is loaded by running ollama ps in a new tab.

Help me figure out why my Telegram bot is not responding after I approved DM pairing.

Your assistant is now reachable from Telegram. Next up, you will put it to work with a real coding task and watch the full request lifecycle in the logs.

Have a Real Conversation from Telegram

Your Telegram bot is live and paired. Every message you send travels from your phone, through the OpenClaw gateway, to gemma4 running on your Mac, and back again.

In this step, you will send a real coding task to your assistant and verify the full message lifecycle using OpenClaw's logs.

In this step, get ready to:
  • Send a real coding task to your Telegram bot and receive a response from gemma4.
  • Verify the end-to-end message flow from Telegram through your local gateway and back.
Ask your assistant to do something useful

A coding task is a good stress test for your local assistant. It pushes gemma4 beyond simple greetings and forces it to reason about structure, logic, and valid syntax.

  • Switch back to your bot conversation in Telegram.
  • Send the following message to your bot:
Write me a short Python script that reads a CSV file and prints the top 5 rows sorted by a column the user specifies as a command-line argument.

What should I see?

Since gemma4 is running locally on your M1 Mac, responses take a few seconds to start streaming. This is normal for a 9.6 GB model running on 16 GB of RAM.

Your bot should reply with a Python script that handles CSV reading and sorting. The exact output varies because it is generated by a language model, but you should see a complete, coherent code block.

Bot not responding?

  • Switch to the terminal tab running the OpenClaw gateway and check for error messages. If the gateway has stopped, restart it with OLLAMA_CONTEXT_LENGTH=64000 ollama launch openclaw.
  • Confirm your DM pairing is still active by running openclaw pairing list telegram in a separate terminal tab.
  • Make sure you are messaging the correct bot. Search for the username you created (e.g. mylocalai_bot) in Telegram.
  • My Telegram bot is not responding to my messages. How can I debug the OpenClaw gateway connection?
Verify the end-to-end flow

Seeing a response in Telegram confirms the connection works. The logs let you trace every hop the message takes through the full pipeline.

  • Open a new terminal tab by pressing Cmd+T (macOS) or Ctrl+Shift+T (Windows).
  • Start streaming the live gateway logs by running this command:
openclaw logs --follow

What does this command do?

The --follow flag keeps the log stream open so new entries appear in real time as messages flow through the gateway. Press Ctrl+C when you are done watching.

  • Switch back to Telegram and send your bot another message, like:
Explain the difference between a list and a tuple in Python.
  • Switch back to your terminal tab running the logs.

You should see log entries showing the message arrive from Telegram, get routed through the OpenClaw gateway, pass to Ollama and gemma4, and the response travel back to Telegram.

Logs not showing any activity?

  • Make sure you sent a new message in Telegram after starting the openclaw logs --follow command. The --follow flag only streams new entries, not past ones.
  • Check that the OpenClaw gateway is still running in your other terminal tab. If it has stopped, restart it and try the logs command again.
  • If the gateway seems unreachable, check for error messages in the gateway terminal tab. A network or process issue may have interrupted the connection.
  • My OpenClaw logs are not showing message activity from Telegram. How can I troubleshoot the gateway log stream?

Secret mission

Create a Custom Skill

Your assistant can chat, but what if it could guide you through specific workflows? In this secret mission, you will create a custom skill from scratch by writing a SKILL.md file. Your assistant will learn how to run a daily standup and format a summary you can paste into your team chat.

Clean Up Your Resources

Clean Up Your Resources

This project runs entirely on your local machine, so there are no ongoing cloud costs. Decide whether to keep your resources running, pause them to come back later, or delete them entirely.

Resources you used:

  • OpenClaw gateway running on port 18789.
  • OpenClaw npm package (globally installed).
  • OpenClaw configuration and workspace at ~/.openclaw/.
  • Telegram bot created via @BotFather.

Keep everything running

No action needed. Choose this if you are still actively building or want to keep chatting with your assistant from Telegram.

  • Your OpenClaw gateway continues running in the background and responds to Telegram messages.
  • Your custom daily-standup skill stays loaded and ready to use.
  • Ollama and gemma4 were already installed before this project and remain on your machine regardless.

Pause - I'll come back to this later

Shut down the gateway to free up memory and GPU resources. Your configuration and skill files stay on disk so you can restart later.

  • Stop the OpenClaw gateway by running:
openclaw gateway stop

Your Telegram bot stays registered with BotFather. It stops responding until you relaunch the gateway.

  • Resume your assistant later by running:
OLLAMA_CONTEXT_LENGTH=64000 ollama launch openclaw

Delete - I don't want to use this again

Remove all project resources and start fresh. This is permanent.

  • Stop the OpenClaw gateway by running:
openclaw gateway stop
  • Remove the OpenClaw configuration and workspace directory by running:
rm -rf ~/.openclaw/
  • Uninstall the OpenClaw npm package by running:
npm uninstall -g openclaw
  • Delete your Telegram bot. Open Telegram and search for @BotFather.
  • Send /deletebot.
  • Select the bot you created and confirm the deletion. This frees the bot username and is irreversible.

What about Ollama and gemma4?

Ollama and the gemma4 model were already on your machine before this project. They are not removed by these cleanup steps.

If you want to remove gemma4 separately, you can run ollama rm gemma4 at any time.

Nice Work!

Nice Work!

You just built a fully private AI assistant that runs entirely on your Mac. You can now message it from Telegram anytime, and every conversation stays local on your machine.

You've learned how to:

  • Installed OpenClaw through Ollama and configured a 64K context window so your M1 Mac can handle real agent tasks.
  • Created a Telegram bot with BotFather and connected it to your local OpenClaw gateway with DM pairing.
  • Had a real end-to-end conversation flowing from Telegram through your local gemma4 model and back, verified through the gateway logs.
  • Secret Mission: Created a custom daily-standup skill with a SKILL.md file and tested it from Telegram.

Ready to quiz yourself?