AIW - AI CLI & MCP Unified Gateway
Unified Router & Proxy for AI CLI Tools and MCP Servers
What is AIW?
AIW is a unified gateway that acts as:
| Layer | Role | What it does |
|---|---|---|
| AI CLI Proxy | Router + Proxy | Route requests to claude/codex/gemini with provider switching, role injection, and transparent parameter forwarding |
| MCP Proxy | Router + Proxy | Route tool calls to multiple MCP servers with intelligent selection, plugin marketplace, and hot-reload |
┌─────────────────────────────────────────────────────────────┐
│ AIW Gateway │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ AI CLI Router │ │ MCP Router │ │
│ │ │ │ │ │
│ │ aiw claude ... ───┼───►│ Claude CLI │ │
│ │ aiw codex ... ───┼───►│ Codex CLI │ │
│ │ aiw gemini ... ───┼───►│ Gemini CLI │ │
│ │ │ │ │ │
│ │ + Provider Switch │ │ aiw mcp serve ────────────►│ │
│ │ + Role Injection │ │ ├─► filesystem server │ │
│ │ + Param Forwarding │ │ ├─► git server │ │
│ │ + CWD Control │ │ ├─► database server │ │
│ │ │ │ └─► ... (plugin market) │ │
│ └─────────────────────┘ └─────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Installation
# Install from NPM
# Verify installation
AI CLI Router & Proxy
Basic Usage
# Route to specific AI CLI
# Auto mode: automatic failover across AI CLIs
# Route to multiple AI CLIs
Provider Switching (-p)
# Switch API provider without changing AI CLI
# Auto-select compatible provider
# Provider config: ~/.aiw/providers.json
Auto Mode (Automatic Failover)
# Auto mode tries CLI+Provider combinations in configured order, switches on failure
# Configure CLI+Provider execution order
Configuration (~/.aiw/config.json):
- Same CLI can be configured with multiple providers (e.g., claude+glm → claude+local → claude+official)
- Provider "auto" means use the CLI's default provider selection
- Order can be fully customized via TUI or direct config editing
Role Injection (-r)
# Inject role prompt before task
# 22 built-in roles + custom roles in ~/.aiw/role/*.md
Working Directory (-C)
# Start AI CLI in specific directory
Git Worktree (Isolated Execution)
AIW automatically creates a git worktree for isolated AI CLI execution.
# AIW automatically creates worktree for git repositories
# After completion, AIW outputs:
# === AIW WORKTREE END ===
# Worktree: /tmp/aiw-worktree-a1b2c3d4
# Branch: main
# Commit: abc123def456
The AI CLI works in a temporary worktree at /tmp/aiw-worktree-<hash>, keeping your working directory clean. Worktree remains after completion for manual review — merge changes or delete as needed.
Transparent Parameter Forwarding
# All unknown flags forwarded to AI CLI
# Order: aiw flags (-r, -p, -C) → AI CLI flags → prompt
Combined Example
# Full example with all options
# ^^^^^^^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
# role provider cwd forwarded prompt
MCP Router & Proxy
Start MCP Server
# Start AIW as MCP server
# Configure in Claude Code (~/.claude/settings.json)
{
}
MCP Server Management
# List configured MCP servers
# Add MCP server
# Enable/disable servers (hot-reload)
# Edit config directly
MCP Registry (Search & Install)
# Browse all available MCP servers (interactive TUI)
# Search across registries (Official + Smithery)
# Get server info
# Install server
Plugin Marketplace
# Browse MCP plugins (interactive TUI)
# Search plugins
# Install plugin
# List/manage installed plugins
# Manage marketplace sources
Task Monitoring
# Show task status
# Wait for all AI CLI tasks to complete
# Wait for specific process
Update
# Update AIW and all AI CLI tools
Configuration Files
| File | Purpose |
|---|---|
~/.aiw/config.json |
AIW global configuration |
~/.aiw/providers.json |
AI provider configurations |
~/.aiw/mcp.json |
MCP server configurations |
~/.aiw/role/*.md |
Custom role prompts |
~/.aiw/settings.json |
Plugin marketplace settings |
~/.aiw/plugins.json |
Installed plugin records |
Global Configuration (~/.aiw/config.json)
| Option | Type | Description |
|---|---|---|
user_roles_dir |
string | Custom directory for user roles (supports ~ expansion). If set, AIW will load user roles from this directory instead of ~/.aiw/role/ |
auto_execution_order |
array | CLI+Provider combinations for auto mode. Each entry has cli (codex/gemini/claude) and provider (provider name or "auto"). Use aiw config cli-order TUI to manage |
This allows you to manage all your roles in a single location, such as ~/.claude/roles/, and share them across different tools.
Using AIW with Claude Code (CLAUDE.md Guide)
When AIW runs as an MCP server inside Claude Code, it can launch background AI CLI tasks (e.g., aiw codex) and manage them via MCP tools. To get the best results, add the following instructions to your project's CLAUDE.md or ~/.claude/CLAUDE.md:
AIW is configured as an MCP server and can launch background AI CLI tasks (codex, gemini, claude) via `start_task` / `manage_task` tools.
Use `aiw codex` (via Bash tool, `run_in_background: true`) for tasks that:
- ----
```bash
aiw codex -r common "implement user authentication module"
aiw codex -r common,frontend-standards "build the landing page"
aiw codex -r common -C /path/to/project "implement feature X"
```
Key flags:
- --
Independent tasks should be launched in parallel using multiple `Bash` calls with `run_in_background: true`:
```
Bash(command="aiw codex -r common 'implement user module'", run_in_background=true, timeout=43200000)
Bash(command="aiw codex -r common 'implement payment module'", run_in_background=true, timeout=43200000)
Bash(command="aiw codex -r common,frontend-standards 'implement frontend pages'", run_in_background=true, timeout=43200000)
```
Dependent tasks must run sequentially — do not parallelize tasks that depend on each other's output.
AIW automatically creates a git worktree (at `/tmp/aiw-worktree-<hash>`) for each task when running inside a git repository. This keeps your working directory clean. After task completion, review the worktree output and merge changes as needed.
1. 2.3.4.5.
Quick Setup
- Configure AIW as MCP server (see MCP Router & Proxy)
- Copy the snippet above into your
CLAUDE.md - Customize roles and providers to match your workflow
Available Roles
Run aiw roles list to see all built-in roles. Common ones:
| Role | Use case |
|---|---|
common |
General-purpose coding (recommended as base) |
frontend-standards |
Frontend development |
database-standards |
Backend / database work |
testing-standards |
Test code |
security |
Security review |
debugger |
Debugging |
devops |
DevOps / infrastructure |
Combine roles with commas: -r common,frontend-standards
License
MIT License - see LICENSE file for details.
AIW - Unified Gateway for AI CLI & MCP | v0.5.60