This guide explains how to set up cli-agents for automated codex-agent and claude-agent session management with Discord thread binding.
cli-agents provides:
- Session lifecycle management for Codex and Claude Code
- Discord thread binding and message forwarding
- Real-time notifications for task start/completion
- Auto-forwarding via
>>prefix or router rules
- OpenClaw Gateway running
- Codex CLI installed (
codex) - Claude Code installed (
claude) - Discord account configured in OpenClaw
# If using as part of OpenClaw workspace:
# cli-agents should already be in your workspace at:
# skills/cli-agents/Edit ~/.codex/config.toml:
notify = ["bash", "/path/to/skills/cli-agents/codex-agent/hooks/notify_chain.sh"]Replace /path/to with your actual workspace path.
Edit ~/.claude/settings.json:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 <SKILL_PATH>/hooks/on_complete.py"
}
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "python3 <SKILL_PATH>/hooks/task_start.py",
"async": true
}
]
}
]
}
}Replace <SKILL_PATH> with the path to cli-agents (e.g., /home/user/openclaw/skills/cli-agents/claude-agent).
mkdir -p /tmp/codex-agent-routes
mkdir -p /tmp/claude-agent-routes# Test Codex route resolution
python3 skills/cli-agents/bridge/agent_session_router.py --help
# Start a test Codex session
cd skills/cli-agents/codex-agent/hooks
CODEX_AGENT_SOURCE_CHAT_ID=channel:123456789 \
CODEX_AGENT_SOURCE_CHANNEL=discord \
CODEX_AGENT_SOURCE_ACCOUNT=coder \
./start_codex.sh test_session /tmp --yolocd skills/cli-agents/codex-agent/hooks
# Start with Discord thread binding
CODEX_AGENT_SOURCE_CHAT_ID=channel:THREAD_ID \
CODEX_AGENT_SOURCE_CHANNEL=discord \
CODEX_AGENT_SOURCE_ACCOUNT=coder \
./start_codex.sh my_session /path/to/workdir --yolocd skills/cli-agents/claude-agent/hooks
CLAUDE_AGENT_SOURCE_CHAT_ID=channel:THREAD_ID \
CLAUDE_AGENT_SOURCE_CHANNEL=discord \
CLAUDE_AGENT_SOURCE_ACCOUNT=coder \
./start_claude.sh my_session /path/to/workdir# Codex
./stop_codex.sh my_session
# Claude
./stop_claude.sh my_sessionPrefix your message with >> to have it refined and forwarded to the bound session:
>> 帮我检查这段代码
This will:
- Strip the
>>prefix - Lightly polish or expand the message so it works better as a CLI-agent prompt
- Do not explain the request, answer it directly, or change the original intent
- Forward the refined message to the bound session
- Confirm with
已转发到 <session>
Messages in threads with active bindings are automatically checked:
- If bound session exists: forward
- If no binding: answer directly
Use @Coder to keep message with main agent (won't forward):
@Coder 你好
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Discord │────▶│ OpenClaw Agent │────▶│ Router │
│ Thread │ │ (main session) │ │ (check bind) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐ ┌─────────────────┐
│ Codex/Claude │◀────│ Forward │
│ Tmux Session │ │ (tmux send) │
└──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ Notify (Discord)│
│ - work-start │
│ - task-reply │
└──────────────────┘
| File | Purpose |
|---|---|
bridge/agent_session_router.py |
Unified routing logic |
bridge/reply_route_map.py |
Reply-target mapping |
codex-agent/hooks/start_codex.sh |
Codex session starter |
codex-agent/hooks/pane_monitor.sh |
Codex status monitor |
codex-agent/hooks/on_complete.py |
Codex task completion handler |
claude-agent/hooks/start_claude.sh |
Claude session starter |
claude-agent/hooks/pane_monitor.sh |
Claude status monitor |
claude-agent/hooks/on_complete.py |
Claude task completion handler |
claude-agent/hooks/task_start.py |
Claude task start handler |
monitor-daemon.sh |
Auto-restart monitors |
-
Check Codex/Claude config:
cat ~/.codex/config.toml | grep notify cat ~/.claude/settings.json | grep hooks
-
Check notify log:
tail -f /tmp/codex_notify_log.txt tail -f /tmp/claude_notify_log.txt
-
Restart monitors:
pkill -f pane_monitor.sh ./monitor-daemon.sh start
-
Check route files:
ls /tmp/codex-agent-routes/ ls /tmp/claude-agent-routes/ cat /tmp/codex-agent-routes/<session>.json
-
Verify tmux session:
tmux list-sessions
- README.md - Overview and architecture
- CHANGELOG.md - Version history