# @actions/github

> Actions github lib

Latest version **9.1.1** (published 2026-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @actions/github
pnpm add @actions/github
yarn add @actions/github
bun add @actions/github
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.1.1 |
| Published | 2026-04-21 |
| First published | 2019-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5847 |
| Maintainers | bryanmacfarlane, thboop, ericsciple, bdehamer |
| Keywords | github, actions |

## Links

- npm: https://www.npmjs.com/package/@actions/github
- Repository: https://github.com/actions/toolkit
- Homepage: https://github.com/actions/toolkit/tree/main/packages/github
- Issues: https://github.com/actions/toolkit/issues
- npm.io page: https://npm.io/package/@actions/github

## Dependencies (7)

- [undici](https://npm.io/package/undici.md) ^6.23.0
- [@octokit/core](https://npm.io/package/@octokit/core.md) ^7.0.6
- [@octokit/request](https://npm.io/package/@octokit/request.md) ^10.0.7
- [@actions/http-client](https://npm.io/package/@actions/http-client.md) ^3.0.2
- [@octokit/request-error](https://npm.io/package/@octokit/request-error.md) ^7.1.0
- [@octokit/plugin-paginate-rest](https://npm.io/package/@octokit/plugin-paginate-rest.md) ^14.0.0
- [@octokit/plugin-rest-endpoint-methods](https://npm.io/package/@octokit/plugin-rest-endpoint-methods.md) ^17.0.0

## Recent versions

- 9.1.1 (latest) — 2026-04-21
- 9.1.0 — 2026-04-08
- 9.0.0 — 2026-01-27
- 8.0.1 — 2026-01-27
- 8.0.0 — 2026-01-26
- 7.0.0 — 2026-01-08
- 6.0.1 — 2025-05-07
- 6.0.0 — 2023-10-10
- 5.1.1 — 2022-09-30
- 5.1.0 — 2022-09-23
- 5.0.3 — 2022-05-13
- 5.0.2 — 2022-05-12
- 5.0.1 — 2022-03-31
- 5.0.0 — 2021-05-14
- 4.0.0 — 2020-06-26
- … 9 more at https://npm.io/package/@actions/github/versions

## README

# `@actions/github`

> A hydrated Octokit client.

## Usage

Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners) and correctly sets GHES base urls. See https://octokit.github.io/rest.js for the API.

**Note:** This package is ESM-only starting from v9.0.0. For CommonJS projects, use dynamic import:
```js
async function main() {
    const { getOctokit, context } = await import('@actions/github');
    // ... your code here
}
main();
```

For bundled actions (recommended), most bundlers like esbuild, webpack, and rollup handle ESM imports automatically.

```js
import * as github from '@actions/github';
import * as core from '@actions/core';

async function run() {
    // This should be a token with access to your repository scoped in as a secret.
    // The YML workflow will need to set myToken with the GitHub Secret Token
    // myToken: ${{ secrets.GITHUB_TOKEN }}
    // https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
    const myToken = core.getInput('myToken');

    const octokit = github.getOctokit(myToken)

    // You can also pass in additional options as a second parameter to getOctokit
    // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"});

    const { data: pullRequest } = await octokit.rest.pulls.get({
        owner: 'octokit',
        repo: 'rest.js',
        pull_number: 123,
        mediaType: {
          format: 'diff'
        }
    });

    console.log(pullRequest);
}

run();
```

You can also make GraphQL requests. See https://github.com/octokit/graphql.js for the API.

```js
const result = await octokit.graphql(query, variables);
```

Finally, you can get the context of the current action:

```js
import * as github from '@actions/github';

const context = github.context;

const newIssue = await octokit.rest.issues.create({
  ...context.repo,
  title: 'New issue!',
  body: 'Hello Universe!'
});
```

## Webhook payload typescript definitions

The npm module `@octokit/webhooks-definitions` provides type definitions for the response payloads. You can cast the payload to these types for better type information.

First, install the npm module `npm install @octokit/webhooks-definitions`

Then, assert the type based on the eventName
```ts
import * as core from '@actions/core'
import * as github from '@actions/github'
import {PushEvent} from '@octokit/webhooks-definitions/schema'

if (github.context.eventName === 'push') {
  const pushPayload = github.context.payload as PushEvent
  core.info(`The head commit is: ${pushPayload.head_commit}`)
}
```

## Extending the Octokit instance
`@octokit/core` now supports the [plugin architecture](https://github.com/octokit/core.js#plugins). You can extend the GitHub instance using plugins. 

For example, using the `@octokit/plugin-enterprise-server` you can now access enterprise admin apis on GHES instances.

```ts
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils'
import { enterpriseServer220Admin } from '@octokit/plugin-enterprise-server'

const octokit = GitHub.plugin(enterpriseServer220Admin)
// or override some of the default values as well 
// const octokit = GitHub.plugin(enterpriseServer220Admin).defaults({userAgent: "MyNewUserAgent"})

const myToken = core.getInput('myToken');
const myOctokit = new octokit(getOctokitOptions(token))
// Create a new user
myOctokit.rest.enterpriseAdmin.createUser({
  login: "testuser",
  email: "testuser@test.com",
});
```

---
_Source: https://npm.io/package/@actions/github · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
