Learning center

Audit CODEOWNERS errors before you require code owner review

GitHub skips a broken CODEOWNERS line or an owner it cannot use, so paths quietly end up with fewer owners than the file shows. Before you require code owner review, list the file's errors through the API, confirm every owner has write access, and keep the file under 3 MB.

How CODEOWNERS fails#

GitHub's documentation describes four ways a CODEOWNERS file stops doing what it says. In each, GitHub drops owners; none is described as blocking a pull request. About code owners

A line with a syntax error is dropped: "If any line in your CODEOWNERS file contains invalid syntax, that line will be skipped." Its paths then go to whichever earlier line also matches them, if any. An owner that cannot be used is dropped too: "If you specify a user or team that doesn't exist or has insufficient access, a code owner will not be assigned." Owners need explicit write access, "even if all the individual members of the team already have write permissions," and a team must also be visible. You can name a user by an email address on their account, but "You cannot use an email address to refer to a managed user account." Finally, files "must be under 3 MB." A larger file "will not be loaded, which means that code owner information is not shown and the appropriate code owners will not be requested."

Each of these lowers the bar. A skipped line hands its paths to an earlier, usually broader, owner. An owner without access is not assigned. An oversized file assigns nobody. With Require review from Code Owners on, a pull request in any of those paths can merge with less review than the file appears to demand.

This behavior has changed before. GitHub's 2022 changelog says that previously a line with a syntax error "would be ignored or in some cases cause the entire CODEOWNERS file to not load." CODEOWNERS improvements changelog The README of the community codeowners-validator still quotes an older version of GitHub's page, saying an invalid line means "the file will not be detected," so check claims like that against the current page.

Terraform comments out owners it cannot use#

HashiCorp's Terraform repository shows the access rule in practice. Several remote-state backends have maintainers outside the HashiCorp organization, and their lines are commented out:

* @hashicorp/terraform-core

#/internal/backend/remote-state/cos              @likexian @SevenEarth
/internal/backend/remote-state/s3                @hashicorp/terraform-core @hashicorp/terraform-aws

The comment above them explains why: "Entries that are commented out have maintainers that are not in the HashiCorp organization and so cannot be automatically added as reviewers," and the lines "would make GitHub consider this file invalid if not commented." hashicorp/terraform CODEOWNERS, read on 2026-11-23. Because the file starts with a default owner, the commented-out paths fall back to @hashicorp/terraform-core and still have someone to request. The project keeps the maintainer list as documentation without leaving GitHub to drop the owners on its own.

List the errors#

GitHub highlights errors when you open the CODEOWNERS file in the repository, and the same list is available from the REST API. List CODEOWNERS errors The endpoint takes a ref parameter, "A branch, tag or commit name used to determine which version of the CODEOWNERS file to use," and defaults to the default branch. Each branch has its own CODEOWNERS file, so check every branch you protect:

gh api repos/OWNER/REPO/codeowners/errors
gh api "repos/OWNER/REPO/codeowners/errors?ref=release-2.4"

The example response in GitHub's OpenAPI description shows two kinds of error, a bad pattern and a bad owner: github/rest-api-description

{
  "errors": [
    {
      "line": 3,
      "column": 1,
      "kind": "Invalid pattern",
      "source": "***/*.rb @monalisa",
      "suggestion": "Did you mean `**/*.rb`?",
      "message": "Invalid pattern on line 3: Did you mean `**/*.rb`?\n\n  ***/*.rb @monalisa\n  ^",
      "path": ".github/CODEOWNERS"
    },
    {
      "line": 7,
      "column": 7,
      "kind": "Invalid owner",
      "source": "*.txt docs@",
      "suggestion": null,
      "message": "Invalid owner on line 7:\n\n  *.txt docs@\n        ^",
      "path": ".github/CODEOWNERS"
    }
  ]
}

The documentation does not say whether a team that exists but lacks write access appears in this list, so check access separately. The team endpoint returns the team's permission on the repository, and "If a team doesn't have permission for the repository, you will receive a 404 Not Found response status." Check team permissions for a repository

gh api orgs/ORG/teams/TEAM_SLUG/repos/OWNER/REPO \
  -H "Accept: application/vnd.github.v3.repository+json" --jq .permissions

Keep it checked on every change#

An audit is a snapshot; the next edit can break a line. A workflow that runs on pull requests touching CODEOWNERS can call the same endpoint against the proposed version. The endpoint needs read access to repository contents, which the workflow token can be given. Permissions required for GitHub Apps This sketch is for pull requests from branches in the same repository:

name: codeowners-errors
on:
  pull_request:
    paths: [".github/CODEOWNERS"]
permissions:
  contents: read
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - env:
          GH_TOKEN: ${{ github.token }}
        run: |
          count=$(gh api "repos/${{ github.repository }}/codeowners/errors?ref=${{ github.event.pull_request.head.sha }}" --jq '.errors | length')
          test "$count" -eq 0

Some projects use other checks. CockroachDB's header asks anyone editing the file to "look at the 'Files' tab and fix any errors Github reports." cockroachdb/cockroach .github/CODEOWNERS, read on 2026-11-23. Grafana runs codeowners-validator on pull requests with its files, duppatterns and syntax checks. grafana/grafana codeowners-validator.yml, read on 2026-11-23.

What a clean audit does not tell you#

An empty error list means every line parses and every owner resolves. It does not mean the right team owns each path: a valid line placed above a broader one is overridden without any error, as the last-match rule shows, and the gitignore forms that CODEOWNERS does not support are a separate trap. It also says nothing about whether an owner team has enough active members to review.

What turning on the requirement costs#

The audit protects against too little review. The requirement brings the opposite risk: a valid owner with no one available blocks merges. A team whose only members are authors of the change cannot approve, because "Pull request authors cannot approve their own pull requests." Approving a pull request with required reviews

The order to turn it on#

On private repositories, code owners need GitHub Pro, Team or Enterprise. GitHub's plans

  1. Run the errors endpoint on each protected branch and fix every entry.
  2. Check write access for every team and user the file names.
  3. Confirm the file is well under 3 MB; Kibana's, at more than 4,000 lines, was about 340 KB when read on 2026-11-23. elastic/kibana .github/CODEOWNERS
  4. Add the pull request check above.
  5. Turn on Require review from Code Owners in the branch rule or ruleset.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading