Overview
NapCat supports two distinct working environments, each designed for different deployment scenarios. The environment is determined by how NapCat is launched and integrated with NTQQ.packages/napcat-core/index.ts:56
Shell Mode
Standalone process that launches and controls QQ
Framework Mode
Injected into existing QQ process as a plugin
Shell Mode
What is Shell Mode?
Shell mode runs NapCat as an independent process that:- Launches QQ as a child process
- Manages the QQ lifecycle
- Handles multi-process coordination
- Provides process isolation and crash recovery
Architecture
Process Management
Shell mode uses a master-worker pattern for stability:packages/napcat-shell/napcat.ts:334
Crash Recovery
Shell mode includes automatic crash recovery:packages/napcat-shell/napcat.ts:284
Restart Process
packages/napcat-shell/napcat.ts:154
Features
Process Isolation
Process Isolation
- Worker process crashes don’t affect master
- Master can restart worker automatically
- Clean separation of concerns
Multi-Process Support
Multi-Process Support
- Electron UtilityProcess on desktop
- Node.js child_process.fork on CLI
- Configurable via environment variables
Quick Login
Quick Login
- Pass QQ number via
-qor--qqargument - Automatically handles quick login flow
- Preserved on first start only (not restarts)
Named Pipe IPC
Named Pipe IPC
- Communicate with external processes
- Can be disabled via
NAPCAT_DISABLE_PIPE=1 - Platform-specific pipe naming
Use Cases
Recommended for production deployments
- Running NapCat as a system service
- Docker containers
- CLI environments
- Scenarios requiring automatic restart
- When you need full process control
Launch Example
Framework Mode
What is Framework Mode?
Framework mode integrates NapCat directly into the QQ process:- QQ is already running when NapCat starts
- NapCat is injected as a framework/plugin
- Shares the same process space as QQ
- Typically used with LiteLoaderQQNT or similar loaders
Architecture
Initialization Flow
packages/napcat-framework/napcat.ts:24
Login Handling
Framework mode provides rich login options through WebUI:packages/napcat-framework/napcat.ts:200
Features
Early WebUI
Early WebUI
- WebUI starts before login
- Control login process via web interface
- QR code display in browser
- Multiple login methods (QR/password/quick)
Login History
Login History
- Access saved login accounts
- Quick login with one click
- Login list populated from QQ’s database
Password Login
Password Login
- Full password login support
- Captcha handling
- Device verification
- Multi-step authentication
Use Cases
Recommended for desktop users
- LiteLoaderQQNT plugin
- Desktop QQ with custom loaders
- Development and debugging
- When QQ UI is needed
- Scenarios where process injection is preferred
Launch Example
Framework mode is typically launched by a plugin loader:Comparison Table
Environment Detection
NapCat components can detect their working environment:Best Practices
Both modes use the same NapCat Core APIs. Switching between modes doesn’t require code changes.
Related
Architecture
Understand the core architecture
Adapters
Configure network adapters
