OpenClaw already talks to WhatsApp, Slack, Telegram and even your shell. The missing piece for many of us was a tight loop with an LLM that understands code well enough to write, test and PR without babysitting. Claude Code finally fills that gap. This post shows exactly how I run Claude Code through OpenClaw so I can message my bot from my phone and come back to a passing pipeline — or, when things blow up, know why.

Why pair OpenClaw with Claude Code?

Claude Code (Anthropic’s coding-tuned model, currently 2024-06-10 release) understands long contexts and produces reasonably clean commits. But the raw API gives you a chat box, not an autonomous dev loop. OpenClaw supplies the rest:

  • Browser control to open your IDE or GitHub if needed.
  • Shell access to run npm test, pytest, go vet, etc.
  • Composio integration for GitHub so the agent can open a PR without extra glue.
  • Persistent memory so it remembers previous failures and avoids flapping.

The result: I can send "Fix the flaky token refresh test in auth-service" from Telegram and watch the bot push a green commit.

Prerequisites

  • Node.js 22.2+. I’m on 22.4.0.
  • OpenClaw 0.32.1 or later (earlier builds lack tool-chaining APIs).
  • A Claude API key with at least 200K context quota.
  • A GitHub personal access token scoped to repo and workflow.
  • A Telegram bot token (or Discord bot) for messaging.
  • Optional but nice: a CI that auto-runs on PRs (GitHub Actions, Buildkite, etc.).

Installing OpenClaw 0.32.1 locally

The daemon keeps the agent alive; the gateway is the web UI. One install command handles both:

# macOS / Linux npm install -g openclaw@0.32.1 openclaw daemon --init

That writes ~/.openclaw/config.yml and starts the daemon in the background. Verify:

openclaw status # ⇒ daemon ✅ gateway ✅ version 0.32.1

Running on ClawCloud instead

If you’d rather skip local setup, spin up a hosted agent:

  1. Sign in at cloud.openclaw.ai.
  2. Click “New Agent”, name it claude-coder.
  3. Copy the generated agent token; we’ll need it for the CLI.

The hosted gateway gives you logs and shell right in the browser, but everything else in this article applies 1-to-1.

Connecting Claude Code as a tool

There’s no official plug-in because Claude’s API is just JSON. We glue it in via the generic HTTP tool. Edit ~/.openclaw/tools/claude-code.yml:

name: claude-code endpoint: 'https://api.anthropic.com/v1/messages' method: POST headers: x-api-key: '{{CLAUDE_API_KEY}}' anthropic-version: '2023-06-01' content-type: 'application/json' body: | { 'model': 'claude-3-code-20240610', 'system': '{{system}}', 'messages': {{messages}}, 'max_tokens': 4096 }

Note the single quotes. They spare us from escaping in this JSON blob. Now export the token:

export CLAUDE_API_KEY='sk-ant-xxx'

OpenClaw hot-reloads tool files, so no restart needed.

GitHub integration

Enable the Composio GitHub tool so the agent can push branches and PRs:

openclaw tools enable github --token ghp_xxx --scopes repo,workflow

Wiring Telegram (or Discord) as the trigger

Plenty of users in the Discord channel prefer Discord webhooks, but I live in Telegram. Either way you need one incoming and one outgoing channel.

# Telegram example openclaw connectors add telegram --bot-token 654321:ABCdef --chat-id -100123456 openclaw settings set defaultConnector telegram

Messages sent in that chat now reach the agent. Outgoing messages appear as the bot replying to you.

Drafting the autonomous coding workflow

OpenClaw ships with scratch-task templates under ~/.openclaw/workflows. I adapted the stock fix-bug.yml to call Claude Code instead of the default OpenAI function:

name: fix-bug triggers: - connector: telegram pattern: '^fix ' steps: - run: | echo 'Pull latest code' git pull origin $(git rev-parse --abbrev-ref HEAD) - run: npm test || echo 'tests failed' > /tmp/claw_tests_failed - if: fileExists('/tmp/claw_tests_failed') then: - call: claude-code with: system: | You are an autonomous developer. Fix the failing tests, commit and push. messages: | [ {'role': 'user', 'content': 'Fix the failing tests in my repo.'} ] - run: | npm test && git push origin HEAD:auto-fix-$(date +%s) - call: github.createPR with: title: 'Autofix from OpenClaw' body: 'Tests now pass. Automated PR.'

