@coderabbitai/config SDK. To write a configuration, start with TypeScript configuration.
Context object
When the default export is a function, CodeRabbit calls it with a context object that describes the review. CodeRabbit computes the object on the server and injects it into the sandbox. It holds metadata only: no tokens, credentials or secrets. CodeRabbit looks up the context only while it evaluates a TypeScript configuration. The lookups use the permissions CodeRabbit already has to read repository metadata. Your configuration code never receives credentials and canât make network requests. A field that CodeRabbit canât resolve degrades, as described in each table, instead of failing the configuration.Invocation and platform
Repository
Pull request
ctx.pr is null when the event has no pull request, or when CodeRabbit couldnât read it. CodeRabbit resolves it for every event that starts a review, not only for a new pull request: comment commands such as @coderabbitai review, label events and repeated reviews included.
Author groups
Each entry ofctx.pr.authorGroups.groups has three fields. The list is sorted by fullPath.
What the list holds depends on the platform:
- GitHub and GitHub Enterprise Server: the teams in the repositoryâs organization that the author belongs to and CodeRabbit can see.
- GitLab: the authorâs direct group memberships under the repositoryâs top-level group. Inherited and shared memberships arenât included.
- Other platforms, CLI and IDE reviews:
statusisunsupported.
Changed files
ctx.pr.changedFiles.paths lists every file the pull request changes, as paths relative to the repository root. For a renamed file, it holds both the old and the new path, so a rule canât miss a file that moves into or out of a protected directory. paths is empty unless status is resolved. This field never reports stale.
Status values
authorGroups, changedFiles, topics and customProperties each carry a status.
Use the values for a decision only when
status is resolved, and decide what an unknown result should mean for your rule.
API reference
The SDK is optional and only adds types; see Install the SDK. During evaluation, CodeRabbit supplies its owndefineConfig, mergeConfig and includeRemote, which behave the same.
Functions
Types
Context types
The function you pass todefineConfig receives the full context, where invocation, repo.topics and repo.customProperties are always present, and pr.authorGroups and pr.changedFiles are present whenever ctx.pr isnât null. The exported types are looser, so code that builds a context object by hand keeps compiling:
CodeRabbitContextkeeps all five fields optional.ResolvedCodeRabbitContextrequiresinvocation. The four lookup fields stay optional.
?., or pass the helper only the values it needs.
Whatâs next
TypeScript configuration
Write a configuration that adapts to each pull request.
Validate and test a change
Type-check the file in CI and test it before you merge.
Configuration reference
Look up every setting the configuration object accepts.