Claude Code Control:macOS 终端自动化 - Openclaw Skills

作者:互联网

2026-03-26

AI教程

什么是 Claude Code Control?

Claude Code Control 是一款功能强大的实用程序,旨在填补手动 CLI 交互与自动化代理工作流之间的空白。通过利用 AppleScript 和 macOS 系统事件,它允许开发人员在可见的 Terminal.app 窗口中启动、指挥和监控 Claude Code。该技能是 Openclaw Skills 用户的核心组件,适用于需要将 Anthropic 的编码代理集成到大型自动化流水线中,同时保持视觉审计终端状态能力的场景。

该工具通过直接与原生 UI 交互,巧妙地绕过了无头环境的限制,确保所有终端功能(包括颜色、提示符和交互元素)的运行效果与人工操作完全一致。这使其成为在 macOS 上构建强大、自文档化 AI 编码工作流的必备工具。

下载入口:https://github.com/openclaw/skills/tree/main/skills/melichar-m/claude-code-control

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install claude-code-control

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 claude-code-control。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Claude Code Control 应用场景

  • 使用 Claude Code 自动执行多步骤代码库重构。
  • 通过自动截图生成 AI 驱动开发会话的视觉文档。
  • 在代理初始化期间通过编程处理安全和文件夹信任提示。
  • 为内部开发平台构建围绕 Claude Code 的自定义包装器。
  • 在复杂、长时间运行的任务中监控并记录 AI 代理的性能。
Claude Code Control 工作原理
  1. 该技能利用 AppleScript 触发 Terminal.app,并在目标项目目录中初始化一个新的 shell 会话。
  2. 它以编程方式执行 claude code 命令以启动交互式 AI 会话。
  3. 通过系统事件按键模拟将命令发送到终端,确保代理将输入识别为标准用户交互。
  4. 集成的截图逻辑捕获终端窗口的具体坐标,以提供视觉状态验证。
  5. 所有交互都会记录到结构化的会话日志中,从而实现对代理操作的完整回放和审计。

Claude Code Control 配置指南

要在 Openclaw Skills 框架内使用此技能,请确保您正在运行 macOS 并已配置必要的环境。

# 确保已全局安装 Claude Code
npm install -g @anthropic-ai/claude-code

# 授予 Terminal.app 辅助功能权限
# 前往:系统设置 > 隐私与安全性 > 辅助功能

配置包括将模块导入 Node.js 环境,并使用有效的项目路径初始化会话。

Claude Code Control 数据架构与分类体系

该技能组织会话数据和视觉产物,以确保自动化工作流的透明度。

数据点 类型 描述
会话 ID UUID 活动终端窗口的唯一标识符
屏幕截图 文件路径 执行命令后终端窗口状态的 PNG 捕获
会话日志 JSON 发送的命令和执行持续时间的按时间顺序排列的记录
持续时间 整数 代理处理特定命令所花费的毫秒数

Claude Code Control

Control Claude Code programmatically through visible Terminal.app windows on macOS.

How It Works

Uses AppleScript to:

  1. Open Terminal.app and launch claude code in a project directory
  2. Type commands via System Events keystrokes
  3. Capture screenshots of just the Terminal window (not full screen)
  4. Record full sessions with timestamped logs

Requirements

  • macOS
  • Node.js 18+
  • Claude Code installed and authenticated
  • Accessibility permissions for Terminal.app + Script Editor (System Settings → Privacy & Security → Accessibility)

Usage

const cc = require('./index');

// Launch Claude Code visibly
const session = await cc.launch('/path/to/project');

// Send a command (types it + presses Enter)
const result = await cc.send(session, 'write tests for app.py', 30);
// result.screenshot → path to Terminal window screenshot

// Save session recording
await cc.saveSession(session, './recording.json');

// Close
await cc.close(session);

API

Function Description
launch(path, opts?) Open Terminal + start Claude Code. Returns session ID
send(id, command, waitSec?) Type command, wait, screenshot. Returns {screenshot, duration_ms}
verifyScreen(id, desc) Take a verification screenshot
approveSecurity(id) Handle "trust this folder" prompt
handleLogin(id) Send /login command
saveSession(id, path) Save session log to JSON
close(id) / closeAll() Exit Claude Code gracefully
takeScreenshot(path?) Capture Terminal window
focusTerminal() Bring Terminal to front

Pro Features (Coming Soon)

  • ?? Video recording of sessions
  • ?? Multi-agent / multi-terminal orchestration
  • ?? Session analytics
  • ?? Session replay
  • ?? Remote control via SSH