# GitHub (https://docs.ctxpipe.ai/docs/self-hosting/github)

GitHub is the base of a self-hosted ctxpipe deployment. The GitHub App reads the
linked code repositories. It also writes to the Workspace repositories. It
writes the knowledge, the source files, and the content of Linear, Notion,
Confluence, PagerDuty, and Slack.

Your deployment must use a GitHub App that **you create and own**. Self-hosted
repository traffic and credentials do not pass through the hosted ctxpipe GitHub
App.

## Before you start

* Configure a stable public HTTPS `AUTH_BASE_URL`.
* Sign in as an owner or admin of the ctxpipe organization.
* Decide if a GitHub user account or a GitHub organization owns the App.
* Make sure that you can install the App on the GitHub accounts that own the
  target repositories.

<Callout type="warn" title="GitHub sign-in is separate">
  A GitHub OAuth App used for product sign-in is not the repository GitHub App.
  The repository App has its own ID, private key, webhook secret, permissions,
  and installation.
</Callout>

## 1. Start the in-product setup

Open **Connectors**, select **Add connection**, then select **Connect** on the
**GitHub** row. The self-hosted wizard reserves a connection and shows the exact
callback, setup, and webhook URLs for that connection.

Keep the wizard open while you register the App. The webhook URL contains a
connection identifier. Copy it from the wizard. Do not guess it.

## 2. Register the GitHub App