The pattern means any Telegram message starting with “fix ” fires the workflow. Change the pattern if you want something else like “patch ” or an emoji.

Testing the trigger

  1. Send “fix flaky token refresh test” in your Telegram chat.
  2. Within a second you should see the bot reply “⏳ starting fix-bug workflow”.
  3. On your machine (or ClawCloud UI) tail -f ~/.openclaw/logs/agent.log shows the spawned shell commands and Claude payloads.

Watching the run in real time

For local installs, I prefer htop in one pane and less +F ~/.openclaw/logs/agent.log in the other. On ClawCloud, use the web console.

Every tool call is timed and streamed back to Telegram. Example output trimmed for clarity:

▶ git pull origin main [0.8s] ✔ git pull OK ▶ npm test [22.8s] ✖ npm test 14 failing ▶ claude-code [36.2s] ✔ patch applied 3 files changed ▶ npm test [21.3s] ✔ all tests pass 0 failing ▶ git push [1.1s] branch auto-fix-1718123123 ▶ github.createPR [0.4s] PR #87 opened

Telegram now shows a link to the PR, and GitHub Actions lights up. I rarely need to open a laptop at this point.

Handling errors and edge cases

Claude hallucinated a file path

If the model patches src/foo.js that never existed, git apply will scream. I catch this by piping git apply --check first and aborting early:

- if: run('git apply --check patch.diff') != 0 then: - notify: 'Claude proposed an invalid patch. Aborting.' - stop: true

Timeouts

Claude Code sometimes needs >40s for large diffs. The default HTTP tool timeout is 30s. Bump it:

openclaw settings set http.defaultTimeout 60000 # ms

Telegram message limit

Telegram caps messages at 4,096 characters. Long diffs blow this up. I truncate the diff in the notification and attach the full patch as a GitHub Gist via Composio.

Case study: shipping a Next.js link shortener in 42 minutes

I built a toy SaaS that shortens URLs and logs clicks. All I wrote myself was the spec:

"A user can POST /v1/links with a longUrl. The server returns a 6-char slug. GET /:slug redirects to longUrl and writes a row to Postgres. Tests must cover slug collision and invalid URLs. Deploy to Vercel."

Workflow:

  1. In Telegram: new project link-shortener nextjs
  2. T0+00 — OpenClaw generates a Next.js scaffold via create-next-app.
  3. T0+08 — Claude Code stubs API routes, chooses nanoid for slugs.
  4. T0+14 — First test run: 11 failures. Claude adds input validation.
  5. T0+27 — Second test run: 3 failures. It forgot the redirect header.
  6. T0+34 — All tests pass locally.
  7. T0+36 — Agent pushes auto-init branch and opens PR #1.
  8. T0+40 — GitHub Actions green. Vercel preview URL in PR comment.
  9. T0+42 — I review & merge on my phone while on the subway.

Total human typing: 54 words. Coffee consumption: one mug.

Tips from the field

  • Use branch protection rules. If Claude breaks formatting you can still reject the PR.
  • Keep prompts short but specific. “Make the token test pass” beats “fix everything”.
  • Limit context. I feed only the failing test output & the diff instead of the whole repo.
  • Rotate Claude keys weekly. OpenClaw stores them encrypted but I treat them as short-lived.
  • Log to both disk and connector; Telegram outages happen.

Next steps

If you want to push this further, point OpenClaw at your CI’s REST API so Claude can read test artifacts, or let it auto-merge when coverage stays above threshold. I’ve also started experimenting with a voice interface: a quick Siri Shortcut sends an audio memo, Whisper transcribes it, and the same fix-bug workflow kicks in. But that’s a story for another post.

For now: wire Claude Code into your own agent, set up a trigger phrase, and enjoy shipping patches while standing in line for coffee.