Back

17. OpenClaw Practice: Building an AI Coding Assistant

This article demonstrates how to build an AI coding assistant with OpenClaw, integrating Claude Code, Codex, and other tools to enable code review, automated testing, CI/CD integration, and more to boost development efficiency.

For OpenClaw v2026.2 | Requires coding-agent, git-workflows, and test-runner skills, plus project codebase access.

TL;DR: Code review: Agent analyzes PR changes and generates review reports. Automated testing: "test-runner": {"frameworks": ["jest", "vitest"]}. CI/CD integration: Webhook receives GitHub/GitLab events. Multi-project management: "projects": {"frontend": {...}, "backend": {...}}. Core command: openclaw agent --message "Review this PR".

Practice Goals

Build an AI coding assistant that can:

  1. Automate code review
  2. Run tests and report results
  3. Generate code documentation
  4. Integrate with CI/CD pipelines
  5. Switch context across multiple projects

Install Required Skills

# Programming-related skills
openclaw skill install coding-agent
openclaw skill install debug-pro
openclaw skill install git-workflows
openclaw skill install docker-essentials

# Testing skills
openclaw skill install test-runner

Code Review Automation

Configure Code Review

---
name: code-review-assistant
version: 1.0.0
description: Automated code review with OpenClaw
triggers:
  - code review
  - PR review
  - review
---

# Code Review Assistant

Automate code review for pull requests.

## Features

- Review code changes
- Check for common issues
- Suggest improvements
- Generate review comments

## Review Checklist

1. **Code Quality**
   - Naming conventions
   - Code structure
   - Error handling

2. **Security**
   - SQL injection
   - XSS vulnerabilities
   - Secret exposure

3. **Performance**
   - N+1 queries
   - Memory leaks
   - Inefficient algorithms

4. **Best Practices**
   - DRY principle
   - SOLID principles
   - Design patterns

Code Review Scenario

User: Review this PR

Agent: Sure, let me review PR #123...

[Fetch PR info]
[Analyze code changes]
[Check for potential issues]

## PR #123 Review Report

### Overview
- Branch: feature/user-search
- Changes: +156 -23
- Files: 8

### Issues Found

**Critical** (1):
- 🚨 `auth.js:45` - Plain-text password storage risk

**Warnings** (3):
- ⚠️ `search.js:23` - Potential SQL injection
- ⚠️ `user.js:78` - Unhandled Promise
- ⚠️ `utils.js:12` - Deprecated API

**Suggestions** (5):
- 💡 Consider adding unit tests
- 💡 Use constants instead of magic numbers
- 💡 Suggest adding error boundaries
- 💡 Consider extracting common methods
- 💡 Suggest adding type annotations

### Code Highlights
- ✅ Good function naming
- ✅ Reasonable module structure
- ✅ Appropriate comments

Would you like me to generate review comments?

Automated Testing

Test Runner Configuration

{
  "skills": {
    "test-runner": {
      "frameworks": ["jest", "vitest", "pytest"],
      "coverage": {
        "enabled": true,
        "threshold": 80
      },
      "reporting": {
        "format": "markdown",
        "output": "test-report.md"
      }
    }
  }
}

Test Scenario

User: Run tests and report results

Agent: Running tests...

[Execute test commands]
[Collect test results]
[Analyze coverage]

## Test Report

### Test Results
- Total: 45 tests
- Passed: 42 ✅
- Failed: 2 ❌
- Skipped: 1 ⏭️

### Failed Tests

**1. UserSearch.test.js**

AssertionError: expected [] to equal [{id: 1, name: ’test’}]

Suggestion: Check database connection or mock data

**2. Auth.test.js**

Timeout: Async callback not invoked within 5000ms

Suggestion: Increase timeout or check async logic

### Coverage

| File | Statements | Branches | Functions | Lines |
|-----|-----|-----|-----|-----|
| auth.js | 85% | 78% | 90% | 85% |
| search.js | 72% | 65% | 80% | 70% |
| user.js | 90% | 85% | 95% | 90% |
| **Total** | **82%** | **76%** | **88%** | **82%** |

Would you like me to fix the failed tests?

CI/CD Integration

GitHub Actions Integration

# .github/workflows/openclaw-review.yml
name: OpenClaw Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup OpenClaw
        run: npm install -g openclaw@latest
        
      - name: Run Review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          openclaw agent --message "Review PR #${{ github.event.pull_request.number }}" \
            --output review-comment.md
            
      - name: Post Comment
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const comment = fs.readFileSync('review-comment.md', 'utf8');
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: comment
            });

