All articles
Tutorial

Setting up your own AI coding agent with OpenClaw and OpenCode

Stop copying and pasting between ChatGPT and your editor. Here's a step-by-step guide to setting up fully autonomous open-source coding agents like OpenClaw and OpenCode.

9 min read

The era of copypasta is over

We've all been there: asking an LLM to generate a complex refactor, copying the response, pasting it into your editor, finding a syntax error, copying the error back to the chat, getting an apology, and repeating the cycle. It works, but it breaks your context window and your flow state.

What if your AI could just edit the files directly, run the terminal commands to test its changes, read the compilation errors, and fix them autonomously?

This is where next-generation autonomous agents like OpenClaw and OpenCode come in. Let's dive into setting up these local coding agents that actually get work done.

OpenClaw: The Agentic Interface

OpenClaw, originally developed by Peter Steinberger, is a free, open-source autonomous AI agent designed to execute tasks through messaging platforms. Unlike traditional browser-based chat interfaces, OpenClaw operates where you already communicate—Slack, Discord, Telegram, or even iMessage.

Crucially, it is proactive. It has "eyes and hands" to browse the web, read/write files, run shell commands, and control APIs on your local machine.

Setting up OpenClaw for GitHub

OpenClaw shines as an autonomous GitHub contributor. It can manage code sessions, run localized tests, capture errors, and automatically open Pull Requests intelligently.

  1. Install Prerequisites: Ensure you possess the GitHub CLI (gh) and Git installed locally on the host machine.
  2. Launch OpenClaw: Configure OpenClaw's context and skills. The agent stores its context locally, ensuring privacy and adaptive behavior across sessions without leaking your enterprise IP to central servers.
  3. Connect to your workspace: Assign your chosen LLM (OpenClaw is model-agnostic, easily supporting Claude 3.5 Sonnet, OpenAI, or a local DeepSeek model).

Security Note: Because OpenClaw runs shell commands, be cautious of community-contributed skills from the "Claw Hub," as community plugins can occasionally harbor malware. If you are running this in an enterprise environment, look into NemoClaw, NVIDIA's open-source stack that adds strict privacy and security controls to the OpenClaw execution ecosystem.

OpenCode: The Local-First IDE Agent

While OpenClaw is phenomenal for asynchronous background PR generation via messaging apps, what about when you are deep in your editor? This is where OpenCode excels.

OpenCode is a local-first AI coding agent designed from the ground up for privacy and "Bring Your Own Keys" (BYOK) setups. It seamlessly integrates via a Terminal UI, a standalone Desktop App, or a native VS Code Extension.

Why OpenCode stands out:

  • LSP Integration: OpenCode hooks directly into Language Server Protocols (LSP). Instead of hallucinating variable names, it gets type-safe, definition-aware suggestions from your IDE's actual language server.
  • Parallel Agent Sessions: You can spin up a "Plan agent" to map out an architectural refactor in the background, while a "Build agent" actively implements a specific React component simultaneously.
  • Safe Autonomy: It defaults to "Allow/Ask/Deny" permissions, meaning a rogue agent won't easily wipe out your database or push destructive commits without explicit consent.

Getting started with OpenCode

# Install the OpenCode CLI globally
npm install -g opencode-cli

# Initialize it in your current project
opencode init

# Start an autonomous session specifying your model
opencode start --model claude-4.5-sonnet

Once running, you can simply tell it:

"Refactor the authentication flow in src/auth/ to use the new parallelized database schema we discussed in the planning doc."

OpenCode will parse your complete codebase, read the LSP definitions, execute safe shell commands to test the types, and commit the changes as an autonomous unit.

Conclusion

Setting up OpenClaw for asynchronous background tasks and OpenCode for deep, editor-integrated workflows transforms how you write software. Instead of being the typist, you become an orchestrator. You guide the architecture and product decisions, while the agents handle the boilerplate, the typing, and the syntax wrestling.

Give it a try this weekend on a side project—you might find it hard to go back to regular coding.