Open Counsel
Open Counsel β Multi-agent framework for Claude Code + Discord
Ask AI about Open Counsel
Powered by Claude Β· Grounded in docs
I know everything about Open Counsel. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Open Counsel
A framework for running multiple autonomous AI agents as a collaborative team, powered by Claude Code and Discord.
Each agent runs as an independent Claude Code session with its own persona, Discord bot, and MCP (Model Context Protocol) channel server. Agents communicate with your team via Discord and with each other through B2B messaging.
Built on the official MCP channel protocol β no unofficial API calls, no browser automation, no TOS risk.
For AI agents: If you're Claude, Codex, or another AI working with this codebase, read
AGENTS.mdinstead. It's written for you.
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Discord Server β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β #alpha β β #beta β β #gamma β ... β
β ββββββ¬ββββββ ββββββ¬ββββββ ββββββ¬ββββββ β
βββββββββΌβββββββββββββββΌβββββββββββββββΌβββββββββββββββββ
β β β
βββββββΌββββββ βββββββΌββββββ βββββββΌββββββ
β Channel β β Channel β β Channel β
β Server β β Server β β Server β
β (MCP+Bot) β β (MCP+Bot) β β (MCP+Bot) β
βββββββ¬ββββββ βββββββ¬ββββββ βββββββ¬ββββββ
β β β
βββββββΌββββββ βββββββΌββββββ βββββββΌββββββ
β Claude β β Claude β β Claude β
β Code β β Code β β Code β
β Session β β Session β β Session β
βββββββββββββ βββββββββββββ βββββββββββββ
Key design: Each channel server is a single Node.js process that acts as both an MCP stdio server (for Claude Code) and a Discord.js bot. No HTTP gateways, no file-based message passing β direct in-process communication.
Features
- Multi-agent collaboration β Each agent has its own role, persona, and Discord channel
- MCP channel protocol β Real-time Discord β Claude Code message bridging
- Auto-restart wrapper β Agents automatically respawn on crash or context compaction
- Session memory system β 30-minute session notes, auto-archival to journals, shared memory
- Hook system β Pre/post-compact context injection, session start restoration, stop guards, diminishing returns detection
- MJ integration β Optional Midjourney watcher with auto-download, button clicking, /imagine via API
- Extensible tools β Add custom MCP tools per agent (see
agent-beta.mjsexample) - Permission auto-approve β Agents auto-approve tool permissions for unattended operation
Quick Start
Prerequisites
- Claude Code CLI installed and authenticated
- Node.js 20+
- A Discord server with bot applications created
Setup
-
Clone and install:
git clone https://github.com/minoming/open-counsel.git cd open-counsel npm install cd channels && npm install && cd .. -
Configure environment:
cp .env.example .env # Edit .env with your Discord bot tokens, channel IDs, etc. -
Create Discord bots:
- Go to Discord Developer Portal
- Create one application per agent
- Enable:
MESSAGE_CONTENTintent,SERVER MEMBERSintent - Generate bot tokens β paste into
.env - Invite bots to your server with appropriate permissions
-
Set up memory directory:
mkdir -p ~/Documents/MAGI_Memory/{session_notes,journals,self_persona,inbox/images} cd ~/Documents/MAGI_Memory && git init -
Create Discord channels:
- One channel per agent (their "home" channel β agents listen without @mention)
- Copy channel IDs β paste into
.env
-
Make run scripts executable:
chmod +x run-*.sh hooks/*.sh -
Launch:
# Launch all agents ./run-all.sh # Or launch individually ./run-alpha.sh
Project Structure
magi-system/
βββ channels/
β βββ base-channel.mjs # Core: MCP + Discord hybrid (shared by all agents)
β βββ agent-alpha.mjs # Simple agent (config-only)
β βββ agent-beta.mjs # Agent with extra tools
β βββ mj_watcher.mjs # Midjourney automation (optional)
β βββ package.json
βββ hooks/
β βββ session-start.sh # Context restoration on fresh start
β βββ pre-compact.sh # Discord notification + timestamp before compaction
β βββ post-compact.sh # Re-inject context after compaction
β βββ stop-check.sh # Block stop if session notes stale
β βββ diminishing-returns.sh # Warn on consecutive tool failures
β βββ log-compact.sh # Track compaction frequency
βββ personas/
β βββ examples/ # Example persona templates
β βββ CUSTOMIZATION.md # How to write effective personas
βββ .env.example # Environment variable template
βββ .mcp-alpha.json # Per-agent MCP config
βββ .mcp-beta.json
βββ CLAUDE.md # Instructions loaded into every Claude Code session
βββ run-alpha.sh # Agent launch script (auto-restart)
βββ run-beta.sh
βββ run-all.sh # Launch all agents
Adding a New Agent
-
Copy an agent channel file:
cp channels/agent-alpha.mjs channels/agent-myagent.mjsEdit:
agentName,discordTokenEnv,homeChannel,emoji,instructions -
Create MCP config:
cp .mcp-alpha.json .mcp-myagent.jsonUpdate the server name and args path.
-
Create run script:
cp run-alpha.sh run-myagent.shUpdate:
MAGI_AGENT, token var, persona path, MCP config path. -
Create persona:
cp personas/examples/agent-alpha.md personas/examples/agent-myagent.mdCustomize for your agent's role.
-
Add to
.env:DISCORD_BOT_TOKEN_MYAGENT=your-token DISCORD_MYAGENT_HOME_CHANNEL=your-channel-id
Hook Configuration
Hooks are shell scripts that run at specific lifecycle events. Configure them in your Claude Code settings (~/.claude/settings.json or project .claude/settings.local.json):
{
"hooks": {
"SessionStart": [{ "command": "bash hooks/session-start.sh" }],
"PreCompact": [
{ "command": "bash hooks/pre-compact.sh" },
{ "command": "bash hooks/log-compact.sh" }
],
"PostCompact": [{ "command": "bash hooks/post-compact.sh" }],
"Stop": [{ "command": "bash hooks/stop-check.sh" }],
"PostToolUse": [{ "command": "bash hooks/diminishing-returns.sh" }]
}
}
How It Works
Message Flow
- User sends a message in
#alphaDiscord channel - The channel server (MCP + Discord.js bot) receives it
- Channel server sends an MCP notification to Claude Code
- Claude Code processes the message with the agent's persona
- Claude Code calls the
replyMCP tool - Channel server sends the reply to Discord
Agent-to-Agent (B2B) Communication
Agents can talk to each other by mentioning another agent's bot in their reply:
@BetaBot Can you generate a concept image for this scene?
The mentioned agent's channel server picks it up and delivers it as a B2B message (prefixed with BOT:).
Session Memory
- Session notes β Written every 30 minutes, stored in
MAGI_MEMORY_DIR/session_notes/{agent}/ - Journals β Compressed archives of old session notes
- SHARED_MEMORY.md β Shared knowledge base across all agents
- Self-reflection β Agent-specific learning and growth notes
Context Compaction
When Claude Code's context window fills up:
pre-compact.shfires β sends Discord notification, records timestamp- Claude Code compresses the conversation
post-compact.shfires β re-injects SHARED_MEMORY, session notes, persona, and pending tasks
Configuration Reference
| Env Variable | Required | Description |
|---|---|---|
DISCORD_BOT_TOKEN_{AGENT} | Yes | Discord bot token per agent |
DISCORD_SERVER_ID | Yes | Your Discord server ID |
DISCORD_DIRECTOR_ID | No | Director's Discord user ID |
DISCORD_{AGENT}_HOME_CHANNEL | Yes | Agent's home channel (listens without @mention) |
DISCORD_PERMISSION_CHANNEL | No | Channel for permission responses |
MAGI_MEMORY_DIR | No | Memory directory (default: ~/Documents/MAGI_Memory) |
SESSION_NOTE_INTERVAL_MS | No | Note reminder interval (default: 1800000 = 30min) |
DISCORD_USER_TOKEN | No | For MJ button clicks and /imagine (optional) |
License
MIT