Create a [new personal GitHub App](https://github.com/settings/apps/new), or
open a GitHub organization's **Settings → Developer settings → GitHub Apps →
New GitHub App**.

Use the values that the ctxpipe wizard shows:

| GitHub field           | Value                                               |
| ---------------------- | --------------------------------------------------- |
| **GitHub App name**    | A unique name your operators recognize              |
| **Homepage URL**       | Your `AUTH_BASE_URL`                                |
| **Callback URL**       | `{AUTH_BASE_URL}/.auth/api/v1/auth/callback/github` |
| **Setup URL**          | `{AUTH_BASE_URL}/.github/setup`                     |
| **Redirect on update** | Enabled                                             |
| **Webhook active**     | Enabled                                             |
| **Webhook URL**        | Copy the connection-specific URL from the wizard    |
| **Webhook secret**     | Copy the generated secret from the wizard           |

The connection-specific webhook follows this shape:

```text
{AUTH_BASE_URL}/api/v1/webhook/github/<connectionId>
```

## 3. Grant the required permissions

Set repository permissions:

* **Contents:** Read and write
* **Pull requests:** Read and write
* **Issues:** Read-only

Set account permissions:

* **Email addresses:** Read-only

Subscribe to these events:

* **Pull request**
* **Pull request review**
* **Pull request review comment**
* **Issues**
* **Issue comment** (conversation on issues and pull requests)
* **Push**
* **Repository**

The pull request events let ctxpipe mirror the closed pull requests of every
linked repository, merged or not. It writes them into
`github/pulls/<owner>/<repo>/` of each Workspace that links the repository. The
**Issues** and **Issue comment** events let ctxpipe mirror the issues of every
linked repository into `github/issues/<owner>/<repo>/` in the same way. The App
installation must be able to read those linked repositories. ctxpipe does not
mirror required-check conclusions.

A backfill of the issues of one linked repository reads up to 200 of the most
recently updated issues. It sends one GraphQL request for each 50 issues. Each
request includes the 100 most recent comments of each issue. It writes all the
files in one commit.

### Add the Issues permission to an existing App

An App that you created before the issue mirror does not have **Issues:
Read-only** or the **Issues** event. Do these steps:

1. In the GitHub App settings, set **Issues** to **Read-only** under
   repository permissions.
2. Subscribe to the **Issues** event.
3. Save the changes.
4. Tell the owner of each installation of the App to accept the new
   permission. GitHub shows the request on the installation settings page of
   that account and sends an email to the owner.

Until the owner of an installation accepts the permission, ctxpipe does not
mirror the issues of that installation. The pull request mirror and indexing
continue to work. When the owner accepts, GitHub sends an `installation` event.
ctxpipe then backfills the issues of each linked repository of that account.
After that, ctxpipe mirrors each issue change.

ctxpipe needs write access because it commits to Workspace repositories. It
also opens pull requests for source changes, upgrades, and Workspace chat. Limit
the App installation to the repositories that ctxpipe must read or write.

## 4. Generate and save credentials

After you create the App:

1. Copy its numeric **App ID**.
2. Copy the App slug from its public URL.
3. Generate and download a private key (`.pem`).
4. Return to the ctxpipe wizard.
5. Paste the App ID and slug, then upload or paste the complete PEM.
6. Save the connection.

ctxpipe encrypts the private key and webhook secret for this GitHub connection.
Keep `AUTH_SECRET` stable. Use
`CONNECTION_SECRETS_ENCRYPTION_KEY` when your secret-management policy needs an
explicit connector encryption key.

## 5. Install and verify the App

Install the App on the GitHub user or organization that owns the source
repositories. Choose **Only select repositories** unless the deployment
needs broad access.

ctxpipe attaches an installation to an organization only with proof that it
belongs there. A connection that you create in the wizard gives this proof with
its own App credentials. An installation of an App that you configure with
`GITHUB_APP_ID` is different. The person who finishes setup must show that
their GitHub account can see the installation. If their linked GitHub account
cannot show this, ctxpipe asks them to authorize the App once. ctxpipe uses
the short-lived token of that authorization for this check only. It does not
keep the token and does not link the GitHub account.

The authorization needs the client ID and the client secret of that same App
in `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`. These variables also turn on
GitHub sign-in. The App must list the callback URL
`{AUTH_BASE_URL}/.auth/api/v1/auth/callback/github`. Without these values, use
the wizard.

Then verify the full path:

1. The GitHub connector reaches **Connected**.
2. **Create workspace** lists repositories from the expected installation.
3. A linked repository reaches **Indexed** in the Workspace's **Settings**.
4. Changing repository selection returns through the ctxpipe setup URL.
5. A test push reaches the connection-specific webhook.
6. A source change can open a pull request on the Workspace repository.

## Troubleshooting

### Installation returns to the wrong host

Check the App's Callback URL and Setup URL against the current
`AUTH_BASE_URL`. Keep browser, auth, callbacks, API, and MCP on the same public
backend origin.

### Setup asks to connect a GitHub account

ctxpipe attaches the installation through the App that `GITHUB_APP_ID`
configures. Link a GitHub account that can see the installation, or create
the connection with the self-hosted wizard so its own App credentials prove the
installation.

### Repositories do not appear

Confirm that the App is installed on the correct GitHub account and has access
to the repository. A change to the installation in GitHub does not tell
ctxpipe to index a repository. After that, link the repository from the
Workspace's **Settings**.

### Webhooks fail signature verification

The secret in the GitHub App settings must match the secret saved for this ctxpipe
connection. Do not reuse a connection-specific URL with credentials from
another connection.

### Issues do not appear in the Workspace

Confirm that the App has **Issues: Read-only** and that it subscribes to the
**Issues** event. Then find the cause in the backend logs:

* `github_issue_mirror_no_permission`: the owner of the installation did not
  accept the Issues permission. Tell the owner to accept it on the installation
  settings page in GitHub. ctxpipe then backfills the issues.
* `github_issue_mirror_repository_not_covered`: the installation does not have
  access to the repository. Add the repository to the repository access of the
  installation in GitHub. After that, ctxpipe mirrors each issue change of
  that repository.

### Connector writes fail

Confirm that **Contents** and **Pull requests** are both read and write.
Confirm that the installation includes the Workspace repository.

<Cards>
  <Card title="Docker deployment" href="/docs/self-hosting/deployment/docker" description="Run the reference stack and provide deployment secrets." />

  <Card title="Production readiness" href="/docs/self-hosting/production-readiness" description="Verify origins, callbacks, persistence, and secret handling." />

  <Card title="GitHub user guide" href="/docs/connections/source-connectors/github" description="Select and manage repositories after operators configure the App." />

  <Card title="Create a Workspace" href="/docs/workspaces/create-workspace" description="Choose the repository connectors write to." />
</Cards>
