🚀 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文件。
致謝