Skip to main content
This page lists the context object that CodeRabbit passes to a configuration function, and the functions and types of the @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 of ctx.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: status is unsupported.

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 own defineConfig, mergeConfig and includeRemote, which behave the same.

Functions

Types

Context types

The function you pass to defineConfig 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:
  • CodeRabbitContext keeps all five fields optional.
  • ResolvedCodeRabbitContext requires invocation. The four lookup fields stay optional.
When you type a helper’s parameter with one of these types, as in the hotfix example, read the optional fields with ?., 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.