tencent cloud

Daemon Mode

Download
Focus Mode
Font Size
Last updated: 2026-09-30 18:41:46
AI-Translated
Daemon mode runs CodeBuddy Code as a background resident service without depending on a terminal window. After startup, it provides complete HTTP APIs and a Web UI, ready to accept requests at any time.
Core value: Transform the CLI from "use and leave" to "always on standby".

Concept

Concept
Description
Worker
A running CLI process registered in ~/.codebuddy/sessions/ through a PID file.
Daemon
A background HTTP service process (--serve mode), managed through daemon start
Background session (bg)
A non-interactive task started with --bg, automatically outputting logs to a file.

Daemon Management

Starting the Daemon

# Start the daemon (run in the background with automatic port allocation)
codebuddy daemon start

# Specify a port
codebuddy daemon start --port 8080

# Specify a bind address (allow remote access)
codebuddy daemon start --host 0.0.0.0

# Specify a permission mode (defaults to delegate mode)
codebuddy daemon start --permission-mode default

# Pass other standard parameters (model, mcp-config, and others are inherited automatically)
codebuddy daemon start --model claude-sonnet-4-20250514 --mcp-config ./.mcp.json
After the Daemon starts, it runs as a detached process, and the parent process exits immediately. Local addresses are accessible without authentication by default, while password authentication is automatically enabled for non-local addresses.
Default delegate mode: Daemon runs in delegate mode by default, where the main agent only handles coordination and scheduling without directly modifying code. All implementation work is completed by subagents. You can switch to other modes through --permission-mode.
Parameter inheritance: Standard CLI parameters specified during daemon start (--model, --permission-mode, --mcp-config, --tools, --agent, --settings, and others) are automatically inherited by daemon child processes.
Idempotent startup: Running daemon start multiple times does not create multiple daemons. If a daemon is already running, the information of the existing daemon is returned directly.

Viewing the Status

codebuddy daemon status
# {"status":"running","pid":12345,"endpoint":"http://127.0.0.1:51862","startedAt":1775498920401}

Stopping / Restarting

codebuddy daemon stop
codebuddy daemon restart

Background Sessions

Starting a Background Task

# Run tasks in the background
codebuddy --bg "Implement the login page"

# Specify a name (for easier lookup)
codebuddy --bg --name feature-login "Implement the login page"
Background sessions run in --print -y mode (no TUI + permission confirmation skipped), and stdout/stderr is redirected to ~/.codebuddy/logs/{name}.log.

Process Management Commands

# List all active workers
codebuddy ps

# View background session logs
codebuddy logs feature-login

# Continuously follow logs (similar to tail -f)
codebuddy logs feature-login -f

# Attach to a background session
codebuddy attach feature-login

# Terminate a background session
codebuddy kill feature-login

HTTP API

All Worker and Daemon management capabilities are exposed through REST APIs, and the Workers page in the Web UI is built on top of these APIs.
For details, see the Workers & Daemon section in the HTTP API documentation.

Example

# List all workers
curl http://127.0.0.1:8080/api/v1/workers

# Start the Daemon
curl -X POST http://127.0.0.1:8080/api/v1/daemon/start \\
-H "Content-Type: application/json" \\
-d '{"port": 9090}'

# View Worker logs (telemetry logs)
curl "http://127.0.0.1:8080/api/v1/workers/12345/logs?type=telemetry&tail=100"

# Terminate a Worker
curl -X DELETE http://127.0.0.1:8080/api/v1/workers/12345

Web UI

After the --serve mode is started, the Web UI provides three management pages:
Workers — Worker process management and Daemon control
Logs — A standalone log viewer that supports Worker selection, log type switching, and keyword search.
Metrics — System resource monitoring and per-Worker process-level metrics.

Logging System

The Log API supports four types, which are automatically selected by priority:
Type
Path
Content
Trigger Condition
telemetry
~/.codebuddy/logs/{date}/{workspace}.log
Info/Warn/Error of all modules
Always (default priority)
process
~/.codebuddy/logs/{name}.log
Process stdout/stderr
Only bg/daemon
debug
~/.codebuddy/debug/{sessionId}.txt
Detailed debug information
Requires --debug
transcript
~/.codebuddy/projects/{id}/{sessionId}.jsonl
Conversation history
Always

PID File Registry

Each CLI process registers a PID file in ~/.codebuddy/sessions/ when it starts:
~/.codebuddy/sessions/
├── 12345.json # Local process (PID as the filename)
├── 67890.json # Another local process
└── manual-abc123.json # Manually added remote Worker
PID file content:
{
"pid": 12345,
"sessionId": "interactive-12345",
"cwd": "/home/user/project",
"startedAt": 1775498920401,
"kind": "interactive",
"url": "http://127.0.0.1:8080",
"mode": "local",
"version": "2.78.1",
"hostname": "my-machine"
}
Process liveness is checked by kill -0, and manually added remote Workers are detected through heartbeat timeout (2 minutes).

Environment Variables

