The `octokit-auth-netrc` package provides a plugin for Octokit that enables authentication using credentials stored in a user's `.netrc` file. This is particularly useful for command-line tools and scripts that need to interact with GitHub without hardcoding tokens or using environment variables directly. The current stable version is 4.0.0, which was released on January 30, 2026. This library's release cadence is generally tied to updates in the Octokit ecosystem and Node.js LTS version changes. Its key differentiator is simplifying authentication against GitHub (including GitHub Enterprise Server) by leveraging the standard `.netrc` file format, providing a robust and familiar mechanism for developers who already use this method for other tools like `curl`. It handles both `api.github.com` and custom GitHub Enterprise domains.
npm install octokit-auth-netrcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to authenticate with GitHub using `octokit-auth-netrc` and then make a simple API request to fetch the authenticated user's details, including handling for a missing .netrc entry.
Upgrade your Node.js runtime to version `^20.19.0` or `>=22.14.0`.
Migrate your codebase to use ES module `import` statements. Ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions for ESM files.
Upgrade your Node.js runtime to version 18, 20, or newer (up to v21 for pre-v4, then v20.19.0 or >=22.14.0 for v4+).
No direct fix required for typical usage, but be aware of the internal dependency change if experiencing unexpected parsing behavior of the `.netrc` file.
Ensure your `~/.netrc` file contains an entry for the target domain (e.g., `api.github.com` or your GitHub Enterprise Server domain) formatted correctly, including `machine <domain>` and `login <personal access token>`.
Convert your project or file to ESM using `import` statements and ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions.
Add an entry to your `~/.netrc` file similar to: ``` machine api.github.com login YOUR_GITHUB_PERSONAL_ACCESS_TOKEN ``` Make sure the file permissions are correct (e.g., `chmod 600 ~/.netrc`).
When initializing `Octokit`, pass the `createNetrcAuth` function as `authStrategy`, and its options as `auth`:
```typescript
const octokit = new Octokit({
authStrategy: createNetrcAuth,
auth: { domain: 'github.acme-inc.com' }
});
```