debug

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ClaudeClaw Container & Sandbox Debugging

ClaudeClaw 容器与沙箱调试指南

This guide covers debugging the agent execution system (container and sandbox runtimes).
本指南涵盖Agent执行系统(容器与沙箱运行时)的调试方法。

Architecture Overview

架构概述

Host (macOS)                          Container (Linux VM)
─────────────────────────────────────────────────────────────
src/orchestrator/container-runner.ts               agent/runner/
    │                                      │
    │ spawns container                      │ runs Claude Agent SDK
    │ with volume mounts                   │ with MCP servers
    │                                      │
    ├── data/env/env ──────────────> /workspace/env-dir/env
    ├── groups/{folder} ───────────> /workspace/group
    ├── data/ipc/{folder} ────────> /workspace/ipc
    ├── data/sessions/{folder}/.claude/ ──> /home/node/.claude/ (isolated per-group)
    └── (main only) project root ──> /workspace/project
Important: The container runs as user
node
with
HOME=/home/node
. Session files must be mounted to
/home/node/.claude/
(not
/root/.claude/
) for session resumption to work.
Host (macOS)                          Container (Linux VM)
─────────────────────────────────────────────────────────────
src/orchestrator/container-runner.ts               agent/runner/
    │                                      │
    │ spawns container                      │ runs Claude Agent SDK
    │ with volume mounts                   │ with MCP servers
    │                                      │
    ├── data/env/env ──────────────> /workspace/env-dir/env
    ├── groups/{folder} ───────────> /workspace/group
    ├── data/ipc/{folder} ────────> /workspace/ipc
    ├── data/sessions/{folder}/.claude/ ──> /home/node/.claude/ (isolated per-group)
    └── (main only) project root ──> /workspace/project
重要提示: 容器以
node
用户运行,
HOME=/home/node
。会话文件必须挂载到
/home/node/.claude/
(而非
/root/.claude/
)才能正常恢复会话。

Log Locations

日志位置

LogLocationContent
Main app logs
logs/claudeclaw.log
Host-side WhatsApp, routing, container spawning
Main app errors
logs/claudeclaw.error.log
Host-side errors
Container run logs
groups/{folder}/logs/container-*.log
Per-run: input, mounts, stderr, stdout
Claude sessions
~/.claude/projects/
Claude Code session history
日志类型路径内容
主应用日志
logs/claudeclaw.log
主机端WhatsApp、路由、容器启动相关日志
主应用错误日志
logs/claudeclaw.error.log
主机端错误信息
容器运行日志
groups/{folder}/logs/container-*.log
单次运行日志:输入、挂载、stderr、stdout
Claude会话日志
~/.claude/projects/
Claude Code会话历史

Enabling Debug Logging

启用调试日志

Set
LOG_LEVEL=debug
for verbose output:
bash
undefined
设置
LOG_LEVEL=debug
以获取详细输出:
bash
undefined

For development

开发环境

LOG_LEVEL=debug npm run dev
LOG_LEVEL=debug npm run dev

For launchd service (macOS), add to plist EnvironmentVariables:

macOS launchd服务,添加到plist的EnvironmentVariables:

<key>LOG_LEVEL</key> <string>debug</string>
<key>LOG_LEVEL</key> <string>debug</string>

For systemd service (Linux), add to unit [Service] section:

Linux systemd服务,添加到单元的[Service]部分:

Environment=LOG_LEVEL=debug

Environment=LOG_LEVEL=debug


Debug level shows:
- Full mount configurations
- Container command arguments
- Real-time container stderr

调试级别会显示:
- 完整挂载配置
- 容器命令参数
- 实时容器stderr输出

Common Issues

常见问题

1. "Claude Code process exited with code 1"

1.「Claude Code进程退出,代码为1」

Check the container log file in
groups/{folder}/logs/container-*.log
Common causes:
检查容器日志文件
groups/{folder}/logs/container-*.log
常见原因:

Missing Authentication

认证信息缺失

Invalid API key · Please run /login
Fix: Ensure
.env
file exists with either OAuth token or API key:
bash
cat .env  # Should show one of:
Invalid API key · Please run /login
修复方案: 确保
.env
文件存在OAuth令牌或API密钥:
bash
cat .env  # 应包含以下其中一项:

CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-... (subscription)

CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-... (订阅版)

ANTHROPIC_API_KEY=sk-ant-api03-... (pay-per-use)

ANTHROPIC_API_KEY=sk-ant-api03-... (按量付费版)

undefined
undefined

