Setup

Connect Feishu (or Lark) to NightMe

The 30-second QR-code registration that hands NightMe's daemon a Feishu app of its own.

by NightMe team 4 min read

The 30-second QR-code registration that hands NightMe's daemon a Feishu app of its own.

Feishu (and its international sibling, Lark) is the most common chat platform to wire up. The flow is identical for both — nightme login feishu registers a fresh Feishu app on your behalf and saves the credentials locally so the daemon can talk to it.

TL;DR

nightme login feishu

A QR code renders in the terminal. Scan it with the Feishu mobile app and confirm the consent page. Within a few seconds the CLI saves the credentials and posts a greeting DM to your account. The daemon isn't started by login — run nightme start afterwards (or later) to bring it up.

What happens under the hood

  1. The CLI calls registration.RegisterApp from larksuite/oapi-sdk-go, passing the NightMe brand preset ("NightMe" / "Sleep tight, NightMe code all night.") and the full NightMe scope set (one-time authorization covers im:message.*, im:chat.*, cardkit:card.*, etc. — no follow-up re-authorize when a new feature lands).
  2. The SDK fetches a device code from Feishu and prints the verification URL — https://accounts.feishu.cn/oauth2/v1/app/registration?from=sdk — alongside the QR code (ASCII half-block on Unix/macOS, ANSI or a temp PNG on Windows, picked at compile time).
  3. Your phone scans → opens the consent page → confirms. On Feishu's side, this is what creates a brand-new app under your tenant and grants it the requested scopes.
  4. The SDK polls Feishu in the background. When the scan is confirmed, Feishu returns a fresh AppID / AppSecret pair for the just-created app.
  5. The CLI writes feishu.app_id and feishu.app_secret into ~/.nightme/config.yaml (atomic write, file mode 0600, directory mode 0700). Any prior Feishu credentials in that file are overwritten — re-running the command is the rebind.
  6. The CLI sends a bilingual greeting DM (a msg_type=post envelope with both zh_cn and en_us blocks; Feishu's client picks the locale matching the receiver's UI language) to the user who just scanned. A failed greeting does not roll back the credentials.
  7. The CLI prints Next: run \nightme start` to launch the gateway daemon.` and exits.

The 10-minute --timeout flag controls how long step 4 will poll. The default is generous; raise it only if you're debugging a flaky network.

Confirming the connection

The credentials are now on disk:

grep -A2 '^feishu:' ~/.nightme/config.yaml

You should see non-empty app_id and app_secret fields. To see the live Feishu WebSocket state once the daemon is up, run nightme doctor (or nightme doctor --json for a scriptable snapshot).

Re-binding and clearing

There is no separate logout subcommand — the login command itself is the rebind. To rotate credentials (e.g. you've changed tenants, or revoked the app from the Feishu admin console), just run nightme login feishu again; it overwrites the existing app_id / app_secret in config.yaml. To remove the channel entirely, delete the feishu: block from ~/.nightme/config.yaml (or the whole file if it's the only configured channel) and restart the daemon.

Per-chat working directory

Each chat has its own working directory — by default the bot's CWD, but you can move it at any time:

/cwd ~/code/feat-backend

Run the same command in any chat to inspect:

/cwd

One CWD = one project. This is the cornerstone of NightMe's parallel-execution model: every chat is an isolated shell against the same daemon, so /cwd in chat A never bleeds into chat B.

Troubleshooting

  • QR code too small to scan — the renderer targets ~80 columns. Make the terminal wider, or pipe the output to a file (nightme login feishu > qr.txt) and scan the file with the Feishu mobile app.
  • feishu: register: ... or feishu: login failed: <code>: <desc> — the SDK surfaces Feishu's own error codes. The common ones are: tenant hasn't enabled self-built apps, the app quota is full, or the network couldn't reach accounts.feishu.cn. Re-run after fixing; the flow is idempotent.
  • Scan succeeded but no greeting DM arrives — the greeting is best-effort; a failure never rolls back the credentials. Confirm the feishu.app_id / feishu.app_secret are non-empty, then send the bot a message in any chat — if the daemon replies, the channel is live.

What's next

With Feishu connected, jump to Run your first agent session — three commands and you'll have a Claude Code session you can steer from your phone.