Variable
Description
CODEBUDDY_SESSION_KIND
Worker type (interactive / bg / daemon)
CODEBUDDY_SESSION_NAME
Display name of the background session
CODEBUDDY_SESSION_LOG
Background session log path
CODEBUDDY_GATEWAY_AUTH
Authentication mode (none / password)

System Service Registration

Register the daemon as an operating system-level service to enable automatic startup on login and automatic recovery from crashes.

Installing / Uninstalling

# Register as a system service and start the daemon immediately
codebuddy daemon install

# Specify the port and permission mode
codebuddy daemon install --port 8080 --permission-mode bypassPermissions

# Remove the system service registration
codebuddy daemon uninstall
After installation, codebuddy daemon status displays the system service status:
{
"status": "running",
"pid": 42567,
"endpoint": "http://127.0.0.1:9527",
"systemService": {
"installed": true,
"backend": "launchd",
"configPath": "/Users/xxx/Library/LaunchAgents/com.codebuddy.daemon.plist"
}
}

Supported Platforms

Platform
Backend
Service Type
Configuration path
macOS
launchd
Launch Agent (user level)
~/Library/LaunchAgents/com.codebuddy.daemon.plist
Linux
systemd
User Unit
~/.config/systemd/user/codebuddy-daemon.service
Windows
Task Scheduler
Scheduled task (user level)
schtasks /tn "CodeBuddy Daemon"
All platforms run as user-level services and do not require administrator privileges.

Automatic Updates

System services + automatic updates form a complete zero-intervention Ops loop:
1. System login → The system service automatically starts the daemon.
2. Every hour → The system checks for new versions in the background and installs them silently.
3. When idle → fork a new daemon process → the old process exits normally (without triggering a crash restart).
4. On crash → The system service recovers automatically (KeepAlive / Restart=on-failure).
Design details: The system service is configured to restart only on abnormal exits. The graceful restart of automatic updates exits with code 0, so it does not trigger the system service restart mechanism. The new process has already been forked by the update process.

Comparison of Management Commands

# Native management on macOS
launchctl list | grep codebuddy
launchctl stop com.codebuddy.daemon
launchctl start com.codebuddy.daemon

# Native management on Linux
systemctl --user status codebuddy-daemon
systemctl --user stop codebuddy-daemon
systemctl --user start codebuddy-daemon

# Native management on Windows
schtasks /query /tn "CodeBuddy Daemon"

Scenarios

Development Server Persistence

Start the daemon once during daily development. After that, you can interact with AI anytime through a browser or API without opening a terminal each time.
codebuddy daemon start --port 8080
# Open http://127.0.0.1:8080 in a browser to start using it
# The service keeps running after the terminal is closed

CI/CD Automation Backend

Start the daemon as an Agent service in the CI pipeline. Other steps can call it through HTTP APIs to perform tasks such as code review and test generation.
# Starting in CI
codebuddy daemon start --port 9090

# Calling from other CI steps (the body must be in Gateway Protocol format and include id/type)
curl -X POST http://127.0.0.1:9090/api/v1/runs \\
-H "Content-Type: application/json" \\
-H "X-CodeBuddy-Request: 1" \\
-d '{"id": "run-1", "type": "message", "payload": {"text": "Review the code changes in this PR"}}'
# Response: {"data": {"runId": "uuid-xxx", "status": "accepted"}}
Note:
Requests to /api/v1/runs must include the X-CodeBuddy-Request header. The body must use the Gateway Protocol format, where id and type are required and the prompt text is placed in payload.text. For field details, see the HTTP API documentation.

Multi-User Shared Agent

Start the daemon on a development machine and bind it to a LAN address. Team members can then share the same Agent environment through the Web UI.
codebuddy daemon start --host 0.0.0.0 --port 8080
# Colleagues can access http://192.168.1.100:8080

Background Batch Tasks

Use --bg to start multiple background sessions concurrently for handling different tasks, and manage them with ps/logs/kill.
codebuddy --bg --name "refactor-auth" "Refactor the authentication module"
codebuddy --bg --name "add-tests" "Add unit tests for the utils directory"
codebuddy --bg --name "fix-types" "Fix all TypeScript type errors"

# Check progress
codebuddy ps
codebuddy logs refactor-auth

WeChat/WeCom Bot Backend

The daemon runs persistently as the backend service for the chatbot and receives messages over persistent connections.
codebuddy daemon start
# Connect WeChat/WeCom channels with the remote control feature

IDE Extension Backend

The IDE plugin connects to the daemon through the ACP protocol to provide AI coding assistance, avoiding the need to restart the CLI process every time the IDE is opened.

Differences from --serve

Feature
--serve
daemon start
Lifecycle
Follows the terminal and exits when the terminal is closed.
Runs persistently in the background, independent of the terminal.
Startup Method
Run in the foreground
fork a detached child process.
Management Method
Stop with Ctrl+C
daemon stop/status/restart
Multiple Starts
Create a new process each time
Idempotent, maintaining only one daemon.
Typical Use
Temporary development and debugging
Long-running service.


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback