A tool for working with CODEOWNERS files from GitHub, GitLab, and Bitbucket. Usable as a CLI or as a library, with no dependencies.
npm install -g codeownersRequires Node.js 22.12 or later.
List each file in the current repository with its owners:
codeowners auditaudit lists the files git knows about: tracked files, plus untracked files that .gitignore
does not exclude. Outside a git repository, or with --include-ignored, it walks the filesystem
instead, skipping node_modules, .git and .cache.
List only the files no one owns:
codeowners audit --unownedUse a non-standard CODEOWNERS file name:
codeowners audit -c CODEKEEPERSVerify that users or teams own a path (exits 1 if none of them do):
codeowners verify src/ @foob_ar @contoso/engineersList the owners of a path:
codeowners list src/index.jsEvery command takes -d, --dialect <github|gitlab> to choose the CODEOWNERS syntax.
const Codeowners = require('codeowners');
// workingDir is optional and defaults to process.cwd()
const repos = new Codeowners(workingDir);
repos.getOwner('path/to/file.js'); // => ['@noahm']
// or parse contents directly
const rules = Codeowners.parse(fs.readFileSync('CODEOWNERS', 'utf8'));
rules.getOwner('path/to/file.js');new Codeowners() searches upward from the working directory, checking .github/, .gitlab/,
.bitbucket/, the directory itself, and docs/ at each level. Paths passed to getOwner are
relative to the project root (repos.codeownersDirectory), or absolute.
GitHub and GitLab read the same file differently, so the parser has a dialect. It defaults to
GitLab for a file in .gitlab/ or one with [Section] headers, and GitHub otherwise. Override it
with new Codeowners(dir, 'CODEOWNERS', { dialect: 'gitlab' }) or Codeowners.parse(text, { dialect }).
| GitHub | GitLab | |
|---|---|---|
docs/a.md (slash in the middle) |
anchored to the root | matches at any depth |
docs (no trailing slash) |
the file, or everything in the directory | only a file named docs |
docs/* |
direct children only | direct children only |
/docs/** |
everything inside | one level, like * |
[abc] |
literal brackets | character class |
!pattern |
invalid, skipped | excludes matching paths from the section |
# comment after owners |
ignored | owners in it are still read |
[Section] headers |
not supported | owners combine across sections |
Both match case-sensitively and treat \ as an escaped space.
pnpm install
pnpm test # vitest
pnpm coverage # fails below 100% coverage
pnpm lint # eslint, prettier, and tsc
pnpm bench # getOwner over 2,000 rules and 200,000 paths- Patterns follow GitHub's CODEOWNERS rules:
docs/*and/*match direct children only, matching is case-sensitive, and\escapes a space. - GitLab syntax: sections, section default owners, optional sections, approval counts,
!exclusions, and character classes. - Bitbucket's
.bitbucket/CODEOWNERSlocation is found. - Lookups are about 75 times faster on large CODEOWNERS files.
- Memory use stays flat however many paths are checked.
- Pattern matching runs in linear time, so a hostile CODEOWNERS file cannot stall it.
- Inline
#comments are skipped when reading owners, and exposed as each entry'scomment. auditskips files ignored by git and includes untracked files git would commit.auditlists files only, sorted, and escapes control characters in file names and owners.auditlists symlinks instead of following them.auditruns with git'score.fsmonitordisabled, so an audited repository cannot run commands.auditruns git from an absolute path onPATH, so agitprogram inside the audited repository is never run.- New
listcommand prints the owners of a path. - New
Codeowners.parse()parses CODEOWNERS contents without the filesystem. - New
-d, --dialectoption anddialectlibrary option. - Windows paths work in
getOwnerand in finding the project root. - Error messages name the requested CODEOWNERS file name.
- No runtime dependencies.
- Requires Node.js 22.12 or later.
- Much-improved performance
- Removal of automatic column width calculation
- Addition of
-w/--widthoption for manual column width- Or use e.g.
codeowners audit | column -ts " "
- Or use e.g.