Concepts
Agim (阿吉姆) is a single Node.js process that bridges messengers (WeChat, Telegram, Feishu, DingTalk, Discord, Email) to AI agents (Claude Code, OpenCode, Codex, Copilot, or any ACP endpoint). No Docker, no Redis — one binary, one config dir.
- Sessions are keyed by
platform:channel:threadand remember the last active agent, model, and message history. Idle for 30 minutes → auto-archive. - Intent classifier picks an agent from casual chat without a slash prefix (bilingual zh/en keyword heuristics), then sticky-locks the choice for a few turns.
- Approval bus intercepts agent tool calls that write files, run
shell, or hit the network. A card surfaces in your IM; reply
y/n/allto gate the call. - Persistent state lives in SQLite under
~/.agim/(legacy 0.x installs keep using~/.im-hub/) —jobs.db,memos.db,reminders.db,audit.dbplus session files. Survives restarts; 30-day TTL on most.
Quick start
Three install paths are documented in detail at the install page。 Shortest happy path:
npm install -g agim-cli # requires Node ≥ 18
agim # bilingual arrow-key wizard (recommended)
agim start # start in foreground The wizard walks: pick language → pick which messengers to enable → run each one's setup (WeChat QR scan / Feishu App Secret / DingTalk ClientID …) → pick which agents to enable → configure SMTP (reminder email) / Baidu Maps AK (geocoding).
Messengers
Each messenger has its own submenu in the wizard with status, Configure, Re-configure, and Remove. Credentials persist to ~/.agim/config.json (legacy installs: ~/.im-hub/config.json; chmod 600).
| Channel | Credentials / Connection | Rich media | Trigger condition |
|---|---|---|---|
| WeChat iLink | QR-code login, stored in ~/.agim/wechat-credentials.json | image / file / voice / video | 1:1 or group @bot |
| Telegram | @BotFather token + channel id | photo / voice / audio (whisper) | 1:1 or group @bot |
| Feishu / Lark | Self-built enterprise app: App ID + Secret, WebSocket | image / file / native location | 1:1 or group @bot |
| DingTalk 钉钉 Stream | Enterprise internal app: ClientID + ClientSecret, Stream WebSocket | image (download → multimodal Read) / voice (server-side ASR with whisper fallback) | 1:1 or group @bot |
| Discord | Bot token + allowed guild/channel ids | — | Direct message in configured channel |
| Email push-only | SMTP host / port / user / pass / from | — | Send only, used for /remind delivery |
DingTalk specifics: must create an "Enterprise Internal App" with Stream mode enabled (NOT a "group webhook bot" — those are push-only). A 1-person company works; register a personal enterprise. DingTalk never delivers native location messages to bots — use /memo here for the capture-link flow, or just type an address and let the agent geocode via Baidu Maps.
AI agents
Each agent maps to a local CLI binary; the wizard probes installation with <cmd> --version and labels "installed / not installed" with install instructions.
| Agent | Install | Notes |
|---|---|---|
| Claude Code | npm i -g @anthropic-ai/claude-code | Multimodal (reads image attachments); tool calls gated by approval bus; supports --resume |
| OpenCode | npm i -g opencode-ai@latest | HTTP driver (Agim built-in daemon); sessionID is opencode-native; auth via opencode auth login |
| Codex | npm i -g @openai/codex | `codex --thread` resumes; sees the full imhub MCP toolset (reminder + memo) |
| GitHub Copilot CLI | npm i -g @github/copilot | Multiple install paths (npm / gh extension / brew / VSCode), plugin auto-detects |
| Remote ACP | — | Any HTTP agent; add via wizard ("Remote ACP agents → Add"), manifest validated, Bearer / apikey auth supported |
Slash commands
All slash commands are platform-agnostic. Most map to agent MCP tools, so natural-language phrasings trigger the same capability.
| Command | What it does |
|---|---|
<text> | Sent as-is; routed to the sticky agent (or via the intent classifier on a fresh session). |
/cc / /oc / /cx / /co | Force-switch to Claude Code / OpenCode / Codex / Copilot. |
/new | New conversation (clear history + sticky lock). |
/remind 1m 喝水 | One-shot reminder; supports every:5m / daily:08:00 / weekly:1,3,5:09:00 . LLM auto-polishes the delivery text; routes to email or IM. |
/memo / /memo list / /memo show <id> | Manage saved 5W1H memos. To create one, use natural language ("帮我记下:…"), the agent calls save_memo. |
/memo here [what] | Returns a short link; open in browser to grant GPS, which auto-creates a coords-tagged memo. Especially useful on DingTalk where native location isn't delivered to bots. |
/agents / /status / /help | List registered agents / connectivity status / help menu. |
/model / /think on|off | View or switch model / toggle extended thinking. |
/plan on|off | Switch agent to read-only plan mode (claude-code adds --permission-mode plan). |
Configuration
Agim reads from three sources, in priority order:
-
~/.agim/config.json(legacy installs:~/.im-hub/config.json) — Primary config: enabled messengers, agents, defaultAgent, per-messenger credential objects, acpAgents list. chmod 600, written by the wizard. -
~/.agim/env(or~/.im-hub/env) — Simple KEY=value file for SMTP credentials and Baidu Maps AK. chmod 600. Loaded by systemd unit via EnvironmentFile=. -
process.env— Runtime process environment; used as a fallback by the wizard when neither file source has the key (systemd `Environment=` lines also surface here).
Frequently-used environment variables:
| Variable | Purpose |
|---|---|
IMHUB_SMTP_HOST / _PORT / _USER / _PASS / _FROM | Outbound email reminder delivery. |
IMHUB_BAIDU_MAP_AK | /memo address geocoding. |
IMHUB_WEB_BIND | Web console bind address; default 127.0.0.1, put a reverse proxy in front of any public deployment. |
IMHUB_WEB_REQUIRE_AUTH | 0 = no token gate (localhost only), 1 = force. Default depends on bind address. |
IMHUB_APPROVAL_DISABLED | =1 disables tool-call approval gating (default on). |
OPENAI_API_KEY / IMHUB_WHISPERCPP_BIN | Voice-transcription fallback (DingTalk ASR + WeChat STT take priority when available). |
Service lifecycle
Three run modes, auto-detected:
- systemd — Installer (when run as root) drops
/etc/systemd/system/agim.service(legacy:im-hub.service). Usesystemctloragim restartto manage. - Background daemon —
agim start --bguses nohup + setsid + pid file. Cross-platform (Linux / macOS / WSL2). - Foreground —
agim starttied to your terminal, Ctrl-C to stop.
agim status detects current mode + pid + uptime + web URL in one shot.
Architecture
Inbound messages are normalized then handed to the router; router picks an agent; agent output goes back out via the originating messenger.
┌─ Messenger ingress ──────────────────────────────┐
│ WeChat iLink (long-poll + image/voice/file) │
│ Telegram (grammy + photo/voice/audio) │
│ Feishu (Lark SDK WebSocket) │
│ DingTalk (Stream WebSocket + ASR baked in) │
│ Discord (discord.js Gateway) │
│ Web Chat (browser WebSocket) │
└───────────────────────┬──────────────────────────┘
│ MessageContext
▼
Router + Session
│
▼
Approval bus (HITL)
│
▼
Agent adapters
┌────────────┴────────────┐
Local CLI Remote ACP
(Claude / Codex / OC / Co) (HTTP /events) Where to get help
- GitHub README — github.com/benking007/imhub (bilingual; long-form install / config / command reference).
- CHANGELOG — full version history。
- Issue tracker — github.com/benking007/imhub/issues。