When to Use
- After sending a time-consuming test instruction to a workspace (such as "write a 5,000-word review")
- After testing is complete or interrupted, when test traces need to be removed
- When residual test messages in a workspace are found to be affecting the AI context
Complete Cleanup Steps
Step 1: Stop Residual Containers
# 查看当前运行的容器
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.RunningFor}}"
# 确认目标容器的 folder(容器名格式:happyclaw-{folder}-{timestamp})
ls data/ipc/
Send an interrupt signal (graceful stop)
touch data/ipc/{folder}/input/_interrupt sleep 5
If the container is still running, send a shutdown signaltouch data/ipc/{folder}/input/_close sleep 10
Confirm the container has stoppeddocker ps --format "{{.Names}}" | grep {folder keyword}
### 第二步:查找测试消息
```python3
python3 -c "
import sqlite3
conn = sqlite3.connect('data/db/messages.db')
cur = conn.cursor()
# 先找到 folder 对应的 JID
cur.execute(\"SELECT jid, folder, name FROM registered_groups WHERE folder = '{folder}'\")
print('Group:', cur.fetchall())
# 查看最近消息,定位测试消息范围
cur.execute(\"\"\"
SELECT id, content, is_from_me, timestamp
FROM messages
WHERE chat_jid = '{jid}'
ORDER BY timestamp DESC LIMIT 20
\"\"\")
for r in cur.fetchall():
print(f'id={r[0]} from_me={r[2]} | {str(r[1])[:80]}')
conn.close()
"
Step 3: Delete Test Messages
python3 -c "
import sqlite3
conn = sqlite3.connect('data/db/messages.db')
cur = conn.cursor()
# 将需要删除的消息 ID 填入列表
test_ids = [
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
# ...
]
placeholders = ','.join(['?' for _ in test_ids])
cur.execute(f'DELETE FROM messages WHERE id IN ({placeholders})', test_ids)
print(f'Deleted {cur.rowcount} messages')
conn.commit()
conn.close()
"
Step 4: Reset the Claude Session (Key: Clear the Token Context)
python3 -c "
import sqlite3, uuid
conn = sqlite3.connect('data/db/messages.db')
cur = conn.cursor()
# 生成新 session ID,下次启动时以空上下文开始
new_id = str(uuid.uuid4())
cur.execute(\"UPDATE sessions SET session_id = ? WHERE group_folder = '{folder}'\", (new_id,))
print(f'Session reset: {cur.rowcount} rows, new ID: {new_id}')
conn.commit()
conn.close()
"
Step 5: Confirm There Are No Accidental Code Changes
git status
git diff --stat
# 应显示 "nothing to commit, working tree clean"
Notes
- The session must be reset: Deleting DB messages alone is not enough. The Claude session file still stores historical context, which will still consume tokens the next time it is activated.
- Correspondence between container names and folders: The container name format is
happyclaw-{folder}-{timestamp}, and you can view all folders vials data/ipc/View all folders - Check carefully before deleting messages: Confirm via
is_from_meand the content to avoid accidentally deleting normal business messages - Changes to the data/ directory do not affect git: SQLite and IPC files are both under
data/and are not included in version control
Quick Checklist
- No residual test containers are running (
docker ps) - Test messages have been deleted from the DB
- The Claude session ID has been reset to a new UUID
-
git statusshows the workspace is clean