Write once in TypeScript. Run your bot across 20+ chat platforms.
File-based commands, cross-platform JSX cards, leak-free hot reload, and opt-in AI agents — managed from the browser.
QQ · WeChat · WeCom · DingTalk · Lark · Discord · Telegram · Slack · KOOK · LINE · …
English · 简体中文
Documentation · Plugin Authoring · Operator Guide · Live Demo · Remote Console · Contributing
Running a bot without writing code? Jump to the Operator & Group Admin Guide or try the Live Demo. Building plugins or adapters in TypeScript? Start right below or browse Plugin Authoring.
No platform account and no model key required (Node.js ≥22.19.0, pnpm 9+):
npm create zhin-app my-bot -- -y --adapter sandbox
cd my-bot
pnpm dev # zhin start --foreground: management gateway + your bot, hot reload- Finish setup in the Console: open the Console link printed in the terminal (
https://console.zhin.dev/?apiBaseUrl=…#token=…; the bootstrap token after#never leaves your browser). Keep the default SQLite database and create the owner account. - Chat with the Sandbox: in the Console, open Conversations → Sandbox and send
/hello. (The standalone pagehttp://127.0.0.1:8068/sandboxworks without signing in only before step 1; once the owner exists it needs a Console API token, issued under your user name → Personal settings (/account) and pasted into the box at the top right.) - Run it in the background:
npx zhin start(thenzhin status,zhin logs -f,zhin stop).
Full walkthrough: Quick start · Something wrong? Run npx zhin doctor.
Important
Upgrading an existing bot from 1.1.13 or earlier? The Runtime now only accepts configVersion: 2. Stop the Bot first, upgrade zhin.js / @zhin.js/cli to the latest, then run zhin migrate instances (preview) and zhin migrate instances --apply (backs up first). Full steps and restore: Upgrading to configVersion 2.
Upgrading from single-process zhin runtime start? zhin start now runs a long-lived management gateway that supervises the bot; Console accounts replace http.tokens. Install @zhin.js/gateway with the same release of zhin.js / @zhin.js/cli and follow Upgrading to the management gateway.
Zhin.js is a TypeScript framework for bots that live in chat apps — community bots, personal assistants, notification and support bots, and governed AI chat assistants.
- One codebase, 20+ platforms. Adapters translate each platform into one unified message model. One bot can host multiple accounts across multiple platforms simultaneously.
- A feature is a file. Drop a file in
commands/,middlewares/,components/,schedules/, ortools/and it registers automatically — zero wiring boilerplate. - Generation-isolated hot reload. Save a file and Zhin atomically swaps in a new Generation. In-flight messages finish on the previous version; if new code throws on startup, the previous version keeps serving without downtime.
- Small by default (<10MB), AI when you want it. The IM core needs no LLM dependencies. Add AI agents, tools, 3-layer Markdown memory, and MCP anytime with
npx zhin setup --ai. - Browser Console & Server-Driven Blueprints included. Manage accounts, edit schema-driven forms, replay AI decisions, and trigger emergency stops from console.zhin.dev. Plugins author pure TypeScript
definePageBlueprintpages (pages/<name>/index.ts— zero.tsx, zeroesbuildbundling) that render in Web Console and project into IM cards (projectBlueprintToImCard) or CLI TUI panels (projectBlueprintToCliPanel).
Zhin is not an in-editor coding agent (like Cursor or Claude Code). Its AI stack is purpose-built for chat platforms, group permissions, and multi-user conversations.
Write interactive cards once in JSX (commands/poll/index.tsx). On platforms that support buttons, users click directly; on plain-text platforms, Zhin automatically degrades <button> into numbered text choices and routes the reply back to your onClick callback:
// commands/poll/index.tsx → /poll "Release v1.2 today?"
import { defineCommand } from 'zhin.js/command'
export default defineCommand({
description: 'Start a quick one-click poll',
params: {
topic: { type: 'text', default: 'Ship it today?' },
},
execute: ({ params }) => (
<card title={`📊 ${params.topic}`}>
<text>Click a button (or reply with its number on plain-text platforms):</text>
<button label="👍 Yes" onClick={(msg) => `Recorded 👍 from ${msg.$sender.name}`} />
<button label="🤔 Wait" onClick={(msg) => `Recorded 🤔 from ${msg.$sender.name}`} />
</card>
),
})Drop a file in tools/<name>/index.ts using defineAgentTool and Schema.object(...) from zhin.js. Framework security policies enforce permissions, visibility, and human approval before the model can invoke it:
// tools/weather/index.ts
import { Schema } from 'zhin.js'
import { defineAgentTool } from '@zhin.js/tool'
export default defineAgentTool<{ city: string }>({
description: 'Get live weather for a city',
parameters: Schema.object({
city: Schema.string().required().description('City name, e.g. Shanghai'),
}),
requiresApproval: 'never',
async execute({ city }) {
const res = await fetch(`https://wttr.in/${encodeURIComponent(city)}?format=3`)
return res.text()
},
})Your project's package.json#zhin.entry points to plugin.ts (or bot.ts in single-file bots), while mounted adapters, child plugins, and per-instance settings all live cleanly in zhin.config.yml:
# zhin.config.yml
configVersion: 2
http:
host: 127.0.0.1
port: 8068
token: ${HTTP_TOKEN}
plugins:
sandbox: '@zhin.js/adapter-sandbox'
reminder: '@zhin.js/plugin-reminder'
sandbox:
endpoints:
- id: local-sandbox
commandPrefix: / chat platform your project (a plugin) chat platform
QQ / Discord … ──▶ Adapter ──▶ Middleware ──▶ Command ──────────────▶ Adapter ──▶ reply
│ no command matched
└──▶ AI Agent (optional) ──▶ Tools
| Part | What it is | Where it lives |
|---|---|---|
| Plugin | Your project is the Root plugin; split into child plugins as it grows | Entry in package.json#zhin.entry (plugin.ts); child instances mounted in zhin.config.yml (plugins:) |
| Command | Runs when a user sends /hello or /remind 10 break |
commands/<name>/index.ts |
| Middleware | Sees every message — keyword replies, rate limits, filters | middlewares/<name>/index.ts |
| Adapter | Connects one platform; one adapter can host many account endpoints |
@zhin.js/adapter-*, configured in zhin.config.yml |
| AI Agent (optional) | Answers messages no command matched and calls your tools | tools/<name>/index.ts, enabled via npx zhin setup --ai |
| Console | Browser admin UI: toggle features per global → adapter → account → conversation, manage chat roles, send messages; plus accounts and permissions, the instance and its logs, terminal, audit log | console.zhin.dev, backed by the management gateway; local /sandbox for test chats |
my-bot/
├── package.json # "zhin" field: entry ("./plugin.ts") and capability features
├── zhin.config.yml # configVersion: 2 — mounted plugins, platform endpoints, HTTP port
├── .env # secrets: HTTP_TOKEN (bootstrap token), platform tokens, API keys
├── plugin.ts # Root plugin entry: definePlugin()
├── commands/ # /commands — folder path = command name
├── middlewares/ # runs on every message
├── components/ # reusable JSX message cards
├── schedules/ # cron scheduled jobs
├── tools/ # functions the AI may call (optional)
└── pages/ # custom Console pages
Next: Core concepts at a glance · Write your first reusable plugin · All convention folders · Commands in depth
npx zhin setup --adapters # pick platforms, enter credentials
pnpm install && pnpm dev| Platform | Package | Platform | Package |
|---|---|---|---|
| Sandbox (local testing) | @zhin.js/adapter-sandbox |
QQ (ICQQ) | @zhin.js/adapter-icqq |
| QQ official bot | @zhin.js/adapter-qq |
OneBot v11 / v12 | @zhin.js/adapter-onebot11 / onebot12 |
| Discord | @zhin.js/adapter-discord |
Telegram | @zhin.js/adapter-telegram |
| Slack | @zhin.js/adapter-slack |
KOOK | @zhin.js/adapter-kook |
| DingTalk | @zhin.js/adapter-dingtalk |
Lark / Feishu | @zhin.js/adapter-lark |
| WeCom | @zhin.js/adapter-wecom |
WeChat MP / WeChat iPad | @zhin.js/adapter-wechat-mp / @zhin.js/adapter-ipad-wechat |
| LINE | @zhin.js/adapter-line |
NapCat / Milky / Satori | napcat / milky / satori |
@zhin.js/adapter-email |
GitHub | @zhin.js/adapter-github |
Each adapter has a maturity tier (Stable / Advanced / Experimental) and its own setup guide: Adapters overview.
npx zhin setup --ai # pick a provider preset (OpenAI, DeepSeek, Qwen, Anthropic, Ollama…)
pnpm install && pnpm devThe wizard installs @zhin.js/agent along with @zhin.js/tool and @zhin.js/prompt-section, enables AI in zhin.config.yml, and generates an ai.plan.yml (with API keys stored in .env) that is automatically seeded into the runtime catalog on first startup:
# zhin.config.yml
ai:
enabled: true# ai.plan.yml (generated by `npx zhin setup --ai`, seeded on first start)
version: 1
services:
- id: openai
label: OpenAI
driver: openai
accounts:
- id: openai-main
label: OpenAI Default
serviceId: openai
authKind: api_key
apiKey: ${OPENAI_API_KEY}
profiles:
- id: default-chat
label: Default Chat
serviceId: openai
accountId: openai-main
model: gpt-4o-mini
defaults:
chatProfileId: default-chatMessages that match no command now go to the model — in DMs by default, in groups with an ai: prefix or @mention. Add files to tools/ to give it new capabilities.
Claude subscription and Antigravity are experimental channels: 实验 · 不受官方支持 · 可能违反供应商条款 · 风险由使用者自行承担 (experimental · not officially supported · may violate vendor terms · use at your own risk). See AI providers.
Next: AI overview · Agent tools, Skills and Prompt Sections · AI Agent learning path
| Tier | Install | Adds |
|---|---|---|
| IM (default) | zhin.js + @zhin.js/cli + an adapter; the CLI provides zhin start and the management gateway @zhin.js/gateway, needed in development and in production |
Built-in commands, components, middleware, schedules, hot reload — <10MB |
| AI | npx zhin setup --ai (installs @zhin.js/agent and features) |
Agent, sessions, memory, tools, compaction |
| Provider | @ai-sdk/openai etc. |
Calls to a specific LLM vendor |
| MCP | @modelcontextprotocol/sdk |
Use tools from external MCP servers |
| Rich media | @zhin.js/html-renderer |
Render HTML / Markdown replies to images (falls back to text) |
| Speech | @zhin.js/speech |
Speech-to-text in, text-to-speech out |
Detailed table and sizes: Install tiers. Since 1.1, ZhinAgent / AIService are imported from zhin.js/agent / zhin.js/ai, not from zhin.js.
Once a bot is deployed, day-to-day operations happen in the browser Console (console.zhin.dev). The Console talks to the project's management gateway: sign-in, permissions, starting and stopping the instance, dependency installs and the terminal are handled there, so the Console keeps working — sign-in, status, logs — while the bot instance is crashed or being upgraded.
First visit: use the setup link zhin start prints (or HTTP_TOKEN from .env) to create the first owner account. The bootstrap token stops working after that and everyone signs in with an account. On a server you can run zhin console init instead.
The Console is organized in four levels of objects — global → adapter → account → conversation — and every level has the same page layout:
| Section | What you see and do |
|---|---|
| Overview | Online state and statistics for this level |
| Features | Turn plugins on or off and override their settings at this level; a level switched off above is locked below, and every field shows which level it is inherited from (layered config) |
| Roles | Who is a chat owner / admin / trusted at this level (inherited downward, granted in the Console or in chat); platform owners and admins are a separate dimension and never become zhin roles (chat roles) |
| Records | Chat history, logs and change records for this level |
Account pages add Connection (sign-in, QR codes, connection checks); conversation pages add Chat (read history and send messages).
Administration:
- Accounts and permissions: Console users, built-in roles (
owner/admin/operator/viewer) and custom roles, bound globally or to one adapter or account; API tokens for automation. Sign-ins, denied requests and every write go to the audit log. See Access control. - Instance and operations: the instance page shows status, restarts the bot and streams its logs; dependency installs and updates roll back on failure. Also the database, config file, environment variables, schedules, files, and an owner-only terminal (off by default). See Operations.
- In-chat self-service: with
features.selfServiceon, people holding the zhinadminrole (or higher) in a group manage it with thefeatureandrolechat commands. - Three-dimension permissions: commands, Agent tools and skills, middlewares and buttons are available based on the sender's zhin role, the sender's platform standing and the bot's own standing in the group — a mute tool, for example, needs
platform:adminandbot:admin; each Agent turn only sees the tools that pass. See chat roles. - Upgrading:
masteris nowowner;master/trusted/ai.trigger.mastersin the config move into the database on first start and fail startup afterwards; permits such asrole(master)andscene_adminare removed. See the chat roles upgrade guide. - Guardrails & emergency stop: approve AI-drafted announcements or risky moderation actions before they run, replay AI decisions, or mute/stop the bot with one click.
👉 Full guide: Operator & Group Admin Guide · Console path · Solutions by outcome
| I want to… | Start here |
|---|---|
| Understand what Zhin is | What is Zhin.js · Core concepts |
| Run a bot for the first time | Quick start · Examples |
| Write commands, cards & plugins | First plugin · definePlugin · Plugin delivery |
| Connect platforms | Adapters · Configuration · Localization |
| Add AI & tools | AI overview · Agent tools · Agent deep dive |
| Deploy and operate | Production · Console · Troubleshooting |
| Understand the internals | Architecture · Plugin model · Message flow · Hot reload (Generations) |
Full site: zhin.js.org (Chinese by default; switch language in the top navigation).
npx zhin start # start the management gateway and the bot in the background (--foreground for dev, systemd, containers)
npx zhin status # gateway and instance status (exit code 3 when not running)
npx zhin logs -f # instance logs
npx zhin restart # restart only the bot instance; the gateway and the Console stay up
npx zhin stop # stop the gateway and the instance
npx zhin update # update dependencies: stop instance → install → start, rolled back on failure
npx zhin console init # create the first Console owner (same as the setup wizard in the browser)
npx zhin console user create alice --role viewer # manage Console accounts; passwd / disable / enable / list
npx zhin service install # install as a system service that starts on boot
npx zhin setup # add platforms, AI, database to an existing project
npx zhin doctor # diagnose Node, ports, tokens, manifest
npx @zhin.js/cli new my-plugin --standalone # scaffold a publishable plugin package
npx zhin search <keyword> # find community plugins
npx zhin install <name> # install and mount a pluginAll commands: CLI reference.
| Package | What it is |
|---|---|
zhin.js |
The main package — re-exports everything plugin authors need |
create-zhin-app |
Project scaffolder (npm create zhin-app) |
@zhin.js/cli |
The zhin command: run, set up, diagnose, migrate, publish |
@zhin.js/gateway |
Management gateway: HTTP, Console accounts and permissions, terminal, dependency transactions, instance supervision (comes with the CLI; list it in the project's dependencies so the lockfile pins one release) |
@zhin.js/agent |
Optional AI Agent runtime with security policies |
@zhin.js/adapter-* |
Platform adapters |
plugins/ |
Official plugins: games, reminders, RSS, calendar, moderation… |
How the layers fit together: architecture · repo structure.
git clone https://github.com/zhinjs/zhin.git
cd zhin
pnpm install && pnpm build
pnpm dev # runs examples/minimal-botOther entry points: pnpm --filter single-file-bot dev (one-file bot) and pnpm dev:test (maintainers' kitchen-sink test-bot, not a template). See the contributing guide for checks, conventions and the release flow.