Root User Restriction

根用户限制

--dangerously-skip-permissions cannot be used with root/sudo privileges
Fix: Container must run as non-root user. Check Dockerfile has
USER node
.
--dangerously-skip-permissions cannot be used with root/sudo privileges
修复方案: 容器必须以非根用户运行。检查Dockerfile中是否包含
USER node
指令。

2. Environment Variables Not Passing

2. 环境变量未传递

Runtime note: Environment variables passed via
-e
may be lost when using
-i
(interactive/piped stdin).
Workaround: The system extracts only authentication variables (
CLAUDE_CODE_OAUTH_TOKEN
,
ANTHROPIC_API_KEY
) from
.env
and mounts them for sourcing inside the container. Other env vars are not exposed.
To verify env vars are reaching the container:
bash
echo '{}' | docker run -i \
  -v $(pwd)/data/env:/workspace/env-dir:ro \
  --entrypoint /bin/bash claudeclaw-agent:latest \
  -c 'export $(cat /workspace/env-dir/env | xargs); echo "OAuth: ${#CLAUDE_CODE_OAUTH_TOKEN} chars, API: ${#ANTHROPIC_API_KEY} chars"'
运行时说明: 使用
-e
传递的环境变量在使用
-i
(交互式/管道标准输入)时可能丢失。
解决方法: 系统仅从
.env
中提取认证变量(
CLAUDE_CODE_OAUTH_TOKEN
ANTHROPIC_API_KEY
)并挂载到容器内部供读取。其他环境变量不会暴露。
验证环境变量是否到达容器:
bash
echo '{}' | docker run -i \
  -v $(pwd)/data/env:/workspace/env-dir:ro \
  --entrypoint /bin/bash claudeclaw-agent:latest \
  -c 'export $(cat /workspace/env-dir/env | xargs); echo "OAuth: ${#CLAUDE_CODE_OAUTH_TOKEN} chars, API: ${#ANTHROPIC_API_KEY} chars"'

3. Mount Issues

3. 挂载问题

Container mount notes:
  • Docker supports both
    -v
    and
    --mount
    syntax
  • Use
    :ro
    suffix for readonly mounts:
    bash
    # Readonly
    -v /path:/container/path:ro
    
    # Read-write
    -v /path:/container/path
To check what's mounted inside a container:
bash
docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c 'ls -la /workspace/'
Expected structure:
/workspace/
├── env-dir/env           # Environment file (CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY)
├── group/                # Current group folder (cwd)
├── project/              # Project root (main channel only)
├── global/               # Global CLAUDE.md (non-main only)
├── ipc/                  # Inter-process communication
│   ├── messages/         # Outgoing WhatsApp messages
│   ├── tasks/            # Scheduled task commands
│   ├── current_tasks.json    # Read-only: scheduled tasks visible to this group
│   └── available_groups.json # Read-only: WhatsApp groups for activation (main only)
└── extra/                # Additional custom mounts
容器挂载说明:
  • Docker支持
    -v
    --mount
    两种语法
  • 使用
    :ro
    后缀设置只读挂载:
    bash
    # 只读
    -v /path:/container/path:ro
    
    # 读写
    -v /path:/container/path
检查容器内部挂载情况:
bash
docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c 'ls -la /workspace/'
预期结构:
/workspace/
├── env-dir/env           # 环境文件(CLAUDE_CODE_OAUTH_TOKEN或ANTHROPIC_API_KEY)
├── group/                # 当前分组目录(工作目录)
├── project/              # 项目根目录(仅主频道)
├── global/               # 全局CLAUDE.md(非主频道)
├── ipc/                  # 进程间通信目录
│   ├── messages/         # 待发送WhatsApp消息
│   ├── tasks/            # 定时任务命令
│   ├── current_tasks.json    # 只读:当前分组可见的定时任务
│   └── available_groups.json # 只读:可激活的WhatsApp分组(仅主频道)
└── extra/                # 额外自定义挂载

4. Permission Issues

4. 权限问题

The container runs as user
node
(uid 1000). Check ownership:
bash
docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c '
  whoami
  ls -la /workspace/
  ls -la /app/
'
All of
/workspace/
and
/app/
should be owned by
node
.
容器以
node
用户(uid 1000)运行。检查文件所有权:
bash
docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c '
  whoami
  ls -la /workspace/
  ls -la /app/
'
/workspace/
/app/
目录都应归
node
用户所有。

5. Session Not Resuming / "Claude Code process exited with code 1"

