Generate improvements
This feature is available exclusively as part of the Pro plan and is not included in the Lite plan. Please refer to ourpricing page for more information about our plans and features.
This page is about using CodeRabbit to generate improvements to code under review.
For a general overview of performing code reviews with CodeRabbit, seeReview pull requests.
Overview of CodeRabbit code generation
This feature is available only on GitHub.
You can request CodeRabbit to generate improvements to a branch that it is currently reviewing.
To do this, write out your request prompt in a comment addressed to@coderabbitai,such as with the following examples:
@coderabbitai Please implement the changes you suggested in your code review.@coderabbitai Add input validation with proper error messages to these new functions.@coderabbitai Break this large function into smaller, more focused methods.
In addition to this kind of free-form request, you can also give CodeRabbit keyword-basedcommands for common code-generation requests, as described inCode generation commands.This includes theplan keyword, which acts as shorthand for the first prompt on theprevious list.
After you give it a code-generation prompt or command, CodeRabbit delivers its suggested improvements by taking these steps:
- CodeRabbit posts a comment or two to the pull request, detailing its improvement plans.
- CodeRabbit publishes a new branch, based on the open pull request's branch, to the remote repository.
- CodeRabbit opens a new pull request based on this new branch, and links to it from the original pull request.
CodeRabbit doesn't make any further changes to the new branch or to the new pull requestafter it creates them. From that point on, it's fully up to you what to do with the new, suggested-change branch.
The best practice is to effectively take ownership of the new branch for yourself,deciding whether it's worth merging into the original pull request branch, and makingany further updates you'd like to make first. You can use comments in the new branchto ask CodeRabbit to explain its changes, if needed, or to otherwise converse withCodeRabbit about the suggested improvements.
Because it's just an ordinary Git branch, the presence of the suggested-change branchdoesn't block the ongoing code review in the original pull request branch. You arefree to merge, defer, or close the suggested-change pull request that CodeRabbit made, using any method or timing that fitsyour workflow.
Code generation commands
This section lists short commands that you can give CodeRabbit to have it accomplishcommon code-generation tasks. For more complex tasks, you can instead write out fullprompts, as described in the previous section.
For a complete CodeRabbit command reference, seeCode review command reference.
Generate inline documentation
To have CodeRabbit generate missing documentation for function code added bythe pull request, post the following comment to thepull request:
@coderabbitai generate docstrings
For more information about how CodeRabbit can generate inline documentation, includingthe Git platforms and programming languages that this feature supports, seeDocstrings.
Generate solutions to open review comments
To have CodeRabbit generate and add a new repository branch with code improvementsthat try to address its own code review comments, post the following comment to thepull request:
@coderabbitai plan
Using this keyword is essentially shorthand for writing out a prompt like the following:
@coderabbitai Implement the changes that you suggested and apply them to this pull request.
If you want to give CodeRabbit more specific implement instructions other than a generalrequest to implement its own suggestions, then you can write out those instructionsas a full prompt, instead of using the one-wordplan command.