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
How it works:
- Reads
auto_execution_orderfrom~/.aiw/config.json - Tries each CLI+Provider combination in order (e.g., codex+auto → gemini+auto → claude+auto)
- Judges success/failure by exit code (0 = success)
- Switches to next combination if current fails
- Failed combinations enter 30-second cooldown period
Configuration (~/.aiw/config.json):
Features:
- Same CLI can be configured with multiple providers (e.g., claude+glm → claude+local → claude+official)
- Each CLI+Provider combination has independent cooldown (30 seconds after failure)
- 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)
New in v0.5.49: AIW automatically creates a git worktree for isolated AI CLI execution.
When you run AIW in a git repository, it:
- Validates the directory is a git repository
- Creates a worktree at
/tmp/aiw-worktree-<8hex> - Executes the AI CLI in the isolated worktree
- Outputs worktree information after task completion
# AIW automatically creates worktree for git repositories
# After completion, AIW outputs:
# === AIW WORKTREE END ===
# Worktree: /tmp/aiw-worktree-a1b2c3d4
# Branch: main
# Commit: abc123def456
Benefits:
- 🛡️ Isolation: AI CLI works in a temporary worktree, keeping your working directory clean
- 🔍 Traceability: Worktree path, branch, and commit are logged for review
- 🧹 No Cleanup: Worktree remains for manual review; you can merge changes or delete it
Error Handling:
- Non-git directory → AIW refuses to run with clear error message
- Worktree already exists → AIW reports the conflict and exits
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.
Quick Reference
# AI CLI routing
# Configuration
# MCP commands
||||
# Plugin commands
||||
# Other commands
License
MIT License - see LICENSE file for details.
AIW - Unified Gateway for AI CLI & MCP | v0.5.48