🎮

Claude CodeにCursorを操作してもらう

に公開

Claude CodeにCursorを操作させる方法を見つけたので、その方法を紹介します。
まずは、以下の動画を見てください。

このように、Claude CodeにCursorでファイルを開かせることができます。

Claude Codeに cursor コマンドを実行させる

cursor コマンドは、ターミナルから cursor . のように実行するとCursorがカレントディレクトリで開くというようにCursorをCLIから操作できるコマンドです。
このコマンドをClaude Codeに実行させることで、Cursorにファイルを開かせることができます。

cursor コマンドの仕組み

cursorコマンドを使うと以下のような操作が可能です。

# ファイルを開く
cursor file_path

# 特定の行にカーソルがある状態で開く
cursor --goto file:line

# 新しいウィンドウで開く
cursor --new-window file

Claude CodeをCursor内のターミナルで実行していると、cursor コマンドでそのフォルダ内のファイルを開くと操作中のウィンドウのタブとして開きます。

~/.claude/CLAUDE.md での設定

現時点では私は ~/.claude/CLAUDE.md に以下のように記述することで、Claude Codeに cursor コマンドを実行するように指示しています。

### 4.2 Cursor Integration
- **Note**: The following cursor commands are only available when Claude Code is running inside Cursor's integrated terminal
- **IMPORTANT**: When Masato asks to find files, specific lines, or wants to see code in the editor, ALWAYS use the cursor command to open them
- Use `cursor` command to open files in Cursor IDE when you need to highlight specific code or files for review
- Useful cursor command options:
  - `cursor file_path` - Open file in existing window
  - `cursor --goto file:line` - Open file at specific line number (use --goto option)
  - `cursor -n file` - Open file in new window
  - `cursor -d file1 file2` - Open diff comparison
- Example scenarios where cursor command should be used:
  - "そのファイルを開いて" → Use `cursor file_path`
  - "そのあたりを開いて" → Use `cursor --goto file:line`
  - "この関数を見せて" → Find the function and open with `cursor --goto file:line`
  - "エラーが出ている箇所を開いて" → Open the error location with cursor
- When referencing important files or code sections, consider using cursor command to make it easier for Masato to review
- If running from external terminal (Ghostty, etc.), cursor commands will open files in a separate Cursor window

完全な ~/.claude/CLAUDE.mdhttps://github.com/smasato/dotfiles/blob/b6832a38bc898944800b4939c69c264d6d9c58c3/dot_claude/CLAUDE.md にあります。

何がうれしいのか

冒頭の動画のように、Claude CodeにCursorを操作させることで、コードの調査やレビューが快適になる可能性があります。
Cursor(VS Code)の既存の機能を使うことでもこのようなことはできますが、Claude CodeにCursorを操作させることができると新しいClaude Codeの使い方が見つかるかもしれません。

まとめ

Claude CodeとCursorの連携は、cursorコマンドと~/.claude/CLAUDE.mdを活用することで実現できます。

  • ターミナルベースのClaude Codeから、GUIのCursorを操作
  • 自然言語での指示を、適切な cursor コマンドの実行に変換

が可能になります。
Claude CodeをCursor(VS Code)で使っている方は、ぜひ試してみてください。

Discussion