5. 会话无法恢复 /「Claude Code进程退出,代码为1」

If sessions aren't being resumed (new session ID every time), or Claude Code exits with code 1 when resuming:
Root cause: The SDK looks for sessions at
$HOME/.claude/projects/
. Inside the container,
HOME=/home/node
, so it looks at
/home/node/.claude/projects/
.
Check the mount path:
bash
undefined
如果会话无法恢复(每次生成新会话ID),或恢复会话时Claude Code退出并返回代码1:
根本原因: SDK在
$HOME/.claude/projects/
路径下查找会话。容器内部
HOME=/home/node
,因此会查找
/home/node/.claude/projects/
检查挂载路径:
bash
undefined

In container-runner.ts, verify mount is to /home/node/.claude/, NOT /root/.claude/

在container-runner.ts中,验证挂载路径为/home/node/.claude/,而非/root/.claude/

grep -A3 "Claude sessions" src/orchestrator/container-runner.ts

**Verify sessions are accessible:**
```bash
docker run --rm --entrypoint /bin/bash \
  -v ~/.claude:/home/node/.claude \
  claudeclaw-agent:latest -c '
echo "HOME=$HOME"
ls -la $HOME/.claude/projects/ 2>&1 | head -5
'
Fix: Ensure
container-runner.ts
mounts to
/home/node/.claude/
:
typescript
mounts.push({
  hostPath: claudeDir,
  containerPath: '/home/node/.claude',  // NOT /root/.claude
  readonly: false
});
grep -A3 "Claude sessions" src/orchestrator/container-runner.ts

**验证会话可访问性:**
```bash
docker run --rm --entrypoint /bin/bash \
  -v ~/.claude:/home/node/.claude \
  claudeclaw-agent:latest -c '
echo "HOME=$HOME"
ls -la $HOME/.claude/projects/ 2>&1 | head -5
'
修复方案: 确保
container-runner.ts
挂载到
/home/node/.claude/
typescript
mounts.push({
  hostPath: claudeDir,
  containerPath: '/home/node/.claude',  // 不要写成/root/.claude
  readonly: false
});

6. MCP Server Failures

6. MCP服务器启动失败

If an MCP server fails to start, the agent may exit. Check the container logs for MCP initialization errors.
如果MCP服务器启动失败,Agent可能会退出。检查容器日志中的MCP初始化错误信息。

Manual Container Testing

手动容器测试

Test the full agent flow:

测试完整Agent流程:

bash
undefined
bash
undefined

Set up env file

创建环境文件目录

mkdir -p data/env groups/test cp .env data/env/env
mkdir -p data/env groups/test cp .env data/env/env

Run test query

运行测试查询

echo '{"prompt":"What is 2+2?","groupFolder":"test","chatJid":"test@g.us","isMain":false}' |
docker run -i
-v $(pwd)/data/env:/workspace/env-dir:ro
-v $(pwd)/groups/test:/workspace/group
-v $(pwd)/data/ipc:/workspace/ipc
claudeclaw-agent:latest
undefined
echo '{"prompt":"What is 2+2?","groupFolder":"test","chatJid":"test@g.us","isMain":false}' |
docker run -i
-v $(pwd)/data/env:/workspace/env-dir:ro
-v $(pwd)/groups/test:/workspace/group
-v $(pwd)/data/ipc:/workspace/ipc
claudeclaw-agent:latest
undefined

Test Claude Code directly:

直接测试Claude Code:

bash
docker run --rm --entrypoint /bin/bash \
  -v $(pwd)/data/env:/workspace/env-dir:ro \
  claudeclaw-agent:latest -c '
  export $(cat /workspace/env-dir/env | xargs)
  claude -p "Say hello" --dangerously-skip-permissions --allowedTools ""
'
bash
docker run --rm --entrypoint /bin/bash \
  -v $(pwd)/data/env:/workspace/env-dir:ro \
  claudeclaw-agent:latest -c '
  export $(cat /workspace/env-dir/env | xargs)
  claude -p "Say hello" --dangerously-skip-permissions --allowedTools ""
'

Interactive shell in container:

进入容器交互式shell:

bash
docker run --rm -it --entrypoint /bin/bash claudeclaw-agent:latest
bash
docker run --rm -it --entrypoint /bin/bash claudeclaw-agent:latest

SDK Options Reference

SDK选项参考

