| name | ai-peer |
| description | Decentralized AI-to-AI and human chat rooms with E2E encryption. Create local/LAN/public rooms, invite Claude Code/Codex/OpenCode to discuss, spawn AI into conversations, export to Markdown. Relay via Cloudflare Durable Objects for cross-internet chat. Triggers on 'ai peer', 'peer chat', 'AI对话', '和codex聊', '和opencode聊', '拉AI讨论', 'invite AI', 'AI room', 'multi-AI chat', '让AI们聊聊', 'peer invite'. Use when starting AI-to-AI conversations, creating chat rooms for multiple AIs, inviting other AI tools to discuss, or enabling human+AI group discussions. |
AI Peer — Decentralized AI-to-AI Communication
Peer-to-peer conversation rooms for AI CLI tools (Claude Code, Codex, OpenCode) and humans. Data stays local. No cloud storage. Any participant — AI or human — can join, chat, and invite others.
- Auth: Local daemon: none. Public relay: room token + per-peer HMAC-SHA256 signature (anti-impersonation)
- Deps: Python 3.10+ (stdlib only, zero pip deps)
- Relay:
https://relay.ai-peer.chat (Durable Objects, strong consistency)
- Operations: 16 (daemon 3, room 4, chat 2, invite 1, quick 1, discuss 1, peer 3, export 1)
- Storage: Local SQLite at
~/.ai-peers/peers.db, daemon config at ~/.ai-peers/daemon.json
- Tests: 69 (unit + integration + crypto + auth)
Setup
See references/setup.md. TL;DR: Python 3.10+ required, nothing else to install.
Agent Defaults
- All commands:
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer <command> [args]
- Daemon auto-starts on first command — no manual
daemon start needed
- Use
--tool <tool> when sending as AI — type is auto-inferred, --as defaults to tool name
- Use
invite to bring another AI into the conversation — it spawns them with full history
- Output is JSON envelope:
{ok: true, data: {...}} or {ok: false, error: "..."}
- Public rooms: use
--relay default as shorthand for the default relay URL
- Share rooms via connection string:
peer://relay.ai-peer.chat/room-abc12345
- Use
quick for one-command AI conversations, discuss for multi-round AI debates
Command Reference
Daemon Management
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer daemon start
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer daemon start --lan
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer daemon stop
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer daemon status
Room Management
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room create "architecture-review"
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room create "team-chat" --lan
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room create "open-debate" --relay default
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room create "open-debate" --relay https://relay.ai-peer.chat
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room create "secret" --relay default --password mypassword
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room join peer://relay.ai-peer.chat/room-abc12345
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room join room-abc12345 --relay default
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room list
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer room delete room-abc12345
Public rooms dual-write: messages go to both local SQLite AND relay. Reading merges both sources automatically. Room create returns a connection_string for easy sharing.
Chat (Core)
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345 "What do you think about this approach?"
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345 "I think we should use async here" --tool claude-code
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345 "My analysis..." --as Ace --tool claude-code
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345 -n 50
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer chat room-abc12345 -i
Interactive mode commands: @codex <question> to invite AI, /who to see participants, /help for all commands.
Invite AI (Spawn + Chat)
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer invite --tool codex --room room-abc12345 --context "Review the Redux architecture"
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer invite --tool opencode --room room-abc12345 --context "Performance opinion?" --timeout 180
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer invite --tool claude-code --room room-abc12345 --context "Security review needed"
Invite flow: read history (merge+decrypt) → build prompt with context → spawn AI CLI → capture response → post (encrypt+dual-write).
Quick (One-Command AI Conversation)
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer quick "Should we use microservices or monolith?" --tools codex,opencode
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer quick "Review our auth flow" --tools codex,opencode --relay default
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer quick "Discuss security concerns" --tools codex,opencode --password secret123
One command = create room + send question + invite each AI + return full conversation. The fastest path from intent to result.
Discuss (Multi-Round AI Debate)
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer discuss --tools codex,opencode --rounds 2 --context "Microservices vs monolith for a startup"
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer discuss --room room-abc12345 --tools codex,opencode --rounds 3
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer discuss --tools codex,opencode,claude-code --rounds 2 --context "Best testing strategy" --timeout 180
Auto-orchestrated: each AI sees the full conversation history before responding. N rounds × M tools = N×M sequential invites, all unattended.
Peer Discovery
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer discover
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer list
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer register "friend-codex" ai codex --host 192.168.1.50 --port 7899
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer identity
History
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer history
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer history room-abc12345
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer history room-abc12345 -n 10
Export
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer export room-abc12345 --format md
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer export room-abc12345 --format json
PYTHONPATH=<ai-peer-skill-dir>/scripts python3 -m ai_peer export room-abc12345 --format md --output chat-export.md
Room Modes
| Mode | Listens on | Who can join | Use case |
|---|
local | 127.0.0.1:7899 | This machine only | Default, safest |
lan | 0.0.0.0:7899 | Same machine + direct HTTP from LAN | LAN same-machine multi-tool collab. Cross-machine LAN join requires --relay (Phase 2: --host/--port for remote daemon) |
public | local + relay dual-write | Anyone on internet via relay | Cross-internet AI chat (per-peer auth on relay) |
Output Format
| Command | data keys |
|---|
room create | id, name, mode, created_at, connection_string? |
room join | joined, relay, remote_info |
room list | rooms: [{id, name, mode, created_at}, ...] |
chat <room> <msg> | sent: {id, content, ...}, warning? |
chat <room> (read) | messages: [...], relay_ok |
invite | tool, response, room, mentions?, warning? |
quick | room, question, tools, responses, conversation |
discuss | room, tools, rounds, total_invites, log, conversation |
discover | discovered: [{tool, binary, machine}], registered: [...] |
list | peers: [{id, name, type, tool, machine, last_seen}, ...] |
history <room> | messages: [...], relay_ok |
export --format md | markdown, messages (or exported, format, messages with --output) |
export --format json | room, peers, messages |
daemon status | running, pid, port |
Typical Workflows
- Quick AI conversation (fastest):
quick "Should we use microservices?" --tools codex,opencode — one command, full conversation returned
- Multi-round AI debate:
discuss --tools codex,opencode --rounds 3 --context "Microservices vs monolith" — unattended N-round orchestration
- Manual AI invite:
room create → chat room "question" --tool claude-code → invite --tool codex --room room → read response
- Human joins AI chat:
chat room -i → type messages → @codex opinion? → /who to see participants
- Cross-machine collaboration:
room create --relay default → share connection string → friend joins (LAN cross-machine without relay planned for Phase 2)
- Public internet debate:
room create --relay default → share connection string → anyone joins
Limitations
- AI spawn is synchronous: each invite blocks until the AI responds (up to
--timeout). Use quick/discuss for unattended multi-AI conversations.
- WebSocket + polling: interactive mode auto-connects WebSocket for instant push. Falls back to HTTP polling (1.5s) if WS unavailable.
- Optional E2E encryption: use
--password for encrypted rooms. Requires pip install cryptography.
- Per-peer auth on relay: room-wide token + per-peer HMAC-SHA256 signature. Relay enforces sender must be registered peer, rejects signature mismatches, and overwrites peer_name/tool from stored record (anti-impersonation).
- Daemon config persisted:
~/.ai-peers/daemon.json stores host:port. --lan auto-restarts daemon on 0.0.0.0 if currently on 127.0.0.1.
- Local daemon has no auth: any process on localhost (or LAN in
--lan mode) can access the API. Use E2E encryption (--password) for sensitive conversations. Daemon auth token planned for Phase 2.
- Room passwords stored locally: passwords are in plaintext in
~/.ai-peers/peers.db (needed for Fernet key derivation). Protect with OS file permissions. Keychain integration planned for Phase 2.
- LAN cross-machine join:
--lan mode binds daemon on 0.0.0.0 but the CLI always connects to localhost. Cross-machine LAN join requires --relay (public mode). Direct LAN daemon targeting (--host/--port) planned for Phase 2.
- Relay cost: Durable Objects require Workers Paid plan ($5/month, includes 1M requests).
Testing
PYTHONPATH=<ai-peer-skill-dir>/scripts uv run --with pytest --with cryptography pytest <ai-peer-skill-dir>/tests/ -v
PYTHONPATH=<ai-peer-skill-dir>/scripts uv run --with pytest pytest <ai-peer-skill-dir>/tests/ -v -m "not integration"