# Architecture overview

> How clai parses flags, constructs vendor queriers, executes the agent tool loop, and streams responses.

Canonical URL: https://www.clai.chat/docs/v0.1/concepts/architecture/ · Version: 0.1 · Updated: 2026-10-21

Full site index: https://www.clai.chat/llms.txt

`clai` is structured around strict dependency injection, typed error handling, and vendor-agnostic core interfaces.

## Six-phase workflow

### 1. Query and unix pipes

`cli.Run` parses flags (`-cm`, `-p`, `-t`, `-i`, `-c`, `-r`), reads piped `stdin`, and streams tokens directly to `stdout`.

### 2. Profiles and Agent Skills

`clai` loads `<clai-config-dir>`, merges any selected profile (`-p`), discovers `SKILL.md` Agent Skills, and renders shell context templates (`-sc`).

### 3. MCP servers and builtin tools

When tools are enabled (`-t`), the generic text querier orchestrates tool calls across builtin tools and MCP stdio servers, applying automatic output truncation and `recall` indexing.

### 4. Multi-vendor transcript import

`clai chat` discovers sessions from Claude Code, Codex, OpenCode, Gemini CLI, Qwen, and Antigravity, normalizes them into `GlobalScope`, and resumes them with any vendor.

### 5. The community hub

`clai.chat` hosts one service beside the CLI: the public hub in `cloud/site/hub.ts`. A signed-in user publishes a profile, MCP server, shell context, Skill, theme or prompt; anyone reads and downloads the raw file; a signed-in reader rates it from one to five stars. Nothing syncs on its own, and the hub never runs a config.

See [Go packages (pkg/agent and pkg/tools)](/docs/reference/go-sdk/) to embed this same agent loop in your own Go programs.