The agent-runner uses these Claude Agent SDK options:
typescript
query({
  prompt: input.prompt,
  options: {
    cwd: '/workspace/group',
    allowedTools: ['Bash', 'Read', 'Write', ...],
    permissionMode: 'bypassPermissions',
    allowDangerouslySkipPermissions: true,  // Required with bypassPermissions
    settingSources: ['project'],
    mcpServers: { ... }
  }
})
Important:
allowDangerouslySkipPermissions: true
is required when using
permissionMode: 'bypassPermissions'
. Without it, Claude Code exits with code 1.
Agent-runner使用以下Claude Agent SDK选项:
typescript
query({
  prompt: input.prompt,
  options: {
    cwd: '/workspace/group',
    allowedTools: ['Bash', 'Read', 'Write', ...],
    permissionMode: 'bypassPermissions',
    allowDangerouslySkipPermissions: true,  // 使用bypassPermissions时必须设置
    settingSources: ['project'],
    mcpServers: { ... }
  }
})
重要提示: 使用
permissionMode: 'bypassPermissions'
时必须设置
allowDangerouslySkipPermissions: true
。否则Claude Code会以代码1退出。

Rebuilding After Changes

修改后重新构建

bash
undefined
bash
undefined

Rebuild main app

重新构建主应用

npm run build
npm run build

Rebuild container (use --no-cache for clean rebuild)

重新构建容器(使用--no-cache进行干净构建)

./src/runtimes/docker/build.sh
./src/runtimes/docker/build.sh

Or force full rebuild

或强制完全重新构建

docker builder prune -af ./src/runtimes/docker/build.sh
undefined
docker builder prune -af ./src/runtimes/docker/build.sh
undefined

Checking Container Image

检查容器镜像

bash
undefined
bash
undefined

List images

列出镜像

docker images
docker images

Check what's in the image

检查镜像内容

docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c ' echo "=== Node version ===" node --version
echo "=== Claude Code version ===" claude --version
echo "=== Installed packages ===" ls /app/node_modules/ '
undefined
docker run --rm --entrypoint /bin/bash claudeclaw-agent:latest -c ' echo "=== Node版本 ===" node --version
echo "=== Claude Code版本 ===" claude --version
echo "=== 已安装包 ===" ls /app/node_modules/ '
undefined

Session Persistence

会话持久化

Claude sessions are stored per-group in
data/sessions/{group}/.claude/
for security isolation. Each group has its own session directory, preventing cross-group access to conversation history.
Critical: The mount path must match the container user's HOME directory:
  • Container user:
    node
  • Container HOME:
    /home/node
  • Mount target:
    /home/node/.claude/
    (NOT
    /root/.claude/
    )
