{"product_id":"claude-code-remote-control-diều-khiển-claude-code-từ-ứng-dụng-ben-ngoai","title":"Claude Code Remote Control: Điều khiển Claude Code từ ứng dụng bên ngoài","description":"\n\u003cdiv class=\"video-embed\" style=\"position:relative;padding-bottom:56.25%;height:0;overflow:hidden;border-radius:12px;margin-bottom:2rem;\"\u003e\n  \u003ciframe src=\"https:\/\/www.youtube.com\/embed\/Ko7_tC1fMMM\" title=\"Using Claude Code Remote Control\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen style=\"position:absolute;top:0;left:0;width:100%;height:100%;\"\u003e\u003c\/iframe\u003e\n\u003c\/div\u003e\n\u003cp\u003e\u003cem\u003eVideo chính thức từ kênh Anthropic — \"Using Claude Code Remote Control\" (2m40s). Hướng dẫn nhanh cách sử dụng Remote Control API để tích hợp Claude Code vào các công cụ khác.\u003c\/em\u003e\u003c\/p\u003e\n\n\u003ch2\u003eRemote Control là gì và tại sao cần dùng?\u003c\/h2\u003e\n\u003cp\u003eMặc định, Claude Code chạy như một CLI tool — bạn gõ lệnh vào terminal và nhận kết quả. Cách làm việc này hiệu quả nhưng có giới hạn: bạn không thể nhúng Claude Code vào một ứng dụng desktop tùy chỉnh, không thể kích hoạt nó từ một pipeline tự động, và không thể xây dựng UI riêng cho team của mình.\u003c\/p\u003e\n\n\u003cp\u003e\u003cstrong\u003eRemote Control API\u003c\/strong\u003e giải quyết chính xác vấn đề này. Nó biến Claude Code thành một server HTTP cục bộ, để bất kỳ ứng dụng nào có thể giao tiếp với nó qua REST API tiêu chuẩn. Thay vì chỉ dùng Claude Code qua terminal, bạn có thể:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003eTạo VS Code extension gọi thẳng Claude Code để review code đang mở\u003c\/li\u003e\n  \u003cli\u003eXây web app nội bộ cho team dùng chung một phiên Claude Code\u003c\/li\u003e\n  \u003cli\u003eTích hợp Claude Code vào CI\/CD pipeline để tự động review PR\u003c\/li\u003e\n  \u003cli\u003eKết nối từ JetBrains IDEs, Vim\/Neovim plugins, hay bất kỳ HTTP client nào\u003c\/li\u003e\n  \u003cli\u003eViết automation scripts bằng Python, Go, hay ngôn ngữ bất kỳ\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch2\u003eCách khởi động Claude Code ở chế độ Remote Control\u003c\/h2\u003e\n\u003cp\u003eĐể bật Remote Control, bạn khởi động Claude Code với flag \u003ccode\u003e--remote-control\u003c\/code\u003e:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003e# Khởi động với port mặc định (thường là 3000)\nclaude --remote-control\n\n# Chỉ định port cụ thể\nclaude --remote-control --port 4000\n\n# Cho phép kết nối từ network (cẩn thận với bảo mật)\nclaude --remote-control --host 0.0.0.0 --port 4000\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003cp\u003eSau khi khởi động, Claude Code sẽ in ra địa chỉ server, ví dụ \u003ccode\u003ehttp:\/\/localhost:3000\u003c\/code\u003e. Từ đây, bạn có thể gọi API từ bất kỳ ứng dụng nào.\u003c\/p\u003e\n\n\u003ch2\u003eCác endpoint chính của Remote Control API\u003c\/h2\u003e\n\n\u003ch3\u003e1. Tạo session mới\u003c\/h3\u003e\n\u003cp\u003eSession là một phiên làm việc với ngữ cảnh riêng biệt. Mỗi session có conversation history độc lập.\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003ePOST http:\/\/localhost:3000\/sessions\n\nResponse:\n{\n  \"session_id\": \"sess_abc123xyz\",\n  \"created_at\": \"2026-03-26T10:00:00Z\",\n  \"status\": \"active\"\n}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch3\u003e2. Gửi tin nhắn\u003c\/h3\u003e\n\u003cp\u003eĐây là endpoint quan trọng nhất — gửi yêu cầu đến Claude Code và nhận phản hồi.\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003ePOST http:\/\/localhost:3000\/sessions\/{session_id}\/messages\n\nBody:\n{\n  \"message\": \"Review file auth.js và tìm lỗi bảo mật\",\n  \"context\": {\n    \"working_directory\": \"\/Users\/jimmy\/my-project\",\n    \"files\": [\"src\/auth.js\"]\n  }\n}\n\nResponse:\n{\n  \"message_id\": \"msg_xyz789\",\n  \"status\": \"processing\",\n  \"response\": null  \/\/ polling hoặc dùng streaming\n}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch3\u003e3. Lấy lịch sử conversation\u003c\/h3\u003e\n\u003cpre\u003e\u003ccode\u003eGET http:\/\/localhost:3000\/sessions\/{session_id}\/messages\n\nResponse:\n{\n  \"session_id\": \"sess_abc123xyz\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Review file auth.js và tìm lỗi bảo mật\",\n      \"timestamp\": \"2026-03-26T10:01:00Z\"\n    },\n    {\n      \"role\": \"assistant\",\n      \"content\": \"Tôi đã phân tích auth.js và tìm thấy 3 vấn đề...\",\n      \"timestamp\": \"2026-03-26T10:01:05Z\"\n    }\n  ]\n}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch3\u003e4. Lắng nghe updates theo thời gian thực\u003c\/h3\u003e\n\u003cp\u003eVới các tác vụ dài, bạn có thể dùng Server-Sent Events để nhận kết quả stream:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003eGET http:\/\/localhost:3000\/sessions\/{session_id}\/stream\n\n\/\/ JavaScript client\nconst eventSource = new EventSource(\n  'http:\/\/localhost:3000\/sessions\/sess_abc123xyz\/stream'\n);\n\neventSource.onmessage = (event) =\u0026gt; {\n  const data = JSON.parse(event.data);\n  if (data.type === 'token') {\n    process.stdout.write(data.content);\n  } else if (data.type === 'done') {\n    console.log('\\nHoàn thành!');\n    eventSource.close();\n  }\n};\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eVí dụ thực tế: VS Code Extension đơn giản\u003c\/h2\u003e\n\u003cp\u003eĐây là ví dụ minh họa cách một VS Code extension có thể gọi Claude Code qua Remote Control:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003e\/\/ extension.ts (simplified)\nimport * as vscode from 'vscode';\nimport fetch from 'node-fetch';\n\nconst CLAUDE_REMOTE = 'http:\/\/localhost:3000';\nlet sessionId: string | null = null;\n\nasync function getOrCreateSession(): Promise\u0026lt;string\u0026gt; {\n  if (sessionId) return sessionId;\n\n  const res = await fetch(`${CLAUDE_REMOTE}\/sessions`, {\n    method: 'POST',\n    headers: { 'Content-Type': 'application\/json' }\n  });\n  const data = await res.json();\n  sessionId = data.session_id;\n  return sessionId;\n}\n\nexport async function reviewCurrentFile() {\n  const editor = vscode.window.activeTextEditor;\n  if (!editor) return;\n\n  const code = editor.document.getText();\n  const filename = editor.document.fileName;\n  const sid = await getOrCreateSession();\n\n  const res = await fetch(\n    `${CLAUDE_REMOTE}\/sessions\/${sid}\/messages`,\n    {\n      method: 'POST',\n      headers: { 'Content-Type': 'application\/json' },\n      body: JSON.stringify({\n        message: `Review đoạn code sau và cho biết có vấn đề gì:\n\nFilename: ${filename}\n\\`\\`\\`\n${code}\n\\`\\`\\``\n      })\n    }\n  );\n\n  const result = await res.json();\n  \/\/ Hiển thị kết quả trong panel VS Code\n  vscode.window.showInformationMessage(result.response);\n}\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eVí dụ thực tế: Python automation script\u003c\/h2\u003e\n\u003cp\u003eScript Python review toàn bộ repository trước khi deploy:\u003c\/p\u003e\n\n\u003cpre\u003e\u003ccode\u003eimport requests\nimport os\nimport glob\n\nCLAUDE_REMOTE = \"http:\/\/localhost:3000\"\n\ndef create_session():\n    resp = requests.post(f\"{CLAUDE_REMOTE}\/sessions\")\n    return resp.json()[\"session_id\"]\n\ndef send_message(session_id, message):\n    resp = requests.post(\n        f\"{CLAUDE_REMOTE}\/sessions\/{session_id}\/messages\",\n        json={\"message\": message}\n    )\n    return resp.json()\n\ndef review_for_deployment(project_dir):\n    sid = create_session()\n\n    # Lấy danh sách files thay đổi từ git\n    changed_files = os.popen(\n        f\"git -C {project_dir} diff --name-only HEAD~1\"\n    ).read().strip().split(\"\\n\")\n\n    js_files = [f for f in changed_files if f.endswith('.js')]\n\n    if not js_files:\n        print(\"Không có file JS nào thay đổi.\")\n        return\n\n    print(f\"Đang review {len(js_files)} files...\")\n\n    result = send_message(sid, f\"\"\"\nTôi cần deploy, hãy review các files sau và báo cáo nếu có:\n1. Lỗi bảo mật nghiêm trọng\n2. Bug logic có thể gây crash\n3. Performance issues\n\nFiles cần review: {', '.join(js_files)}\nWorking directory: {project_dir}\n    \"\"\")\n\n    print(\"\\n=== KẾT QUẢ REVIEW ===\")\n    print(result.get(\"response\", \"Không có phản hồi\"))\n\nif __name__ == \"__main__\":\n    review_for_deployment(\"\/Users\/jimmy\/my-project\")\u003c\/code\u003e\u003c\/pre\u003e\n\n\u003ch2\u003eBảo mật khi dùng Remote Control\u003c\/h2\u003e\n\u003cp\u003eVì Remote Control mở một HTTP server, cần chú ý một số điểm bảo mật:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eChỉ bind localhost:\u003c\/strong\u003e Mặc định server chỉ lắng nghe \u003ccode\u003e127.0.0.1\u003c\/code\u003e, không expose ra network. Đừng dùng \u003ccode\u003e--host 0.0.0.0\u003c\/code\u003e trừ khi thực sự cần.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAPI key authentication:\u003c\/strong\u003e Nếu cần expose ra network nội bộ, cấu hình API key trong header \u003ccode\u003eAuthorization: Bearer YOUR_KEY\u003c\/code\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eKhông để server chạy nền khi không dùng:\u003c\/strong\u003e Tắt Claude Code khi xong việc để giải phóng port.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGiới hạn working directory:\u003c\/strong\u003e Remote Control chỉ truy cập được files trong working directory đã cấu hình, không phải toàn bộ filesystem.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch2\u003eUse case phù hợp nhất\u003c\/h2\u003e\n\u003cp\u003eRemote Control phù hợp nhất cho:\u003c\/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTeam tools:\u003c\/strong\u003e Xây internal tool để cả team cùng dùng một instance Claude Code có ngữ cảnh project\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eIDE plugins:\u003c\/strong\u003e Tích hợp sâu hơn vào workflow coding mà không cần chuyển sang terminal\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCI\/CD automation:\u003c\/strong\u003e Tự động review code trong pipeline không cần interaction thủ công\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCustom dashboards:\u003c\/strong\u003e Tạo web UI đẹp hơn terminal cho những người không quen CLI\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003cp\u003eNếu bạn chỉ dùng Claude Code cá nhân qua terminal, Remote Control không mang lại nhiều giá trị. Nhưng khi cần \u003cem\u003etích hợp\u003c\/em\u003e hoặc \u003cem\u003echia sẻ\u003c\/em\u003e Claude Code với người khác hay với hệ thống khác, đây là tính năng không thể thiếu.\u003c\/p\u003e\n","brand":"Minh Tuấn","offers":[{"title":"Default Title","offer_id":47722600038612,"sku":null,"price":0.0,"currency_code":"VND","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0821\/0264\/9044\/files\/claude-code-remote-control-di_u-khi_n-claude-code-t_-_ng-d_ng-ben-ngoai.jpg?v=1774526748","url":"https:\/\/claude.vn\/products\/claude-code-remote-control-di%e1%bb%81u-khi%e1%bb%83n-claude-code-t%e1%bb%ab-%e1%bb%a9ng-d%e1%bb%a5ng-ben-ngoai","provider":"CLAUDE.VN","version":"1.0","type":"link"}