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 path | Owner | Why |
|---|---|---|
/docs/ | @acme/docs-team | Default owner for every page |
/docs/api/ | @acme/api-team | Describes the API handlers |
/docs/billing/ | @acme/billing | Describes plans and invoices |
/README.md | @acme/docs-team | First 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.
# 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/platformHow the patterns match
Patterns follow most .gitignore rules. A few differences catch people out.
/docs/with a leading slash matches the rootdocsfolder and everything under it.docs/without one matches adocsfolder at any depth, includingpackages/sdk/docs/.*.mdmatches 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.
- 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.
- Turn on Require a pull request before merging.
- Under it, turn on Require review from Code Owners.
- Save. GitHub reads
CODEOWNERSfrom 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.
- Open the
CODEOWNERSfile on GitHub. Lines with a problem, such as an unknown team or a team without write access, are highlighted with the reason. - Open a pull request that edits one page under
docs/api/. The reviewers list should show@acme/api-team, requested by code owners. - Edit a page under
docs/that no specific rule covers. The request should go to@acme/docs-team. - 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.
{ "$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/leadsat 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
CODEOWNERSto 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.