To clear sessions:
bash
undefined
Claude会话按分组存储在
data/sessions/{group}/.claude/
中,实现安全隔离。每个分组拥有独立的会话目录,防止跨分组访问对话历史。
关键注意事项: 挂载路径必须与容器用户的HOME目录匹配:
  • 容器用户:
    node
  • 容器HOME:
    /home/node
  • 挂载目标:
    /home/node/.claude/
    (而非
    /root/.claude/
清除会话:
bash
undefined

Clear all sessions for all groups

清除所有分组的会话

rm -rf data/sessions/
rm -rf data/sessions/

Clear sessions for a specific group

清除特定分组的会话

rm -rf data/sessions/{groupFolder}/.claude/
rm -rf data/sessions/{groupFolder}/.claude/

Also clear the session ID from ClaudeClaw's tracking (stored in SQLite)

同时清除ClaudeClaw跟踪的会话ID(存储在SQLite中)

sqlite3 store/messages.db "DELETE FROM sessions WHERE group_folder = '{groupFolder}'"

To verify session resumption is working, check the logs for the same session ID across messages:
```bash
grep "Session initialized" logs/claudeclaw.log | tail -5
sqlite3 store/messages.db "DELETE FROM sessions WHERE group_folder = '{groupFolder}'"

验证会话恢复功能是否正常,检查日志中同一分组的连续消息是否使用相同会话ID:
```bash
grep "Session initialized" logs/claudeclaw.log | tail -5

Should show the SAME session ID for consecutive messages in the same group

同一分组的连续消息应显示相同的会话ID

undefined
undefined

IPC Debugging

IPC调试

The container communicates back to the host via files in
/workspace/ipc/
:
bash
undefined
容器通过
/workspace/ipc/
目录下的文件与主机通信:
bash
undefined

Check pending messages

检查待发送消息

ls -la data/ipc/messages/
ls -la data/ipc/messages/

Check pending task operations

检查待处理任务操作

ls -la data/ipc/tasks/
ls -la data/ipc/tasks/

Read a specific IPC file

读取特定IPC文件

cat data/ipc/messages/*.json
cat data/ipc/messages/*.json

Check available groups (main channel only)

检查可用分组(仅主频道)

cat data/ipc/main/available_groups.json
cat data/ipc/main/available_groups.json

Check current tasks snapshot

检查当前任务快照

cat data/ipc/{groupFolder}/current_tasks.json

**IPC file types:**
- `messages/*.json` - Agent writes: outgoing WhatsApp messages
- `tasks/*.json` - Agent writes: task operations (schedule, pause, resume, cancel, refresh_groups)
- `current_tasks.json` - Host writes: read-only snapshot of scheduled tasks
- `available_groups.json` - Host writes: read-only list of WhatsApp groups (main only)
cat data/ipc/{groupFolder}/current_tasks.json

**IPC文件类型:**
- `messages/*.json` - Agent写入:待发送WhatsApp消息
- `tasks/*.json` - Agent写入:任务操作(调度、暂停、恢复、取消、刷新分组)
- `current_tasks.json` - 主机写入:只读定时任务快照
- `available_groups.json` - 主机写入:只读WhatsApp分组列表(仅主频道)

Sandbox Runtime Debugging

沙箱运行时调试

If
RUNTIME=sandbox
is set, agents run via
@anthropic-ai/sandbox-runtime
instead of containers.
如果设置
RUNTIME=sandbox
,Agent将通过
@anthropic-ai/sandbox-runtime
而非容器运行。

Sandbox Architecture

沙箱架构

Host (macOS/Linux)
───────────────────────────────────────────
src/orchestrator/sandbox-runner.ts
    │ spawns sandboxed process via srt CLI
    │ with kernel-enforced filesystem/network
    ├── CLAUDECLAW_GROUP_DIR → groups/{folder}
    ├── CLAUDECLAW_IPC_DIR → data/ipc/{folder}
    ├── CLAUDECLAW_PROJECT_DIR → project root (read-only)
    ├── CLAUDECLAW_GLOBAL_DIR → groups/global (read-only)
    └── CLAUDECLAW_EXTRA_DIR → additional mounts
Host (macOS/Linux)
───────────────────────────────────────────
src/orchestrator/sandbox-runner.ts
    │ spawns sandboxed process via srt CLI
    │ with kernel-enforced filesystem/network
    ├── CLAUDECLAW_GROUP_DIR → groups/{folder}
    ├── CLAUDECLAW_IPC_DIR → data/ipc/{folder}
    ├── CLAUDECLAW_PROJECT_DIR → project root (read-only)
    ├── CLAUDECLAW_GLOBAL_DIR → groups/global (read-only)
    └── CLAUDECLAW_EXTRA_DIR → additional mounts

Sandbox-Specific Issues

沙箱特定问题

EPERM on all operations: The srt settings JSON file requires ALL fields including empty arrays (
allowRead: []
). Omit any field and the entire settings file silently fails validation — zero error messages.
Agent runner won't start (tsx/EPERM): Sandbox blocks Unix sockets needed by
tsx
. Fix: pre-compile with
cd agent/runner && npx tsc
, run with plain
node
.
Agent can't find paths: Check that
CLAUDECLAW_*_DIR
env vars are set in
sandbox-runner.ts
. The agent runner falls back to
/workspace/*
if env vars are missing.
Stale sessions after runtime switch: Switching a group between container and sandbox leaves stale session IDs. Fix:
sqlite3 store/messages.db "DELETE FROM sessions"
Network blocked: Verify
allowedDomains
in the generated settings file includes
api.anthropic.com
. Check
data/sandbox-settings/
for the last generated settings file.
Credential issues: Sandbox passes real credentials via env vars (not through the credential proxy). Ensure
ANTHROPIC_API_KEY
or
CLAUDE_CODE_OAUTH_TOKEN
is in
.env
.
所有操作均返回EPERM: srt设置JSON文件需要包含所有字段,包括空数组(如
allowRead: []
)。省略任何字段会导致整个设置文件静默验证失败,且无错误提示。
Agent runner无法启动(tsx/EPERM): 沙箱阻止了
tsx
所需的Unix套接字。修复方案:预编译代码(
cd agent/runner && npx tsc
),使用普通
node
运行。
Agent无法找到路径: 检查
sandbox-runner.ts
中是否设置了
CLAUDECLAW_*_DIR
环境变量。如果缺少这些变量,Agent runner会回退到
/workspace/*
路径。
切换运行时后会话失效: 在容器与沙箱之间切换分组会留下失效的会话ID。修复方案:
sqlite3 store/messages.db "DELETE FROM sessions"
网络被阻止: 验证生成的设置文件中
allowedDomains
包含
api.anthropic.com
。检查
data/sandbox-settings/
目录下最新生成的设置文件。
凭证问题: 沙箱通过环境变量传递真实凭证(而非通过凭证代理)。确保
.env
文件中包含
ANTHROPIC_API_KEY
CLAUDE_CODE_OAUTH_TOKEN

Quick Diagnostic Script

快速诊断脚本

Run this to check common issues:
bash
echo "=== Checking ClaudeClaw Agent Setup ==="

echo -e "\n1. Authentication configured?"
[ -f .env ] && (grep -q "CLAUDE_CODE_OAUTH_TOKEN=sk-" .env || grep -q "ANTHROPIC_API_KEY=sk-" .env) && echo "OK" || echo "MISSING - add CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY to .env"

echo -e "\n2. Env file copied for container?"
[ -f data/env/env ] && echo "OK" || echo "MISSING - will be created on first run"

echo -e "\n3. Container runtime running?"
docker info &>/dev/null && echo "OK" || echo "NOT RUNNING - start Docker Desktop (macOS) or sudo systemctl start docker (Linux)"

echo -e "\n4. Container image exists?"
echo '{}' | docker run -i --entrypoint /bin/echo claudeclaw-agent:latest "OK" 2>/dev/null || echo "MISSING - run ./src/runtimes/docker/build.sh"

echo -e "\n5. Session mount path correct?"
grep -q "/home/node/.claude" src/orchestrator/container-runner.ts 2>/dev/null && echo "OK" || echo "WRONG - should mount to /home/node/.claude/, not /root/.claude/"

echo -e "\n6. Groups directory?"
ls -la groups/ 2>/dev/null || echo "MISSING - run setup"

echo -e "\n7. Recent container logs?"
ls -t groups/*/logs/container-*.log 2>/dev/null | head -3 || echo "No container logs yet"

echo -e "\n8. Session continuity working?"
SESSIONS=$(grep "Session initialized" logs/claudeclaw.log 2>/dev/null | tail -5 | awk '{print $NF}' | sort -u | wc -l)
[ "$SESSIONS" -le 2 ] && echo "OK (recent sessions reusing IDs)" || echo "CHECK - multiple different session IDs, may indicate resumption issues"
运行以下脚本检查常见问题:
bash
echo "=== 检查ClaudeClaw Agent配置 ==="

echo -e "\n1. 认证已配置?"
[ -f .env ] && (grep -q "CLAUDE_CODE_OAUTH_TOKEN=sk-" .env || grep -q "ANTHROPIC_API_KEY=sk-" .env) && echo "正常" || echo "缺失 - 请在.env中添加CLAUDE_CODE_OAUTH_TOKEN或ANTHROPIC_API_KEY"

echo -e "\n2. 环境文件已复制到容器目录?"
[ -f data/env/env ] && echo "正常" || echo "缺失 - 首次运行时会自动创建"

echo -e "\n3. 容器运行时已启动?"
docker info &>/dev/null && echo "正常" || echo "未运行 - 启动Docker Desktop(macOS)或执行sudo systemctl start docker(Linux)"

echo -e "\n4. 容器镜像存在?"
echo '{}' | docker run -i --entrypoint /bin/echo claudeclaw-agent:latest "正常" 2>/dev/null || echo "缺失 - 运行./src/runtimes/docker/build.sh"

echo -e "\n5. 会话挂载路径正确?"
grep -q "/home/node/.claude" src/orchestrator/container-runner.ts 2>/dev/null && echo "正常" || echo "错误 - 应挂载到/home/node/.claude/,而非/root/.claude/"

echo -e "\n6. 分组目录存在?"
ls -la groups/ 2>/dev/null || echo "缺失 - 执行初始化设置"

echo -e "\n7. 最近的容器日志?"
ls -t groups/*/logs/container-*.log 2>/dev/null | head -3 || echo "暂无容器日志"

echo -e "\n8. 会话连续性正常?"
SESSIONS=$(grep "Session initialized" logs/claudeclaw.log 2>/dev/null | tail -5 | awk '{print $NF}' | sort -u | wc -l)
[ "$SESSIONS" -le 2 ] && echo "正常(最近会话复用ID)" || echo "需检查 - 存在多个不同会话ID,可能表示恢复功能异常"