The Claude Code Mattermost Plugin provides a native integration between Mattermost and Claude Code CLI, replacing the web UI with chat-based interactions.
┌─────────────────────────────────────────────────────────────┐
│ Mattermost Server │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Claude Code Plugin │ │
│ │ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ Go Backend │◄─────────►│React Frontend│ │ │
│ │ │ (Commands, │ │ (UI Components) │ │
│ │ │ Sessions) │ │ │ │ │
│ │ └──────┬───────┘ └────────────────┘ │ │
│ └─────────┼──────────────────────────────────────────────┘ │
└────────────┼──────────────────────────────────────────────┘
│ REST + WebSocket
▼
┌─────────────────────────────────────────────────────────────┐
│ Bridge Server (Node.js) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Session │ │ WebSocket │ │ SQLite │ │
│ │ Manager │ │ Server │ │ Database │ │
│ └──────┬───────┘ └──────────────┘ └──────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ CLI Spawner & Manager │ │
│ └──────────────────────────┬───────────────────────────┘ │
└─────────────────────────────┼──────────────────────────────┘
│ spawn/stdin/stdout
▼
┌──────────────────┐
│ Claude Code CLI │
│ (AI Assistant) │
└──────────────────┘
Responsibilities:
- Register and handle slash commands
- Manage session lifecycle per channel
- Create interactive messages and dialogs
- Communicate with bridge server
- Persist session data in KV store
Key Files:
plugin.go- Plugin lifecycle, initializationcommands.go- Slash command routing and executionsession_manager.go- Session state managementbridge_client.go- HTTP client for bridge serverwebsocket_client.go- WebSocket connection handlingthread_context.go- Thread history integrationfile_operations.go- File browsing and management
Data Flow:
- User types slash command in Mattermost
- Plugin receives command via
ExecuteCommand() - Plugin validates and routes to handler
- Handler interacts with bridge server
- Response posted back to channel via bot
Responsibilities:
- Render custom UI components
- Handle interactive button clicks
- Display dialogs and modals
- Real-time message updates
Key Files:
index.tsx- Plugin initializationcomponents/- React components for UI
Data Flow:
- Plugin registers React components
- Components render in Mattermost UI
- User interactions trigger API calls
- Updates reflected in real-time
Responsibilities:
- Spawn and manage Claude Code CLI processes
- Provide REST API for session operations
- WebSocket server for real-time communication
- Session persistence in SQLite
- File system operations
- Context injection (threads, files)
Key Files:
index.ts- Express server setupsession-manager.ts- Session lifecyclecli-spawner.ts- CLI process managementwebsocket-server.ts- Real-time messagingdatabase.ts- SQLite operationsapi/sessions.ts- Session endpointsapi/files.ts- File operation endpointsapi/context.ts- Context injection
API Endpoints:
| Method | Path | Description |
|---|---|---|
| POST | /api/sessions |
Create new session |
| GET | /api/sessions/:id |
Get session status |
| DELETE | /api/sessions/:id |
Stop session |
| POST | /api/sessions/:id/prompt |
Send message to Claude |
| POST | /api/sessions/:id/context |
Inject context (thread/file) |
| GET | /api/sessions/:id/files |
List project files |
| GET | /api/sessions/:id/files/:path |
Get file content |
| POST | /api/sessions/:id/files |
Create file |
| PUT | /api/sessions/:id/files/:path |
Update file |
| DELETE | /api/sessions/:id/files/:path |
Delete file |
| POST | /api/sessions/:id/approve |
Approve change |
| POST | /api/sessions/:id/reject |
Reject change |
WebSocket Events:
| Direction | Event | Payload | Description |
|---|---|---|---|
| Server→Client | message |
{content, type} |
Claude's response |
| Server→Client | status |
{status} |
Session status change |
| Server→Client | file_change |
{path, action} |
File modified |
| Server→Client | error |
{error} |
Error occurred |
| Client→Server | prompt |
{content} |
User message |
Responsibilities:
- Process natural language instructions
- Read and modify files
- Execute shell commands
- Maintain conversation context
Communication:
- Bridge server spawns CLI as child process
- Stdin for sending prompts
- Stdout for receiving responses
- Stderr for errors and logs
type Session struct {
SessionID string `json:"session_id"`
ChannelID string `json:"channel_id"`
UserID string `json:"user_id"`
ProjectPath string `json:"project_path"`
Status string `json:"status"` // "active", "idle", "stopped"
CreatedAt time.Time `json:"created_at"`
LastActive time.Time `json:"last_active"`
}interface Message {
id: string;
sessionId: string;
type: 'user' | 'assistant' | 'system';
content: string;
timestamp: number;
}type FileNode struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "file" | "directory"
Size *int64 `json:"size,omitempty"`
Children []FileNode `json:"children,omitempty"`
}Used for commands that need immediate response:
Plugin Bridge Server
│ │
├──POST /api/sessions─────────►
│ │
◄─────{session_id}────────────┤
│ │
Used for long-running operations and real-time updates:
Plugin Bridge Server
│ │
├──WebSocket Connect──────────►
│ │
├──{type: "prompt"}───────────►
│ │
◄──{type: "message"}──────────┤
◄──{type: "message"}──────────┤
◄──{type: "message"}──────────┤
│ │
User approvals flow through REST API:
User Plugin Bridge Server
│ │ │
├─Click Approve────────► │
│ ├─POST /api/.../approve►
│ │ │
│ ◄─────{success}─────────┤
│ │ │
◄─Confirmation Message─┤ │
│ │ │
- Plugin to Bridge: API token configured in plugin settings
- Plugin to Mattermost: Uses Mattermost plugin API (authenticated)
- User to Plugin: Mattermost handles user authentication
- Sessions are channel-scoped (one session per channel)
- Only users in the channel can interact with that session
- File operations restricted to project directory
- File paths validated to prevent directory traversal
- Project paths must be absolute and existing
- Command arguments sanitized before execution
- Sessions stored in KV store (encrypted at rest by Mattermost)
- Bridge server database can be encrypted
- Thread context respects Mattermost permissions
- No user data sent to external services without consent
- Single Bridge Server: Handles all sessions
- In-Memory State: Session data in memory + SQLite backup
- One CLI per Session: Each session spawns separate Claude Code process
- Bridge server is single point of failure
- CLI processes consume significant memory (each runs independently)
- SQLite limits concurrent writes
- Horizontal Scaling: Multiple bridge servers with load balancer
- Session Affinity: Sticky sessions or distributed state
- Process Pooling: Reuse CLI processes across sessions
- Database: Move to PostgreSQL for better concurrency
- Message Queue: Redis for WebSocket message distribution
- Command validation errors → ephemeral message
- Bridge server unavailable → retry with exponential backoff
- WebSocket disconnect → automatic reconnection
- Session not found → clear message to user
- CLI spawn failure → return error to plugin
- CLI crash → cleanup session, notify plugin
- File operation errors → return descriptive error
- Database errors → log and return 500
- Session Recovery: Persist session state, restore on restart
- CLI Crash: Detect via process exit, optionally restart
- Connection Loss: Automatic WebSocket reconnection
- Partial Updates: Transaction-like file operations
- KV store operations are async
- WebSocket connection pooling
- Rate limiting on commands (prevent spam)
- Async I/O for file operations
- Stream large responses (don't buffer in memory)
- Connection limits (max concurrent sessions)
- SQLite WAL mode for better concurrency
- Bot messages throttled (respect rate limits)
- Ephemeral messages don't persist (faster)
- Attachments for large content (not inline text)
[Developer Machine]
├── Mattermost (Docker)
├── Bridge Server (npm run dev)
└── Claude Code CLI (local install)
[Server]
├── Mattermost Server
│ └── Claude Code Plugin
├── Bridge Server (systemd/PM2)
└── Claude Code CLI
[Load Balancer]
│
├──► [Mattermost Server 1]
│ └── Plugin
│
└──► [Mattermost Server 2]
└── Plugin
│
▼
[Bridge Server Cluster]
├── Instance 1
├── Instance 2
└── Instance 3
│
▼
[Shared Database]
- Session count (active/total)
- Message throughput (msg/sec)
- CLI spawn time (ms)
- Response latency (ms)
- Error rate
- Plugin: Mattermost plugin logs
- Bridge: Winston/Pino structured logs
- CLI: Captured and persisted
- Bridge:
GET /healthendpoint - Plugin: Mattermost plugin health API
- CLI: Process existence check
- Multi-User Sessions: Multiple users collaborating in same session
- Session Sharing: Share session across channels
- History Browsing: Review past conversations
- Custom Actions: User-defined interactive buttons
- Advanced File Editor: Full IDE-like experience in dialogs
- Voice Input: Speech-to-text for prompts
- Mobile Optimization: Better mobile UI components
- Analytics Dashboard: Usage statistics and insights