Why the file needs an owner#
Required code owner review protects each path with the approval of the team the file names. The file itself is a path too. If its last matching line is the default owner, * @acme/developers, then any developer can approve a change that rewrites who owns everything else. The base-branch rule means the team being removed still reviews the pull request that removes it, as the guide to the base-branch rule shows, but only if that pull request also touches the team's code. A pull request that changes only CODEOWNERS requests whoever owns CODEOWNERS, and nobody else.
GitHub's documentation names this gap: "To protect a repository fully against unauthorized changes, you also need to define an owner for the CODEOWNERS file itself. The most secure method is to define a CODEOWNERS file in the .github directory of the repository and define the repository owner as the owner of either the CODEOWNERS file (/.github/CODEOWNERS @owner_username) or the whole directory (/.github/ @owner_username)." CODEOWNERS and branch protection
Why .github/ is the right location#
GitHub looks for the file in three places: "create a new file called CODEOWNERS in the .github/, root, or docs/ directory ... If CODEOWNERS files exist in more than one of those locations, GitHub will search for them in that order and use the first one it finds." CODEOWNERS file location
That order matters for ownership. If your file is in .github/, a pull request that adds a root CODEOWNERS changes nothing, because GitHub never reaches it. If your file is at the root, a pull request that adds .github/CODEOWNERS replaces the whole ownership map once it merges, and the reviewers of that pull request are whoever owns the new path. Keeping the file in .github/ and owning that directory closes both routes with one line.
How public projects do it#
Node.js assigns the file to its Technical Steering Committee: /.github/CODEOWNERS @nodejs/tsc. nodejs/node .github/CODEOWNERS, read on 2026-11-23. Node's file says it is for courtesy pings only, so the line routes attention rather than enforcing approval.
Grafana gives the file to one person, /.github/CODEOWNERS @tolzhabayev, in its "GitHub Workflows and Templates" section. grafana/grafana .github/CODEOWNERS, read on 2026-11-23. Under required code owner review, an individual owner means one person's absence holds every ownership change.
Home Assistant keeps its file at the repository root, with a header saying "This file is generated by script/hassfest/codeowners.py," and owns the directory that would shadow it: /.github/ @home-assistant/core. home-assistant/core CODEOWNERS, read on 2026-11-23. The file as read contains no line that matches the root CODEOWNERS path itself, so CODEOWNERS requests no one for a direct edit to it. When a generator writes the file, a check that regenerates it and compares the result is what would catch a hand edit; the file alone does not show whether the project runs one.
A fictional setup#
Suppose acme/shop keeps its file in .github/. The end of the file reads:
# Ownership and CI configuration. Keep this section last so no broader
# pattern above can take these paths.
/.github/ @acme/repo-admins
/.github/workflows/ @acme/repo-admins @acme/ci
@acme/repo-admins has three members and write access, and the default branch ruleset has Require review from Code Owners on. A developer on @acme/payments opens a pull request that deletes the /services/payments/ @acme/payments-leads line, so that their own team's approval would suffice from then on. GitHub requests @acme/repo-admins, because the last matching line for .github/CODEOWNERS is /.github/. The pull request waits for an admin, who can ask the payments leads before approving.
Placing the section last matters because the last matching line wins. A *.yml or **/* pattern added below it later would quietly take these paths; the last-match rule explains how.
The section also covers workflow files. A pull request can change the workflow that runs its own required check, which is a separate risk with the same fix. The example gives /.github/workflows/ its own line with @acme/ci beside the admins, so either team's approval satisfies it.
What owning the file does not catch#
An admin who approves an ownership change sees a diff of patterns and team names. Nothing in that diff shows which files a pattern change moves between teams, or that a named team lacks write access. Ask the author to name the paths that change owner, and check the file's errors on the head commit before approving.
The line also does not bind people who can bypass the rule. A ruleset's bypass list, or an administrator who is exempt from a branch protection rule, can merge a CODEOWNERS change without the admins' approval.
What it costs#
Every ownership change waits for one of a few people. In a repository where teams reorganize often, that queue becomes visible. A team of three or more, with team review auto assignment turned on so that one member is picked per request, keeps the delay short without widening who can approve.
The decision#
Own the file whenever Require review from Code Owners is on; without that line, the requirement can be edited away by anyone the default owner includes. Keep the file in .github/, give that directory to a small admin team rather than an individual, and keep the line in a final section that nothing follows.