@coderabbitai/config
v5.4.0
Published
Programmatic (TypeScript) authoring SDK for CodeRabbit configuration.
Downloads
554,173
Readme
@coderabbitai/config
Typed, programmatic authoring for CodeRabbit
configuration — write your .coderabbit.config.ts in TypeScript instead of
.coderabbit.yaml, with editor autocomplete and author-time type-checking.
A committed .coderabbit.yaml always takes precedence over
.coderabbit.config.ts.
Install
npm install --save-dev @coderabbitai/configUsage
Create a .coderabbit.config.ts at the root of your repository:
import { defineConfig } from "@coderabbitai/config"
export default defineConfig({
language: "en-US",
reviews: { profile: "chill" },
})defineConfig also accepts a factory that receives repository / organization /
pull-request and invocation context, so your config can adapt to where, what,
and how it runs — something a static YAML file cannot do:
import { defineConfig } from "@coderabbitai/config"
export default defineConfig(ctx => ({
reviews: {
// Keep local CLI reviews focused; use normal policy in the repository.
profile: ctx.invocation.source === "cli" ? "chill" : "assertive",
},
}))ctx.invocation.source is "cli" for a local coderabbit review and
"review" for reviews initiated through an SCM provider or another review
client.
For pull requests and merge requests, ctx.pr.authorGroups exposes the
author's provider groups without putting provider-specific objects in your
config:
import { defineConfig } from "@coderabbitai/config"
export default defineConfig(ctx => {
const groups =
ctx.pr?.authorGroups.status === "resolved" ? ctx.pr.authorGroups.groups : []
const isUsaPlatform = groups.some(
group => group.fullPath === "acme/platform-usa",
)
return {
language: isUsaPlatform ? "en-US" : "ko-KR",
}
})Each group has a provider-stable id, a short slug, and a provider-qualified
fullPath. status is:
"resolved": the provider returned the complete visible membership list;groupsmay be empty."unavailable": permissions, timeout, provider failure, or a safety bound prevented a complete lookup.groupsis empty and must not be treated as proof that the author belongs to no groups."unsupported": the current provider or invocation has no author-group resolver. Local CLI reviews currently use this status."stale": reserved for a future cached membership result.
GitHub and GitHub Enterprise resolve organization teams. GitLab.com and self-managed GitLab resolve direct group memberships visible to CodeRabbit; GitLab's membership API does not include inherited or shared group membership.
Repository topics and GitHub custom properties are available under ctx.repo:
import { defineConfig } from "@coderabbitai/config"
export default defineConfig(ctx => {
const topics =
ctx.repo.topics.status === "resolved" ? ctx.repo.topics.names : []
const properties =
ctx.repo.customProperties.status === "resolved"
? ctx.repo.customProperties.values
: {}
const isCriticalService =
topics.includes("critical") && properties.repo_type === "service"
return {
reviews: {
profile: isCriticalService ? "assertive" : "chill",
},
}
})topics.names is a sorted list. customProperties.values is keyed by the
property name; each value is a string, a string array, or null. Both objects
use the same resolved, unavailable, unsupported, and reserved stale
statuses as author groups. A resolved collection may be empty. An unavailable
collection is unknown and must not be treated as authoritatively empty.
GitHub supplies topics and custom properties. Other providers and local CLI
reviews currently report unsupported; GitHub failures and unsupported GitHub
Enterprise versions report unavailable. These lookups use the installation's
existing metadata read permission and run only when a TypeScript config is
evaluated.
ctx.pr.changedFiles exposes the complete set of repository-relative paths in
the pull request or merge request diff. This makes it possible to select review
policy based on the areas a change touches:
import { defineConfig } from "@coderabbitai/config"
export default defineConfig(ctx => {
const paths =
ctx.pr?.changedFiles.status === "resolved" ? ctx.pr.changedFiles.paths : []
const touchesInfrastructure = paths.some(
path => path.startsWith("terraform/") || path.endsWith(".tf"),
)
return {
reviews: {
profile: touchesInfrastructure ? "assertive" : "chill",
},
}
})The status is "resolved" only when CodeRabbit has the complete path list.
Provider errors, timeouts, revision changes, or safety limits produce
"unavailable" with an empty list; platforms without a complete inventory
produce "unsupported". Never interpret either status as proof that no files
changed. Renames include both the previous and current path so policies can
detect files moving into or out of a protected area.
Composing configs
mergeConfig deep-merges fragments (objects merge, arrays concatenate, later
scalars win), and includeRemote pulls a shared fragment from your
organization's coderabbit repository by default:
import { defineConfig, mergeConfig, includeRemote } from "@coderabbitai/config"
const orgBase = includeRemote({ path: "base.ts" })
const platformBase = includeRemote({
repo: "acme/platform-config",
path: "reviews/base.ts",
ref: "v1",
})
export default defineConfig(
mergeConfig(orgBase, platformBase, { reviews: { profile: "assertive" } }),
)YAML fragments
A config can import YAML fragments, such as existing .coderabbit.yaml
sections. To type those imports in your editor, reference the yaml subpath
once:
/// <reference types="@coderabbitai/config/yaml" />
import { defineConfig, mergeConfig } from "@coderabbitai/config"
import pathRules from "./coderabbit/path-rules.yaml"
export default defineConfig(
mergeConfig(pathRules, { reviews: { profile: "chill" } }),
)The reference types every .yaml and .yml import in the TypeScript program
as CodeRabbitConfig, so skip it if your project already declares types for
YAML modules. CodeRabbit validates the fragment's contents when it evaluates
your config.
How it works
Your config is evaluated by CodeRabbit in an isolated, network-free sandbox and
validated against the same schema a .coderabbit.yaml uses. This package is
author-time only — it gives you types and autocomplete; the actual
evaluation happens server-side, so your config works whether or not the package
is installed. Installing it just makes your editor and CI aware of the config
shape.
API
defineConfig(config | (ctx) => config)— typed identity for your config.mergeConfig(...fragments)— deep-merge fragments (arrays concatenate).includeRemote({ repo?, path, ref? })— include a shared file.repouses the provider-native repository format and defaults to your org'scoderabbitrepository.@coderabbitai/config/yaml— ambient types for.yamland.ymlimports.- Types:
CodeRabbitConfig,CodeRabbitContext,CodeRabbitAuthorGroup,CodeRabbitAuthorGroupsContext,CodeRabbitAuthorGroupsStatus,CodeRabbitContextResolutionStatus,CodeRabbitChangedFilesContext,CodeRabbitChangedFilesStatus,CodeRabbitRepositoryContext,CodeRabbitRepositoryTopicsContext,CodeRabbitRepositoryCustomPropertiesContext,CodeRabbitRepositoryCustomPropertyValue,CodeRabbitPullRequestContext,CodeRabbitInvocationContext,CodeRabbitInvocationSource,ResolvedCodeRabbitContext,RemoteInclude.
Repository configuration directory
Hosted GitHub Cloud reviews support automatic V2 directory loading with cascading
.coderabbit/instructions/ and .coderabbit/pre-merge-checks/ Markdown files,
including repositories without a YAML or TypeScript configuration entry. Each
file requires YAML front matter with a stable id. Files apply within their
containing directory and can narrow that scope with paths and exclude.
Omitted report uses a GitHub check run; set report: coderabbit for the native
walkthrough report.
Review admission and preparation use the YAML or TypeScript entry configuration.
The detailed review loads directory context inside proReview(), after admission,
from the existing trusted checkout or snapshot at the selected document commit,
or a complete private bundle cached for that exact commit. Settings needed before
that point must stay in the entry configuration. A directory-only change can
select PR documents without changing the YAML or TypeScript source.
Document loading never starts a clone solely for discovery, calls GitHub tree or Contents APIs for directory discovery, or fetches missing Git objects. Immutable bundles do not require ETag revalidation. Remote configuration fragments do not add discovery roots.
A missing or incomplete bundle is unknown, not an empty directory. If neither the selected local source nor a complete cached bundle is available, the activated directory load fails explicitly. Reviews, commands and QA admission must not omit instructions or clear checks on that basis. A skipped detailed review can still run YAML checks, but cannot auto-approve while its directory context is unread. A validated empty bundle proves that the selected commit has no documents in the requested namespaces.
Repository V3 on GitHub Cloud
Hosted reviews of GitHub Cloud repositories opt in with numeric version: 3
in the primary .coderabbit.yaml, .coderabbit.yml, or .coderabbit.config.ts.
CodeRabbitConfigV3 and the defineConfig / mergeConfig overloads support
the V3 layout. CodeRabbitConfig continues to describe V2. YAML takes
precedence over TypeScript. Self-hosted and central V3 entry files are outside
the hosted repository rollout.
The separate internal pilot for repository-defined QA agents uses platform
reporting when report is omitted and retains the QA run comment.
V3 uses only its canonical field names. Put approval policy under
reviews.behavior.auto_approvals, chat permissions under reviews.output.chat,
and tone, art and fortune settings under fun. Runtime validation rejects
unknown fields, misspellings and retired aliases; it does not translate V2 or
earlier-preview spellings. V2 keeps its existing compatibility behavior.
Only the number 3 selects V3. Omitting version keeps V2, and an invalid V3
document is not reinterpreted as V2. Use the migration tool to convert a V2
configuration before changing its version.
import { defineConfig, mergeConfig } from "@coderabbitai/config"
export default defineConfig(ctx =>
mergeConfig(
{ version: 3, reviews: { behavior: { profile: "chill" } } },
{ fun: { in_progress_fortune: ctx.invocation.source === "review" } },
),
)Start each V3 mergeConfig call with a V3 base, including nested calls:
mergeConfig({ version: 3 }, basePolicy, repositoryPolicy). A call with only versionless
fragments retains the V2 contract; an enclosing V3 merge cannot change how an
inner call has already combined its fragments.
For an admitted primary repository, directory documents use the selected immutable
configuration revision unless the trusted PR source policy admits a directory-only
change from the PR head. Imported fragments do not create additional directory
discovery roots. Use
includeRemote<CodeRabbitConfigV3Fragment>({ path: "base.ts" }) to type a remote
V3 fragment; calls without a type argument retain their V2 return type. The
offline V2 migration CLI
still reads explicit YAML inputs; it does not execute TypeScript factories or
attest their inherited source graph. Use --repository-root with the local Git
root to qualify whether existing directory inputs are absent. Without that
inventory, or when it finds instructions, checks, QA definitions, or namespace
links, the YAML-only plan remains a draft and cannot qualify source replacement.
It makes no clone, provider, or database call.
