2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ついにCodeRabbit CLIが登場しました!

Posted at

CodeRabbitは、AIコードレビューサービスです。GitHubやGitLabと連携し、プルリクエストに対して自動的にレビューを実行します。開発者はCodeRabbitからの指摘を確認して修正を行い(修正をCodeRabbitにやってもらうこともできます)、追加でコミットします。

本日(2025/09/17)、CodeRabbit CLIがリリースされました。CodeRabbit CLIは、ターミナルから直接コードレビューを実行できるツールです。最近ではCodexやClaude Codeのように、CLIベースのAIコーディングエージェントが出てきていますが、CodeRabbit CLIはこれらのエージェントと組み合わせて使うことができます。

今回は、このCodeRabbit CLIの使い方を解説します。

CodeRabbit CLIのインストール

インストールは下記のコマンドにて行います。

curl -fsSL https://cli.coderabbit.ai/install.sh | sh
# または
curl -fsSL https://cli.coderabbit.ai/install.sh | bash

WSL2環境の場合、エラーになる可能性があります。その場合はbashを使ってください。

インストールが完了したら、coderabbitコマンドが使えるようになります。

% coderabbit --help
Usage: coderabbit [options] [command]

CodeRabbit CLI for code review

Options:
  -V, --version            output the version number
  --plain                  Output in plain text format (non-interactive)
  --prompt-only            Show only AI agent prompts (implies --plain)
  -t, --type <type>        Review type: all, committed, uncommitted (default: "all")
  -c, --config <files...>  Additional instructions for CodeRabbit AI (e.g., claude.md, coderabbit.yaml)
  --base <branch>          Base branch for comparison
  --base-commit <commit>   Base commit on current branch for comparison
  --cwd <path>             Working directory path
  --no-color               Disable colored output
  -h, --help               display help for command

Commands:
  auth                     Authentication commands
  review [options]         AI-driven code reviews with interactive or plain text output

認証

まず、 coderabbit auth で認証を行います。ブラウザが立ち上がるので、CodeRabbitのアカウントでログイン&認証を行います。

coderabbit auth

image.png

生成されたトークンを貼り付けて、認証完了です。

CodeRabbit CLIの使い方(インクリメンタル)

認証が終わったら、コードレビューを行うリポジトリで coderabbit コマンドを実行します。

coderabbit

そうすると、こんなUIが表示されるので、エンターキーでレビューを開始します。

image.png

レビュー中…。

スクリーンショット 2025-09-17 18.01.48.png

レビューが完了すると、指摘事項が表示されます。

CodeRabbit CLIの使い方(AIコーディングエージェントとの連携)

実際の運用では、こちらの方が実用的かと思います。CodexやClaude CodeのようなAIコーディングエージェントと組み合わせた使い方です。

(実装に関する説明)
実装したら `coderabbit --prompt-only` をバックグラウンドで実行し、必要なだけ実行させ、検出された問題を修正してください。

そうすると、AIコーディングエージェントが coderabbit --prompt-only をバックグラウンドで実行し、結果を読み取ってくれます。--prompt-only オプションを付けると、AIエージェントに必要な内容だけ出力します。

実際に試したところ、以下のような形で進んでいました。

  Use Claude to help with file analysis, editing, bash commands and git
  Be as specific as you would with another engineer for the best results
  ✔ Run /terminal-setup to set up terminal integration

> (実装内容)

  ・gitブランチを作成して
  ・テストも作成して
  ・実装したら、 `coderabbit --prompt-only` を実行し、必要なだけ長時間(バックグラウンド)で実行し、レビューの指摘に沿って、修正を行ってください。

⏺ コーディングを行います。まず、現在のコードベースを確認してから実装を進めます。

⏺ Search(pattern: "**/*.java")
  ⎿  Found 6 files (ctrl+o to expand)

⏺ Read(src/path/to/mail.java)
  ⎿  Read 35 lines (ctrl+o to expand)

⏺ Read(src/path/to/request.java)
  ⎿  Read 70 lines (ctrl+o to expand)

⏺ Bash(git checkout -b feature/attachments-support)
  ⎿  use v24.0.2                                           
     Switched to a new branch 'feature/attachments-support'

⏺ 設計を行います:

  添付ファイル機能の実装方針:
  1. Mailクラスにattachmentsフィールド(List<String>)を追加
  2. RequestのsendメソッドをMultipartEntity対応に修正
  3. ファイルパスからファイルを読み込んでマルチパートリクエストに追加

