Skip to content

How to set up CODEOWNERS for documentation

A docs page without an owner gets fixed by whoever notices, which is usually nobody. GitHub's CODEOWNERS file names a team for each docs folder, requests their review on any pull request that edits it, and can make that review required. Set it up in four steps and test it with one pull request.

Updated 5 min read

Step 1. Decide who owns which pages

Match docs to the teams that own the code they describe. The API team owns the API reference, the billing team owns the billing guides, and a docs or developer relations team owns the getting-started path and anything shared.

Name teams, not people. A team survives a person changing roles, and GitHub requests review from the whole team so anyone on it can approve.

Docs pathOwnerWhy
/docs/@acme/docs-teamDefault owner for every page
/docs/api/@acme/api-teamDescribes the API handlers
/docs/billing/@acme/billingDescribes plans and invoices
/README.md@acme/docs-teamFirst page most readers see

Step 2. Write the CODEOWNERS file

Create CODEOWNERS in .github/, at the repository root or in docs/. GitHub looks in that order and uses the first file it finds. Each line is a path pattern followed by one or more owners, written as @user, @org/team or an email address.

Put the broad rule first and the specific rules after it. When several lines match a file, the last matching line wins, so a catch-all at the bottom would override every specific rule above it.

.github/CODEOWNERS
# Docs owners. The last matching line wins, so broad rules go first./docs/                      @acme/docs-team/docs/api/                  @acme/api-team/docs/billing/              @acme/billing/README.md                  @acme/docs-team
# Agent instructions are docs for coding agents.AGENTS.md                   @acme/platformCLAUDE.md                   @acme/platform

How the patterns match

Patterns follow most .gitignore rules. A few differences catch people out.

  • /docs/ with a leading slash matches the root docs folder and everything under it. docs/ without one matches a docs folder at any depth, including packages/sdk/docs/.
  • *.md matches Markdown files anywhere in the repository, code folders included. Prefer folder rules for docs.
  • ! negation and [ ] character ranges do not work.
  • A line with a pattern and no owner leaves those files without an owner, which is how you exclude a generated folder from a broad rule.

Give every owner write access

GitHub only requests review from owners who have write access to the repository. A team must also be visible. An owner without that access is ignored, and GitHub marks the line as an error when you view the file in the repository.

Step 3. Require review from code owners

On its own the file only requests reviews. To make an approval required, turn on the rule for the default branch.

  1. On GitHub, open the repository's Settings, then Rules, then Rulesets, and edit or create the ruleset for the default branch. With classic branch protection, open Settings, then Branches.
  2. Turn on Require a pull request before merging.
  3. Under it, turn on Require review from Code Owners.
  4. Save. GitHub reads CODEOWNERS from the pull request's base branch, so the file must be merged there first.

Step 4. Test it with one pull request

Merge the file into the default branch first, then test from a new branch.

  1. Open the CODEOWNERS file on GitHub. Lines with a problem, such as an unknown team or a team without write access, are highlighted with the reason.
  2. Open a pull request that edits one page under docs/api/. The reviewers list should show @acme/api-team, requested by code owners.
  3. Edit a page under docs/ that no specific rule covers. The request should go to @acme/docs-team.
  4. If no reviewer appears, check whether the pull request is a draft. GitHub requests code owners when a draft is marked ready for review.

Keep docs owners apart from code owners

CODEOWNERS makes no distinction between who approves code and who looks after a page. If the two differ in your team, Rimfe reads an owners key in the root .rimfe.json for docs pages first and falls back to CODEOWNERS for any page no rule matches. In owners, unlike CODEOWNERS, the last matching rule also wins.

Rimfe uses the owners in three places. It asks them to review the docs pull requests it opens, skipping the author. It lists them on each finding in its pull request comment, in code spans so nobody gets pinged. It tells owners who linked their Slack account or receive email when a finding touches their page.

.rimfe.json
{  "$schema": "https://rimfe.com/schema/rimfe.json",  "docsGlobs": ["README.md", "docs/**/*.{md,mdx}"],  "owners": [    { "paths": ["docs/**", "README.md"], "owners": ["@acme/docs-team"] },    { "paths": ["docs/api/**"], "owners": ["@acme/api-team"] }  ]}

Common mistakes

  • A catch-all line such as * @acme/leads at the bottom of the file, which overrides every docs rule above it.
  • A team without write access, which GitHub skips without telling the author.
  • Requiring owner approval on generated folders such as docs/api/generated/, so a team must approve files a tool rewrites. Give those folders a line with no owner.
  • Expecting CODEOWNERS to catch missing docs. It reviews pages a pull request edits. A page nobody edited never reaches its owner, which is the gap a docs check closes.

Takeaway

Broad rules first, teams with write access as owners, and Require review from Code Owners on the default branch. Then add a check for the pages nobody thought to edit.