The Problem

Duplicate logic across fourteen API route files creates a maintenance burden: 149 repeated six-line blocks surface in src/app/api/agents/create/route.ts, src/app/api/agents/delete/route.ts, src/app/api/bootstrap/route.ts, and src/app/api/detect-gateway/route.ts, among others. A change to shared validation or gateway interaction must be applied in multiple places, increasing the risk of inconsistency and introducing bugs when updates are missed.

What This Does

ChatClaw is a multi-agent chat platform that lets users create virtual companies, hire AI agent employees, and build teams for collaborative work. It runs as a Next.js 16 application with TypeScript and Tailwind CSS, supporting both IndexedDB (browser default) and Drizzle/ SQLite (server-side) storage. The codebase is organized under src/ (76 files), with API routes under src/app/api/, components under src/components/, and utilities under src/lib/. Runtime logic lives in src/lib/runtime/index.ts, while state is managed by src/lib/store.tsx. The project can operate with authentication disabled for local use or enabled via next-auth v5 for cloud multi-tenant deployment. It connects to an OpenClaw gateway (or any OpenAI-compatible API) via SSE streaming, with avatar picking, file upload, markdown rendering, and agent workspace file editing as core features.

How It Is Wired

Execution starts at init in src/lib/store.tsx:984, which reaches six functions and is called from a single place. The primary user-facing flow originates from sendMessage in src/lib/runtime/index.ts:57, invoked from three call sites. The internal call graph contains 249 resolved call edges; the hub module cn (defined in src/lib/utils.ts) is called from 84 places, making it the widest-reaching utility. Data flows: POST -> getDb occurs 31 times, and POST -> gatewayRpcCall three times. The database layer is handled by src/lib/db-drizzle.ts (22 functions, called from 5 files) and src/lib/db-indexeddb.ts (21 functions). An outbound network call is made via gatewayRpc (called from 8 places), and one function reads or writes files. The module graph shows no circular dependencies across 77 analyzed files, but the duplicated API route logic and the cn hub mean refactoring one path can ripple widely through the codebase.

How To Use It

Setup

git clone https://github.com/moses-y/chatclaw.git
cd chatclaw
pnpm install

Configuration Environment variables are defined in .env.example and loaded by the app. Required vars include:

  • DB_BACKEND=indexeddb (or drizzle for SQLite)
  • AUTH_ENABLED=false
  • AUTH_SECRET=your-secret
  • MULTI_COMPANY=true
  • CHATCLAW_DATA_DIR=./data (for drizzle mode)

The .env.docker file contains committed credentials and must be removed before sharing the repo.

Running it

pnpm dev       # starts Next.js at http://localhost:3000
# or via Docker
docker compose up -d

Real-World Use

A product team sets up a local OpenClaw gateway, clones the repo, and runs pnpm dev. A project manager creates a company, adds three agents with distinct SOUL.md, IDENTITY.md, and TOOLS.md workspace files, and invites them to a team chat. The agents reply sequentially, each seeing the full conversation context. The admin uploads a 128KB avatar via the AvatarPicker, enables AUTH_ENABLED=true for cloud access, and configures the gateway URL through the UI’s JSON editor. Team members join conversations, paste clipboard images that render inline with markdown, and use the collapsible conversation panel to switch between multiple threads per agent.

Code Health & Issues

  • HIGH - Duplicated code blocks across 14 files (149 repeated six-line blocks); fix: extract shared helpers.
  • HIGH - Deep nesting up to level 8 in src/components/dialogs/user-profile-dialog.tsx, src/components/app-sidebar.tsx, and src/components/chat-area.tsx; fix: flatten with guard clauses.
  • HIGH - Oversized files: src/components/chat-area.tsx (687 lines), src/components/ui/sidebar.tsx, and src/lib/store.tsx; fix: split by responsibility.
  • HIGH - High branching density (24 branch points over 68 lines) in src/app/api/agents/create/route.ts, src/app/api/agents/delete/route.ts, and src/app/api/workspace/route.ts; fix: decompose decision logic.
  • HIGH - Third-party GitHub Actions pinned only to tags (docker/login-action@v3, etc.); fix: pin to commit SHAs.
  • HIGH - No test suite; 77 source files with zero test files; fix: add one test per public entry point.
  • HIGH - Committed .env.docker with live credentials; fix: git rm --cached, add to .gitignore, rotate secrets.
  • MEDIUM - No Dependabot or Renovate configuration; fix: commit .github/dependabot.yml.
  • MEDIUM - Dockerfile uses mutable base image node:22-slim; fix: pin by digest.
  • MEDIUM - No dependency vulnerability scanning in CI; fix: add dependency-review-action on pull_request.
  • MEDIUM - No pre-commit secret gate; fix: add hook scanning staged content.
  • LOW - Workflow jobs lack timeout-minutes; fix: add realistic bounds.
  • LOW - Missing .editorconfig, .gitattributes, formatter config; fix: add convention files.

The Bottom Line

The repository offers a functional, well-structured multi-agent chat platform with clear architecture and useful features like workspace file editing and avatar customization. However, the duplicated API logic, outsized files, and absence of tests create tangible risk for anyone planning to extend or maintain the codebase. It is suitable for teams wanting to prototype an OpenClaw-gateway-backed chat system quickly, provided they invest in refactoring the repeated routes and establishing test coverage early.