(コーディングの差分)

⏺ テストのコンパイルと実行が成功しました!進捗を更新します:
  :
⏺ Bash(coderabbit --prompt-only)
  ⎿  Running in the background (down arrow to manage)

⏺ BashOutput(Reading shell output)
  ⎿  use v24.0.2                                     
     Starting CodeRabbit review in plain text mode...

     Connecting to review service

⏺ レビューの完了を待ちます:
  :
⏺ BashOutput(Reading shell output)
  ⎿  use v24.0.2                                     
     Starting CodeRabbit review in plain text mode...
     … +19 lines (ctrl+o to expand)

⏺ CodeRabbitのレビューが完了しました。指摘事項に対応します:

⏺ レビューの指摘に従って、try-with-resourcesを使用してリソース管理を改善します:

⏺ Update(src/path/to/request.java)
  ⎿  Updated src/path/to/request.java with 6 additions and 8 removals
       33        String result = "";
       34        ObjectMapper mapper = new ObjectMapper();
       35        mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
       36 -      try {
       37 -        HttpPost httpPost = new HttpPost(url);
       38 -        CloseableHttpClient client = HttpClients.createDefault();
       39 -        CloseableHttpResponse response;
       36    
       37 +      HttpPost httpPost = new HttpPost(url);
       38 +  
       39 +      try (CloseableHttpClient client = HttpClients.createDefault()) {

⏺ Bash(gradle test)
  ⎿  use v24.0.2                   

     > Task :compileJava
     … +26 lines (ctrl+o to expand)

⏺ テストが成功しました。変更をコミットします:

⏺ 完了しました

  添付ファイル機能の実装が完了しました:

  実装内容

  1. Mailクラス:
    - attachmentsフィールド(List<String>)を追加
    - addAttachment(String filePath)メソッドを実装
  2. Requestクラス:
    - マルチパート対応に修正
    - 添付ファイルがある場合はMultipartEntityを使用
    - CodeRabbitの指摘に従い、try-with-resourcesでリソース管理を改善
  3. テスト作成:
    - 包括的なテストケースを実装
    - ファイル追加、複数ファイル、nullチェック等をカバー

  ブランチ

  feature/attachments-supportに実装済み

  CodeRabbitレビュー結果

  - リソース管理の問題を指摘→修正済み
  - try-with-resourcesで適切にクローズ処理を実装

  全てのテストが正常に動作しています。

このフローの場合、CodeRabbitの指摘はすべて受け入れる形になっています。CodeRabbitの指摘がすべて正しい訳ではないので、自動適用のフローが難しい場合もあるかと思います。その場合には、 coderabbit --plain を実行しつつ、まず指摘をリストアップした上で検討、適用するという流れが良さそうです。

個人的には、一旦CodeRabbitのベストプラクティスに基づく指摘は受け入れておき、そこから自分の判断で修正を加える形が良いのではないかと思います。セキュリティやパフォーマンスなどの重要な指摘を見逃すリスクが減るためです。

コマンドリファレンス

コマンド 説明
coderabbit コードレビューの実行(デフォルトは対話モード)
coderabbit --plain 詳細なフィードバックをプレーンテキスト形式で出力
coderabbit --prompt-only AIエージェントに最適化された最小限の出力を表示
coderabbit auth 認証コマンド
coderabbit review インタラクティブまたはプレーンテキスト出力によるAI主導のコードレビュー
cr すべてのcoderabbitコマンドの短い別名

追加オプション

オプション 説明
-t, --type <type> レビューの種類:すべて、コミット済み、未コミット(デフォルト:"すべて")
-c, --config <files...> CodeRabbit AI用の追加説明書(claude.md、coderabbit.yamlなど)
--base <branch> 比較のためのベースブランチ
--base-commit <commit> 比較のために現在のブランチをベースとするコミット
--cwd <path> 作業ディレクトリパス
--no-color カラー出力を無効にする

注意点

CLIのレビューと、従来のPRレビューの内容は異なる可能性があります。CLIは、即時フィードバックに最適化されており、PRレビューは組織のコンテキストや、より広範なコードベースの理解に基づいています。

まとめ

CodeRabbit CLIは、AIコーディングエージェントと連携できる最良なコードレビュー体験を提供します。ローカルでの実行はもちろんのこと、CI/CDパイプラインへの組み込みも可能です。

ぜひCodeRabbit CLIを試してみてください。質問やフィードバックは、CodeRabbitのDiscordの #japanese チャンネルにぜひ!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?