English | 中文
2026-03-18 update: Discord thread routing has been re-validated end-to-end. Managed
claude-agent/codex-agentsessions now use active-pane + ready-state forwarding, completion/monitor notifications extract nestedmessageIdvalues reliably, and replying directly to an agent's thread message can route back throughreply-target-message-idto the original tmux session.
cli-agentsis a consolidated repository for OpenClaw / agent-deck terminal agent workflows. It brings togethercodex-agent,claude-agent, and shared bridge utilities into a single versioned runtime that handles session startup, monitoring, notifications, thread routing, reply-target mapping, and multi-session coordination.
In one sentence: cli-agents is a runtime toolkit that helps OpenClaw operate CLI coding agents reliably in real terminal environments.
Instead of treating Codex or Claude Code as isolated command-line tools, this repository provides the runtime glue that lets higher-level agents:
- launch and manage CLI agents inside
tmux - detect important lifecycle events such as task start, task completion, and approval prompts
- send notifications back to Discord / Telegram / bound threads
- route user replies back to the original tmux session
- keep multi-session / multi-thread / multi-workdir workflows stable
This is not just the README for a single agent. It is a unified runtime repository that contains:
codex-agent/— tmux + hook workflow for Codexclaude-agent/— tmux + hook workflow for Claude Codebridge/— shared routing, reply-target mapping, and forwarding utilities
If you use CLI agents manually, the flow usually looks like this:
Open terminal → write prompt → launch CLI agent → watch output → approve commands/tools → iterate → finish
cli-agents aims to make the flow look more like this:
User assigns a task in chat → OpenClaw prepares and orchestrates execution →
CLI agent keeps running in tmux → key events trigger notifications →
user can reply, intervene, or take over at any time
The goal is not to replace Codex or Claude Code. The goal is to make them fit into a stable, observable, routable, asynchronously managed agent workflow.
This repository puts codex-agent and claude-agent under one roof so that:
- shared bridge tools live in one place
- path conventions stay stable
- updates are easier to coordinate
- the runtime is versioned as one deployable unit
In real chat-driven workflows, common failures include:
- notifications going to the wrong thread
- replies not returning to the original session
- route bindings drifting after session restarts
- multiple agents competing for the same thread
This repository uses route files, bridge scripts, and reply-target maps to make routing more robust.
CLI agent tasks often outlive a single agent turn. Running them in tmux provides:
- persistent execution for long-running tasks
- manual takeover via
tmux attach - event-driven wakeups instead of constant polling by the parent agent
- less dependence on one foreground chat turn remaining alive forever
The runtime splits notifications into meaningful event classes:
- task start
- task completion
- approval wait
- reply-target routing
In practice:
- Claude Code relies more on native hooks
- Codex combines completion hooks with
pane_monitor.sh
Discord and similar platforms impose message length limits. The current runtime already supports:
- automatic chunking for long notifications
- chunk numbering such as
[1/N] - fenced code block aware chunk splitting
That means long logs and long assistant replies are not simply truncated, and Markdown code fences are much less likely to break mid-message.
The runtime is built around three layers.
Each CLI agent runs inside its own tmux session.
Examples:
codex-agent/hooks/start_codex.shclaude-agent/hooks/start_claude.sh
These launchers are responsible for:
- creating sessions
- writing route files
- starting monitors
- injecting runtime context
- sending one extra empty
Enteron first startup to help unblock trust-directory / continue prompts in newly entered workdirs
This layer detects important lifecycle changes:
on_complete.py— task completion notificationspane_monitor.sh— approval wait / task start state detectiontask_start.py— Claude Code task start event handling
This is the layer that decides when to notify, what to notify, and where the notification should go.
Located in:
bridge/agent_session_router.pybridge/reply_route_map.py
This layer is responsible for:
- mapping threads or reply-targets to sessions
- selecting the correct session from route files
- forwarding user messages into the right tmux session
cli-agents/
├── README.md # English overview
├── README_zh.md # Chinese overview
├── CHANGELOG.md # Repository-level changelog
│
├── bridge/
│ ├── agent_session_router.py
│ └── reply_route_map.py
│
├── codex-agent/
│ ├── README.md
│ ├── README_EN.md
│ ├── INSTALL.md
│ ├── SKILL.md
│ └── hooks/
│ ├── start_codex.sh
│ ├── pane_monitor.sh
│ └── on_complete.py
│
└── claude-agent/
├── README.md
├── README_EN.md
├── INSTALL.md
├── SKILL.md
└── hooks/
├── start_claude.sh
├── task_start.py
├── pane_monitor.sh
└── on_complete.py
For detailed setup, read each subproject’s own
INSTALL.mdfirst.
git clone git@github.com:L4ntern0/cli-agents.git
cd cli-agentsA typical location would be:
~/.openclaw/workspace-coding/skills/cli-agentsYou should have at least:
bashpython3gittmux- the actual CLI agents you want to use (for example
codexand/orclaude)
Example checks:
bash --version
python3 --version
git --version
tmux -VRead the corresponding docs:
codex-agent/README.mdcodex-agent/INSTALL.mdclaude-agent/README.mdclaude-agent/INSTALL.md
cli-agents is a unified repository, but each runtime still depends on the specific CLI tool you actually want to run.
Whenever you modify hooks, monitors, or bridge logic, it is strongly recommended to run:
bash -n codex-agent/hooks/*.sh
bash -n claude-agent/hooks/*.sh
python3 -m py_compile bridge/*.py codex-agent/hooks/*.py claude-agent/hooks/*.pyAfter setup, the repository can be integrated into:
- OpenClaw agent workflows
- agent-deck thread / session management
- Discord / Telegram notification routing
- tmux-driven long-running task execution
- Codex:
on_complete.py - Claude Code:
on_complete.py
Supported features include:
- response notifications
- reply-target mapping
- automatic long-message chunking
- fenced code block aware chunking
- Claude Code uses more native hooks plus monitor logic
- Codex relies more heavily on pane monitor state detection
When a Discord thread is already bound to a live tmux session, the OpenClaw agent should first invoke the unified router:
python3 skills/cli-agents/bridge/agent_session_router.py \
--chat-id <chat_id> \
--channel <channel> \
--message "<text>"If a message starts with >> , the intended behavior is:
- strip the prefix
- lightly polish or expand the message so it works better as a prompt for the bound CLI agent
- do not explain it, do not answer it yourself, and do not change the original intent
- forward the refined message to the bound session
This matters because in CLI-agent workflows, users often want the main agent to act as a lightweight prompt organizer before handing the task to the tmux-managed agent.
The scripts here directly participate in:
- session startup
- route binding
- monitor execution
- completion hooks
- user notifications
That means changes here should be treated as changes to production runtime components, not just examples.
If a session is manually restarted, renamed, or moved to a different workdir without refreshing route files, you can easily end up with:
- notifications going to the wrong thread
- reply routing failing
- threads that look bound but are actually stale
Discord and similar platforms impose practical message limits. If you extend the notification format later, avoid reintroducing “send one huge message and let the platform truncate it” behavior.
This project has primarily been tested under GPT-5.4.
At the moment, OpenClaw does not provide a Discord message-level hook / interceptor that can enforce thread forwarding at the gateway layer. Because of that, message forwarding is currently implemented mainly through rules written in AGENTS.md, instructing the main agent to invoke the router first before deciding whether to answer directly.
This approach works, but in practice the agent may occasionally forget or drift away from those rules. So for important threads, important tasks, or any situation where forwarding looks suspicious, it is wise to restate and re-confirm the forwarding rules explicitly.
In practice, that usually means reminding the agent that:
- routing should be attempted first
- bound sessions should be forwarded to by default
>>messages should be refined and then forwarded according to the documented convention- the main agent should only answer directly when there is no binding or an explicit escape applies
A good commit split usually looks like:
- monitor behavior fixes
- route matching fixes
- notification chunking improvements
- documentation updates
That makes troubleshooting, rollback, and review much easier.
This repository did not emerge from a vacuum. It builds on ideas and implementations from upstream projects, then adapts them to real OpenClaw / agent-deck workflows.
Special thanks to the original repositories and authors:
Their work provided the baseline concepts and implementation patterns that made this consolidated runtime possible.
On top of those foundations, cli-agents extends the system with:
- unified repository layout
- shared bridge routing tools
- reply-target mapping
- thread/session auto-forwarding
- monitor stability improvements
- Discord long-message chunking
- fenced code block aware chunk splitting
In short, cli-agents is both a continuation of those upstream ideas and a runtime-focused evolution shaped by real operational needs.
- INSTALL.md — repository-level installation and setup notes
- CHANGELOG.md — repository-level change history
- codex-agent/README.md — detailed Codex agent documentation
- codex-agent/README_EN.md — Codex agent English README
- codex-agent/INSTALL.md — Codex agent setup guide
- claude-agent/README.md — detailed Claude Code agent documentation
- claude-agent/README_EN.md — Claude agent English README
- claude-agent/INSTALL.md — Claude agent setup guide
If you want the repository to be explicitly open source, add a LICENSE file at the repository root.
This README describes purpose, structure, and operations, but it is not a substitute for a formal license file.