🚀 Claude文本编辑器
Claude文本编辑器是一个无缝的文本编辑系统,它通过模型上下文协议(MCP)与Claude桌面应用集成。在macOS系统上,你可以选择任意文本,将其发送给Claude进行编辑,并自动接收编辑后的版本。
🚀 快速开始
在使用Claude文本编辑器之前,你需要完成安装并在Claude桌面应用中进行初始化。
安装
快速安装(推荐)
git clone https://github.com/lucapinello/claude-text-editor.git
cd claude-text-editor
./install.sh
安装脚本会执行以下操作:
- 检查Python/conda/mamba是否安装
- 创建必要的目录
- 根据
environment.yml
设置Python环境
- 安装依赖项(包括MCP)
- 安装
terminal-notifier
以实现桌面通知(如果已安装Homebrew)
- 配置Claude桌面应用
- 将所有文件复制到正确的位置
- 创建默认的提示文件
注意:桌面通知需要安装Homebrew。如果未安装,文本处理完成时你仍会听到音频反馈(玻璃音效)。
在Claude桌面应用中初始化
安装完成后,你需要在Claude桌面应用中初始化Claude文本编辑器:
简单方法初始化Claude文本编辑器
- 安装完成后重启Claude桌面应用。
- 创建一个新的聊天,命名为
claude_text_editor
。
- 复制并粘贴以下消息,然后按回车键:
I'm using the Claude Text Editor MCP server.
CONTINUOUS TEXT EDITOR MONITORING TASK
CORE DIRECTIVE: Monitor and process text files indefinitely without stopping.
OPERATIONAL RULES:
- Run FOREVER until explicitly told to stop
- Work silently - NO status updates, NO explanations
- Only output when actually processing a file (minimal output only)
INFINITE LOOP PROCESS:
- check_edit_queue
- If files exist → get_text_to_edit → edit → save_edited_text
- wait_for_files (30 seconds)
- Return to step 1
OUTPUT MINIMIZATION:
- Process files without commentary
- No logging except essential file processing confirmations
- Maintain silent operation to conserve resources
- Claude会确认工具可用,并开始监控文件。
- 在使用文本编辑器时保持此聊天窗口打开 - Claude会在文件到达时自动处理。
测试设置
echo "This is a test sentance with bad grammer." > ~/.claude_text_editor/inbox/test.txt
cat ~/.claude_text_editor/outbox/test.txt
✨ 主要特性
- 🚀 零摩擦编辑:选择文本 → 右键点击 → “使用Claude编辑” → 获取编辑后的文本
- 📁 基于文件的处理:无超时限制,无需切换焦点
- 🔄 自动队列管理:将文件拖入收件箱,在发件箱获取结果
- 🎯 可定制提示:在
claude_prompt.txt
中定义编辑指令
- 🖥️ 系统级集成:可与任何macOS应用配合使用
- 🔔 桌面通知:文本处理完成时会收到通知
- 📋 自动复制到剪贴板:编辑后的文本会自动复制到剪贴板
- 🤖 由MCP驱动:与Claude桌面应用原生集成
📦 安装指南
前提条件
- macOS(在macOS 14.x上测试)
- 已安装Claude桌面应用
- 可访问终端
- 互联网连接
- Homebrew(可选,但推荐用于桌面通知)
- 从以下地址安装:https://brew.sh
- 或者运行:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装步骤
快速安装(推荐)
git clone https://github.com/lucapinello/claude-text-editor.git
cd claude-text-editor
./install.sh
💻 使用示例
基本工作流程
- 保持Claude桌面应用打开,并激活
claude_text_editor
聊天。
- 使用键盘快捷键(⌥⌘.):
- 选中文本时:处理所选内容
- 未选中文本时:处理剪贴板内容
- Claude自动处理,并将结果保存到
~/.claude_text_editor/outbox/
。
- 获取即时反馈:
- 桌面通知(需要Homebrew + terminal-notifier)
- “玻璃”音效(始终可用)
- 文本自动复制到剪贴板
使用客户端脚本
pbpaste | ~/claude-text-editor/claude_text_client.py
cat myfile.txt | ~/claude-text-editor/claude_text_client.py
echo "Edit this text" | ~/claude-text-editor/claude_text_client.py --timeout 60
echo "Edit this text" | ~/claude-text-editor/claude_text_client.py --no-clipboard
快速命令行函数
将以下内容添加到~/.zshrc
或~/.bashrc
中,以便快速编辑文本:
ce() {
if [ $# -eq 0 ]; then
pbpaste | ~/claude-text-editor/claude_text_client.py
else
printf '%s\n' "$*" | ~/claude-text-editor/claude_text_client.py
fi
}
现在你可以在任何地方快速编辑文本:
ce
ce Fix this sentence that have bad grammer
这两种方法都使用了完整的客户端工作流程,包括通知和剪贴板集成!
自定义编辑指令
编辑~/.claude_text_editor/claude_prompt.txt
以更改Claude处理文本的方式:
Please edit the following text to:
- Make it more formal and professional
- Fix any technical inaccuracies
- Add relevant examples where appropriate
Text to edit:
系统级文本编辑快捷键
安装脚本会设置必要的文件。要启用键盘快捷键:
选项1:导入预制快捷键(最简单)
- 打开快捷指令应用。
- 文件 → 导入或从项目文件夹中拖动
Edit_with_Claude.shortcut
。
- 快捷键已配置好,可以直接使用!
选项2:手动创建快捷键
- 打开快捷指令应用。
- 点击**+**创建新的快捷指令。
- 添加以下操作:
- 接收文本:从“快速操作”中选择
- 运行Shell脚本:
- 外壳:
/bin/bash
- 传递输入:“到标准输入”
- 脚本:
~/claude-text-editor/claude_text_shortcut.sh
- 设置(⚙️):
- ✅ 用作快速操作
- ✅ 服务菜单
- 名称:“使用Claude编辑”
添加键盘快捷键
- 系统设置 → 键盘 → 键盘快捷键 → 服务
- 在“文本”下找到“使用Claude编辑”
- 添加快捷键:⌥⌘.(Option+Command+句点)
现在你可以:
- 选中文本 → ⌥⌘. → Claude处理文本 → 结果复制到剪贴板!
- 未选中文本 → ⌥⌘. → Claude处理剪贴板内容 → 结果复制到剪贴板!
🔧 技术细节
架构
该系统由以下几个组件组成:
- MCP服务器 (
text-editor-server.py
):与Claude桌面应用集成
- 文件监控器:监控
~/.claude_text_editor/inbox/
中的新文件
- 客户端脚本 (
claude_text_client.py
):用于文本编辑的命令行界面
- 包装脚本 (
mcp-server-wrapper.sh
):管理Python环境
文件流程
用户输入 → 收件箱/ → Claude处理 → 发件箱/ → 用户接收输出
📚 详细文档
故障排除
服务器无法连接
- 检查日志:
tail -100 ~/Library/Logs/Claude/mcp-server-text-editor.log
- 验证conda环境:
conda activate claude-text-editor && which python
- 直接测试服务器:
~/claude-text-editor/mcp-server-wrapper.sh
Claude桌面应用中工具不可用
- 确保配置后重启了Claude桌面应用
- 检查配置文件路径是否正确
- 验证包装脚本是否可执行
- 在日志中查找错误消息
权限错误
chmod +x ~/claude-text-editor/mcp-server-wrapper.sh
chmod +x ~/claude-text-editor/claude_text_client.py
找不到Python或模块
- 确保conda在你的shell中正确初始化
- 验证环境是否已激活:
conda activate claude-text-editor
- 检查MCP是否已安装:
pip list | grep mcp
卸载
要从系统中完全移除Claude文本编辑器:
./uninstall.sh
卸载脚本将:
- 删除安装目录
- 删除conda环境(如果使用了)
- 清理Claude桌面应用配置
- 可选地删除数据目录
- 提供手动清理快捷方式的说明
开发
项目结构
~/claude-text-editor/
├── text-editor-server.py # MCP服务器实现
├── mcp-server-wrapper.sh # 环境包装器
├── claude_text_client.py # 命令行客户端
└── ~/.claude_text_editor/
├── inbox/ # 放入文本文件
├── outbox/ # 接收编辑后的文件
└── claude_prompt.txt # 编辑指令
扩展系统
你可以通过以下方式扩展系统:
- 向MCP服务器添加新工具
- 为特定工作流创建额外的客户端脚本
- 通过AppleScript或shell脚本与其他应用集成
📄 许可证
本项目采用MIT许可证,详情请参阅LICENSE文件。
致谢