Automated Deployment

User: Deploy to staging

Agent: Deploying to staging environment...

[Pull latest code]
[Run tests]
[Build project]
[Deploy to server]

## Deployment Report

### Deployment Info
- Environment: staging
- Branch: main
- Commit: abc1234
- Time: 2026-02-26 15:30

### Deployment Steps
1. ✅ Pull code
2. ✅ Install dependencies
3. ✅ Run tests (45/45 passed)
4. ✅ Build project
5. ✅ Deploy to server

### Health Check
- API: ✅ OK
- Database: ✅ Connected
- Redis: ✅ Connected

### Access URLs
- URL: https://staging.example.com
- API: https://api-staging.example.com

Deployment successful!

Multi-Project Management

Project Configuration

{
  "projects": {
    "frontend": {
      "path": "~/projects/frontend",
      "skills": ["coding-agent", "test-runner"],
      "context": "AGENTS.md"
    },
    "backend": {
      "path": "~/projects/backend",
      "skills": ["coding-agent", "docker-essentials"],
      "context": "AGENTS.md"
    },
    "mobile": {
      "path": "~/projects/mobile",
      "skills": ["coding-agent"],
      "context": "AGENTS.md"
    }
  }
}

Project Switching

User: Switch to backend project

Agent: Switched to backend project.

Current project info:
- Name: backend
- Path: ~/projects/backend
- Stack: Python/FastAPI
- Recent commit: Add user authentication

What would you like me to help with?

Code Generation

Generate Boilerplate Code

User: Create CRUD API for User model

Agent: Sure, I'll create a CRUD API for the User model...

[Analyze existing code structure]
[Generate code files]

Generated the following files:

**1. models/user.py**
```python
from pydantic import BaseModel
from datetime import datetime

class User(BaseModel):
    id: int
    name: str
    email: str
    created_at: datetime
    updated_at: datetime

class UserCreate(BaseModel):
    name: str
    email: str

class UserUpdate(BaseModel):
    name: str | None = None
    email: str | None = None

2. routers/users.py

from fastapi import APIRouter, HTTPException
from models.user import User, UserCreate, UserUpdate

router = APIRouter(prefix="/users", tags=["users"])

@router.get("/", response_model=list[User])
async def list_users(): ...

@router.get("/{user_id}", response_model=User)
async def get_user(user_id: int): ...

@router.post("/", response_model=User)
async def create_user(user: UserCreate): ...

@router.put("/{user_id}", response_model=User)
async def update_user(user_id: int, user: UserUpdate): ...

@router.delete("/{user_id}")
async def delete_user(user_id: int): ...

3. tests/test_users.py

from fastapi.testclient import TestClient

def test_list_users(): ...
def test_create_user(): ...
def test_update_user(): ...
def test_delete_user(): ...

Would you like me to run tests to verify?


## Documentation Generation

### API Documentation

User: Generate documentation for this API

Agent: Analyzing API endpoints…

[Scan route files] [Extract API info] [Generate documentation]

API Documentation

User Module

GET /users

Get user list

Parameters

Name Type Required Description
page int No Page number
limit int No Items per page

Response

{
  "data": [User],
  "total": int,
  "page": int,
  "limit": int
}

POST /users

Create user

Request Body

{
  "name": "string",
  "email": "string"
}

Response

{
  "id": 1,
  "name": "string",
  "email": "string",
  "created_at": "2026-02-26T00:00:00Z",
  "updated_at": "2026-02-26T00:00:00Z"
}

Save to docs/api.md?


## Troubleshooting

### CI/CD Issues

```bash
# Check CI/CD status
openclaw ci status

# View CI/CD logs
openclaw ci logs --last

# Retry failed jobs
openclaw ci retry

Code Issues

# Analyze code issues
openclaw analyze --project backend

# Generate fix suggestions
openclaw suggest --file auth.js

Summary

Building a coding assistant with OpenClaw:

  • Code Review: Automated PR review
  • Test Execution: Automated testing and reporting
  • CI/CD Integration: Automated deployment workflows
  • Multi-Project Management: Quick context switching
  • Code Generation: Boilerplate code generation
  • Documentation Generation: Automatic API documentation

Changelog:

  • 2026-02-26: Initial release

Series Navigation: