exec-inspector查看和分析 OpenClaw Agent exec 工具的执行历史,支持查询、搜索、统计和实时监控命令使用详情。
Install via ClawdBot CLI:
clawdbot install zhengzk-bj/exec-inspector查看和分析 OpenClaw Agent 的 exec 工具执行历史和明细。
当用户提出以下需求时,AI 应该立即执行相应命令,而不是只告诉用户怎么做:
| 用户说什么 | AI 应该做什么 | 执行命令 |
|-----------|--------------|---------|
| "最近执行了哪些命令" | 列出最近 20 条 | ~/.openclaw/scripts/exec-history.sh list |
| "统计命令使用情况" | 显示统计数据 | ~/.openclaw/scripts/exec-history.sh stats |
| "查找/搜索 XXX 命令" | 搜索特定命令 | ~/.openclaw/scripts/exec-history.sh search XXX |
| "今天执行了什么" | 显示今天的命令 | ~/.openclaw/scripts/exec-history.sh today |
| "查看 session 列表" | 列出所有 sessions | ~/.openclaw/scripts/exec-history.sh session |
| "查看所有工具使用" | 统计所有工具 | ~/.openclaw/scripts/exec-history.sh all-tools |
| "实时监控 exec" | 启动实时监控 | ~/.openclaw/scripts/exec-history.sh watch |
| "导出执行历史" | 导出 JSON 文件 | ~/.openclaw/scripts/exec-history.sh export |
~/.openclaw/scripts/exec-history.sh❌ 错误示例 (只告诉,不执行):
用户: 我最近执行了哪些命令?
AI: 你可以运行 exec-history.sh list 来查看...
✅ 正确示例 (立即执行):
用户: 我最近执行了哪些命令?
AI: 让我查看一下... [运行命令]
📋 最近 20 条 exec 命令:
1. ls -la (今天 15:30)
2. git status (今天 15:28)
...
看起来你今天主要在做 git 操作和文件管理。
# 启动后台守护进程
~/.openclaw/scripts/exec-monitor-daemon.sh start
# 查看实时输出
~/.openclaw/scripts/exec-monitor-daemon.sh tail
效果:从此刻起,OpenClaw 每次执行 exec 命令时,都会自动在日志中实时输出!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚡ EXEC COMMAND DETECTED
🕐 Time: 15:30:45
🤖 Model: gpt-4.1 (friday-aws)
📋 Command: ls -la
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚡ EXEC COMMAND DETECTED
🕐 Time: 15:30:48
🤖 Model: gpt-4.1 (friday-aws)
📋 Command: git status
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
| 命令 | 说明 |
|------|------|
| start | 启动后台监控守护进程 |
| stop | 停止守护进程 |
| restart | 重启守护进程 |
| status | 查看守护进程状态 |
| tail | 实时查看监控输出 |
1. 启动守护进程
~/.openclaw/scripts/exec-monitor-daemon.sh start
2. 在另一个终端查看实时输出
~/.openclaw/scripts/exec-monitor-daemon.sh tail
3. 正常使用 OpenClaw
4. 停止监控
~/.openclaw/scripts/exec-monitor-daemon.sh stop
# 添加到 ~/.zshrc 或 ~/.bashrc
alias exec-monitor='~/.openclaw/scripts/exec-monitor-daemon.sh'
alias exec-monitor-start='~/.openclaw/scripts/exec-monitor-daemon.sh start && ~/.openclaw/scripts/exec-monitor-daemon.sh tail'
alias exec-monitor-stop='~/.openclaw/scripts/exec-monitor-daemon.sh stop'
然后:
exec-monitor-start # 启动并立即查看输出
exec-monitor status # 查看状态
exec-monitor-stop # 停止
# 查看最近 10 条 exec 执行记录
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | tail -10 | while read line; do echo "$line" | jq -r '.message.content[0].arguments.command'; done
# 或者使用更详细的格式
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | tail -10 | jq -r '"\(.timestamp) | \(.message.content[0].arguments.command)"'
# 统计所有 exec 命令的使用频率
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | jq -r '.message.content[0].arguments.command' | sort | uniq -c | sort -rn
# 查看特定 session 的所有 exec 命令
SESSION_ID="aa19ccb2-19ff-4458-84b4-d20e688fd797"
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/${SESSION_ID}.jsonl | jq -r '"\(.timestamp) | \(.message.content[0].arguments.command)"'
# 搜索包含特定关键字的命令执行记录
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | jq -r 'select(.message.content[0].arguments.command | contains("git")) | "\(.timestamp) | \(.message.content[0].arguments.command)"'
# 查看包含输入输出的完整记录
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | jq -C '.'
# 统计所有工具的使用频率
grep -o '"name":"[^"]*"' ~/.openclaw/agents/main/sessions/*.jsonl | sort | uniq -c | sort -rn
# 查看今天的 exec 执行记录
TODAY=$(date +%Y-%m-%d)
grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl | jq -r "select(.timestamp | startswith(\"$TODAY\")) | \"\(.timestamp) | \(.message.content[0].arguments.command)\""
创建一个便捷的脚本来查看 exec 历史:
cat > ~/.openclaw/scripts/exec-history.sh <<'EOF'
#!/bin/bash
# OpenClaw Exec History Viewer
SESSION_DIR="$HOME/.openclaw/agents/main/sessions"
case "$1" in
list|"")
echo "📋 Recent exec commands (last 20):"
grep '"name":"exec"' "$SESSION_DIR"/*.jsonl 2>/dev/null | tail -20 | jq -r '"\(.timestamp | split("T")[0]) \(.timestamp | split("T")[1] | split(".")[0]) | \(.message.content[0].arguments.command)"' | nl
;;
stats)
echo "📊 Command usage statistics:"
grep '"name":"exec"' "$SESSION_DIR"/*.jsonl 2>/dev/null | jq -r '.message.content[0].arguments.command' | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
;;
search)
if [ -z "$2" ]; then
echo "Usage: $0 search <keyword>"
exit 1
fi
echo "🔍 Searching for commands containing: $2"
grep '"name":"exec"' "$SESSION_DIR"/*.jsonl 2>/dev/null | jq -r "select(.message.content[0].arguments.command | contains(\"$2\")) | \"\(.timestamp | split(\"T\")[0]) \(.timestamp | split(\"T\")[1] | split(\".\")[0]) | \(.message.content[0].arguments.command)\"" | nl
;;
today)
TODAY=$(date +%Y-%m-%d)
echo "📅 Commands executed today ($TODAY):"
grep '"name":"exec"' "$SESSION_DIR"/*.jsonl 2>/dev/null | jq -r "select(.timestamp | startswith(\"$TODAY\")) | \"\(.timestamp | split(\"T\")[1] | split(\".\")[0]) | \(.message.content[0].arguments.command)\"" | nl
;;
session)
if [ -z "$2" ]; then
echo "Available sessions:"
ls -1 "$SESSION_DIR"/*.jsonl | xargs basename -s .jsonl | nl
exit 0
fi
SESSION_FILE="$SESSION_DIR/$2.jsonl"
if [ ! -f "$SESSION_FILE" ]; then
echo "Session not found: $2"
exit 1
fi
echo "📝 Exec history for session: $2"
grep '"name":"exec"' "$SESSION_FILE" 2>/dev/null | jq -r '"\(.timestamp | split("T")[0]) \(.timestamp | split("T")[1] | split(".")[0]) | \(.message.content[0].arguments.command)"' | nl
;;
all-tools)
echo "🔧 All tool usage statistics:"
grep -o '"name":"[^"]*"' "$SESSION_DIR"/*.jsonl 2>/dev/null | grep -v '"name":"[A-Z]' | sort | uniq -c | sort -rn
;;
*)
echo "Usage: $0 {list|stats|search|today|session|all-tools} [args]"
echo ""
echo "Commands:"
echo " list - Show recent 20 exec commands"
echo " stats - Show command usage statistics"
echo " search <kw> - Search for commands containing keyword"
echo " today - Show today's executed commands"
echo " session [id] - Show exec history for a specific session"
echo " all-tools - Show usage stats for all tools"
;;
esac
EOF
chmod +x ~/.openclaw/scripts/exec-history.sh
当用户询问 exec 执行历史时,你应该:
用户: "我最近执行了哪些命令?"
AI 回复:
让我查看一下你最近的 exec 执行记录...
📋 最近 10 条 exec 命令:
1. 2026-02-10 15:30:45 | ls -la
2. 2026-02-10 15:28:12 | git status
3. 2026-02-10 15:25:33 | npm install
4. 2026-02-10 14:55:20 | grep '"name":"exec"' ~/.openclaw/agents/main/sessions/*.jsonl
5. 2026-02-10 14:50:10 | cat package.json
6. 2026-02-10 14:45:05 | pwd
7. 2026-02-10 14:40:22 | node --version
8. 2026-02-10 14:35:15 | docker ps
9. 2026-02-10 14:30:08 | tail -f logs/app.log
10. 2026-02-10 14:25:45 | find . -name "*.js"
📊 最常用的命令类型:
- git (15次)
- npm (12次)
- ls (10次)
- grep (8次)
- docker (5次)
Session 文件存储在 ~/.openclaw/agents/main/sessions/ 目录下,每个 session 对应一个 .jsonl 文件。
Exec 工具调用记录结构:
{
"type": "message",
"id": "d3478fcf",
"parentId": "9631fadb",
"timestamp": "2026-02-05T12:15:25.206Z",
"message": {
"role": "assistant",
"content": [
{
"type": "toolCall",
"id": "call_2e8e8fa469e14f478aa15ae5",
"name": "exec",
"arguments": {
"command": "ls -la"
}
}
],
"api": "openai-completions",
"provider": "friday-longcat",
"model": "LongCat-Flash-Chat",
"usage": {
"input": 15688,
"output": 21,
"totalTokens": 15709
},
"stopReason": "toolUse",
"timestamp": 1770293723959
}
}
timestamp: ISO 8601 格式的执行时间message.content[0].name: 工具名称 (exec)message.content[0].arguments.command: 执行的命令message.provider: 使用的模型提供商message.model: 使用的具体模型message.usage: Token 使用统计# 创建便捷别名
alias exec-history='~/.openclaw/scripts/exec-history.sh'
alias exec-list='exec-history list'
alias exec-stats='exec-history stats'
alias exec-today='exec-history today'
# 使用示例
exec-list # 查看最近执行的命令
exec-stats # 查看统计信息
exec-search git # 搜索 git 相关命令
exec-today # 查看今天执行的命令
exec-history all-tools # 查看所有工具的使用统计
~/.openclaw/agents/main/sessions/*.jsonl~/.openclaw/logs/gateway.log~/.openclaw/agents/main/agent/jq 工具处理 JSON 数据,请确保已安装你可以基于这个 skill 创建:
版本: 1.0.0
作者: OpenClaw Community
最后更新: 2026-02-10
Generated Mar 1, 2026
Software development teams can use Exec Inspector to track command execution patterns during coding sessions, identifying frequently used tools and workflows. This helps optimize development environments and automate repetitive tasks by analyzing historical exec data.
IT security teams can monitor exec commands in real-time to detect unauthorized or suspicious activities within OpenClaw agents. The tool logs all executions, enabling forensic analysis and compliance reporting for security audits.
AI researchers and engineers can analyze exec command histories to debug agent behavior, identify inefficiencies, and refine prompts. The real-time monitoring feature allows for immediate observation of tool usage during agent interactions.
System administrators can leverage Exec Inspector to audit automated scripts and cron jobs executed by OpenClaw agents. It provides insights into command frequency and errors, aiding in maintenance and optimization of system tasks.
Educators and students can use the tool to review and analyze command executions as part of learning programming or system administration. The search and stats features help track progress and identify common mistakes in command usage.
Offer a free basic version with limited history and monitoring features, while charging for advanced analytics, longer retention periods, and team collaboration tools. Revenue is generated through monthly subscriptions for premium tiers.
Sell licenses to large organizations for integration into their internal AI and development platforms. This includes custom features, dedicated support, and compliance with industry-specific regulations like GDPR or HIPAA.
Provide professional services to help companies deploy and customize Exec Inspector within their existing workflows. This includes training, custom script development, and ongoing maintenance for optimal performance.
💬 Integration Tip
Integrate Exec Inspector by setting up the provided scripts and aliases in your shell configuration, then use the real-time monitoring to immediately start capturing exec commands without disrupting existing workflows.
Automatically update Clawdbot and all installed skills once daily. Runs via cron, checks for updates, applies them, and messages the user with a summary of what changed.
Full desktop computer use for headless Linux servers. Xvfb + XFCE virtual desktop with xdotool automation. 17 actions (click, type, scroll, screenshot, drag,...
Essential Docker commands and workflows for container management, image operations, and debugging.
Tool discovery and shell one-liner reference for sysadmin, DevOps, and security tasks. AUTO-CONSULT this skill when the user is: troubleshooting network issues, debugging processes, analyzing logs, working with SSL/TLS, managing DNS, testing HTTP endpoints, auditing security, working with containers, writing shell scripts, or asks 'what tool should I use for X'. Source: github.com/trimstray/the-book-of-secret-knowledge
Deploy applications and manage projects with complete CLI reference. Commands for deployments, projects, domains, environment variables, and live documentation access.
Monitor topics of interest and proactively alert when important developments occur. Use when user wants automated monitoring of specific subjects (e.g., product releases, price changes, news topics, technology updates). Supports scheduled web searches, AI-powered importance scoring, smart alerts vs weekly digests, and memory-aware contextual summaries.