# GitHub
URL: https://docs.clearly-ai.com/docs/integrations/code/github
Description: Connect Clearly AI to GitHub.
## Overview [#overview]

Connect GitHub so Clearly AI can use your repositories as project context and review the code in them.

An admin sets up GitHub for the workspace with one of three authentication methods:

* **Shared API Token**: a GitHub fine-grained personal access token.
* **OAuth 2.0**: signing in to GitHub, plus the Clearly AI GitHub App.
* **GitHub App installation**: the Clearly AI GitHub App's access to its selected repositories, independent of a person's access.

For help choosing between them, see [Which method should you use?](#which-method-should-you-use).

## Set up GitHub [#set-up-github]

<Steps>
  <Step>
    ### Open the GitHub integration [#open-the-github-integration]

    In **Organization settings** > **Integrations**, click **Allow** on the GitHub card if it's under **Available**. Then open **Connections**, click **Add connection**, choose **GitHub** under **Integration**, and choose **Everyone in the workspace** under **Who can use it**.
  </Step>

  <Step>
    ### Choose an authentication method [#choose-an-authentication-method]

    Under **Authentication method**, select **Shared API Token**, **OAuth 2.0**, or **GitHub App installation**.

    #### Option A. Shared API Token [#option-a-shared-api-token]

    1. In GitHub, [create a fine-grained personal access token](https://github.com/settings/personal-access-tokens/new). Select the organization and repositories Clearly AI should access, and grant **Contents** and **Pull requests** read and write. GitHub adds **Metadata** read automatically.
    2. Paste the token into **Shared API Token**.

    #### Option B. OAuth 2.0 [#option-b-oauth-20]

    <Note>
      Only the owner of the GitHub account, or an owner of the GitHub organization, can install the Clearly AI GitHub App on its repositories.
    </Note>

    1. Click **Connect**. Sign in to GitHub if prompted, and approve Clearly AI's access request.
    2. Install the [Clearly AI GitHub App](https://github.com/apps/clearly-ai-app/installations/new) on the organization or account that owns the repositories, and grant it access to those repositories.

    <Callout>
      Clearly AI shows a green **Connected** label as soon as you sign in to GitHub, before it has found a Clearly AI GitHub App installation. **Connected** doesn't mean repository access works. Install the App before you save the connection.
    </Callout>

    #### Option C. GitHub App installation [#option-c-github-app-installation]

    <Note>
      A Clearly AI workspace admin must connect the installation. For a GitHub organization, the person connecting must also be an active GitHub organization owner/admin. Connect a **Personal (User)** GitHub **OAuth 2.0** connection first so Clearly AI can list installations and check your role. If you haven't signed in, the installation picker offers the GitHub sign-in flow.
    </Note>

    1. Select **GitHub App installation**.
    2. Choose an installation. Each option shows the GitHub account and **All repositories** or **Selected repositories**. To add an installation, click **Install on another GitHub organization** and choose its repository access in GitHub.
    3. Optionally name the connection, then save it.

    If GitHub refuses the role check, the installation appears disabled with this message:

    > GitHub refused the role check. Authorize Clearly AI for SSO in this org, or ask an org owner.

    Complete any required SSO authorization or organization approval in GitHub, then reload the installations. Other installations remain available.
  </Step>

  <Step>
    ### Save the connection [#save-the-connection]

    For **Shared API Token** or **GitHub App installation**, click **Save Authentication**. If you chose **OAuth 2.0**, the connection saves after you finish signing in; there is no separate save button. Clearly AI tests the credential and saves the connection only when the test passes. Projects can then add GitHub repositories as sources.
  </Step>
</Steps>

To change the token or the GitHub account later, open **Connections**, click **Manage** on the GitHub connection, update the credential under **Credential**, then click **Save**. Clearly AI tests it again before saving.

People can also connect their own GitHub account as a **Personal (User)** Connection: open **Connections**, click **Add connection**, choose **GitHub** under **Integration**, and choose **Only me** if you're an admin. GitHub appears there only after an admin allows it in **Organization settings** > **Integrations**. Sources that run as you use your Personal Connection. Workflow steps use the Connection selected on the step. A Personal Connection reaches only repositories where the Clearly AI GitHub App is installed, so install the App there first.

## Which method should you use? [#which-method-should-you-use]

| Method                      | Best when                                                                                            | Notes                                                                              |
| --------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| **Shared API Token**        | You want the quickest setup and prefer to manage the token yourself                                  | Access is limited to the repositories and permissions granted to that token        |
| **OAuth 2.0**               | You want GitHub to handle signing in and grant repository access through the Clearly AI GitHub App   | Requires the App installed on the repositories                                     |
| **GitHub App installation** | Workspace access should follow the installation's repository selection rather than a person's access | Personal OAuth proves ownership during setup; ongoing access uses the installation |

An installation Connection uses short-lived GitHub App tokens, not a person's token. Changing the installation's repository selection changes its access. Uninstalling or suspending the App in GitHub revokes that access.

## GitHub App and GitHub user permissions [#github-app-and-github-user-permissions]

OAuth 2.0 combines two separate pieces of GitHub access. Both are required, and each does a different job:

| Piece                                         | Grants                                                                                                 | Configured by                                                                                                                                                                                  |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Clearly AI GitHub App** install             | Which organizations, accounts, and repositories Clearly AI can read (for example, repository contents) | The personal account owner, or a GitHub organization owner for org-owned repositories, from the [Clearly AI GitHub App install page](https://github.com/apps/clearly-ai-app/installations/new) |
| **GitHub user** who signs in with **Connect** | Which of those App installations Clearly AI can see and use                                            | The person who signs in through OAuth in Clearly AI                                                                                                                                            |

Neither piece alone is enough:

* The App install without a connected GitHub user leaves Clearly AI with no signed-in identity to look up the installation.
* A connected GitHub user without the App install leaves Clearly AI with no repository permissions. GitHub App permissions come from the App's install configuration, not from OAuth consent scopes, so signing in doesn't grant repository access by itself.

For a **Shared (Workspace)** OAuth connection, use a dedicated GitHub bot or service account to sign in, instead of a personal account. Alternatively, choose **GitHub App installation** so ongoing access follows the installation rather than that account.

## Which GitHub account writes a wiki page [#which-github-account-writes-a-wiki-page]

The **Upsert GitHub Wiki Page** workflow step publishes a review to a GitHub wiki. GitHub stores wiki pages in a separate repository, so the step clones that repository and pushes the page using the GitHub account behind its selected Connection.

The selected GitHub account must have write access to the wiki repository, and the Clearly AI GitHub App must be installed there. The App installation gives Clearly AI access to the repository; it does not grant the selected account write permission. To publish with another account, select a different Connection on the step.

## Refresh a repository on a project [#refresh-a-repository-on-a-project]

Clearly AI keeps the commit it downloaded until you refresh the source. To pick up later commits, open the project, open **Manage Sources**, and choose **Refresh source** on the branch. When processing finishes, re-run the review. See [Update a review when sources change](https://docs.clearly-ai.com/docs/reviews#update-a-review-when-sources-change).

## FAQs [#faqs]

<Accordions>
  <Accordion title="Why does Clearly AI reject my Shared API Token?">
    Confirm the token is still active, covers the repositories Clearly AI needs, and grants **Contents** and **Pull requests** read and write.
  </Accordion>

  <Accordion title="Why does Connect do nothing?">
    Check whether your browser is blocking pop-ups or redirects for Clearly AI.
  </Accordion>

  <Accordion title="Why are some repositories missing after OAuth 2.0 succeeds?">
    Confirm that the GitHub account you authorized can access those repositories and that any required SSO or organization approval has been completed.
  </Accordion>

  <Accordion title="Why does OAuth show Connected but the credential or repository links fail?">
    **Connected** confirms GitHub sign-in succeeded, not that the Clearly AI GitHub App is installed. [Install the App](https://github.com/apps/clearly-ai-app/installations/new) and grant it access to the target repositories. Then open **Connections**, click **Manage** on the GitHub connection, open **Credential**, and click **Connect** again, or add the repository or pull request link again. See [GitHub App and GitHub user permissions](#github-app-and-github-user-permissions) for details.
  </Accordion>

  <Accordion title="Why does the Organization dropdown only show one org after I installed the GitHub App?">
    The dropdown lists only the organizations and accounts where the Clearly AI GitHub App is installed. If you need repositories from your personal account as well as an organization, install the App separately on your personal account from the [Clearly AI GitHub App install page](https://github.com/apps/clearly-ai-app/installations/new). Your personal account then appears as its own entry in the Organization dropdown.
  </Accordion>

  <Accordion title="Is Personal (User) OAuth the same as the Shared (Workspace) GitHub connection?">
    No. A Shared (Workspace) OAuth connection and a Personal (User) OAuth connection are independent. Expanding personal OAuth access does not change the shared connection's repository scope, and the reverse is also true.
  </Accordion>

  <Accordion title="Why does Clearly AI need both a GitHub App install and a connected GitHub user?">
    For OAuth connections, they grant different things. The Clearly AI GitHub App install grants repository permissions. The connected GitHub user is the identity Clearly AI uses to look up which App installations it can use. For **GitHub App installation** connections, personal OAuth is required to verify ownership during setup, but ongoing access uses the installation. See [GitHub App and GitHub user permissions](#github-app-and-github-user-permissions).
  </Accordion>

  <Accordion title="Should I connect a personal GitHub account or a service account?">
    For a **Personal (User)** connection, connect your own account. For a **Shared (Workspace)** OAuth connection, use a dedicated GitHub bot or service account. Choose **GitHub App installation** if workspace access should follow the installation instead of an account.
  </Accordion>

  <Accordion title="Why does Upsert GitHub Wiki Page return 403 Write access to repository not granted?">
    The tile pushes as the GitHub account in [Which GitHub account writes a wiki page](#which-github-account-writes-a-wiki-page). GitHub returns that 403 when the account cannot write to the repository.
  </Accordion>
</Accordions>

## Related [#related]

* [Integrations](https://docs.clearly-ai.com/docs/integrations) - Choose an authentication method for an integration
* [Concepts](https://docs.clearly-ai.com/docs/concepts) - Learn how integrations provide project context in Clearly AI