# Linear (https://docs.ctxpipe.ai/docs/self-hosting/linear)

Self-hosted Linear uses an OAuth application that you create in Linear. The
usual path is to paste the client ID, client secret, and webhook signing secret
into the connector wizard. That path needs no `LINEAR_*` environment variables
and no service restart.

The same routes run on hosted ctxpipe and on self-host. Hosted ctxpipe keeps a
deployment-wide Linear app in environment variables as a fallback. Self-host
operators can use that fallback too. Use it when you want one shared Linear
application for the whole deployment.

The worker decrypts the saved client secret with the same key the backend uses
(`AUTH_SECRET` or `CONNECTION_SECRETS_ENCRYPTION_KEY`). That is not a new Linear
environment variable.

## What you need

* A public HTTPS `AUTH_BASE_URL`. In production, keep
  `CTXPIPE_PUBLIC_APP_URL` on the same origin.
* Permission to create a Linear OAuth application.
* A ctxpipe GitHub App connection with write access to the repository of each
  Workspace that uses Linear.
* Network access from the backend and the worker to `api.linear.app` over
  HTTPS.

## Connector state and backups

You can review the Linear scope in Git:

* Each Workspace has a source file at `sources/linear/<name>.md`. Draft scope is
  the file on the branch of the pull request that adds it.
* Live scope is the same file on the default branch after the merge.
* The deployment stores encrypted credentials and setup status on the
  `connections` row. The connection holds authorization only.
* Signed Linear events update in-scope generated files through durable worker
  jobs.

Back up PostgreSQL for connection credentials. Back up the Workspace
repositories for both scope and mirrored content. PostgreSQL contains only
credentials and setup state.

## 1. Create a Linear application

Open [Create new application](https://linear.app/settings/api/applications/new)
in Linear Settings → API.

Fill in **Application name** and **Developer name**. In **Redirect URIs**, paste:

```text
https://<public-origin>/api/v1/integrations/linear/callback
```

Linear supports several redirect URIs, one per line. Add local, staging, or
preview callbacks individually when those environments must run OAuth. The
scheme, host, path, and trailing slash must match the URI that ctxpipe sends.

ctxpipe requests the **`read`** scope with a user actor on the authorize URL. You
do not set those on this Linear form.

Linear cannot deliver webhooks to a private localhost address. To test a
connector end to end, use a public HTTPS deployment or tunnel.

## 2. Configure webhooks on the same form

Turn **Webhooks** on and set **Webhook URL** to:

```text
https://<public-origin>/api/v1/webhook/linear
```

Copy **Webhook signing secret** from that form. Linear fills it in before you
select Create. ctxpipe verifies the `Linear-Signature` HMAC against the raw
request body. It rejects stale timestamps. For an accepted in-scope event,
ctxpipe starts a durable update before the endpoint acknowledges delivery.

Under **Data change events**, select Issues, Comments, Documents, Projects,
Initiatives, Teams, and the related update and attachment boxes (including
cycles, issue labels, users, and customer requests). Under **Authorization events**,
select OAuth authorization events.

Then select **Create**. Only after that, Linear shows **Client ID** and
**Client secret**. Copy them for the next step.

<Callout title="One webhook URL per Linear application">
  A Linear application has one webhook destination. You can register several
  OAuth redirect URIs, but events from every workspace installation go to that
  one webhook URL. Use a separate Linear application when a staging or PR
  environment must receive its own incremental events. Per-organization apps
  each register the same Webhook URL and store their own signing secret on the
  connection.
</Callout>

## 3. Register the app in the product UI

1. Open **Connectors**, select **Add connection**, then select **Connect** on
   the **Linear** row.
2. On **Register Linear OAuth app**, paste the client ID and the client secret
   that Linear shows after Create. Also paste the webhook signing secret from the
   create form. The wizard shows the exact **Redirect URIs** and **Webhook URL** values
   for this deployment.
3. Save the app, then continue to **Connect Linear**.
4. Complete OAuth. In **Add to Workspaces**, choose the Workspaces and the
   scope, then merge the pull request that adds `sources/linear/<name>.md`.

ctxpipe stores secrets encrypted on the Linear `connections` row. The list and
status APIs never return them.

The backend and worker must share the encryption key
(`AUTH_SECRET` / `CONNECTION_SECRETS_ENCRYPTION_KEY`) so token refresh can use
the saved client secret.

## 4. Optional deployment-wide environment variables

`LINEAR_*` is an optional operator shortcut for a deployment-wide Linear
application (the hosted fallback). When you set both `LINEAR_CLIENT_ID` and
`LINEAR_CLIENT_SECRET`, the wizard skips Register and starts at Connect.

| Variable                |                           Required | Purpose                                                                                    |
| ----------------------- | ---------------------------------: | ------------------------------------------------------------------------------------------ |
| `LINEAR_CLIENT_ID`      | Optional; backend + worker if used | Shared OAuth application client ID                                                         |
| `LINEAR_CLIENT_SECRET`  | Optional; backend + worker if used | Shared OAuth code exchange and token refresh                                               |
| `LINEAR_REDIRECT_URI`   |                  Backend; optional | Exact callback override; defaults to `{AUTH_BASE_URL}/api/v1/integrations/linear/callback` |
| `LINEAR_WEBHOOK_SECRET` |          Optional; backend if used | Shared signing secret for `/api/v1/webhook/linear`                                         |

Empty values still parse as unset. Restart or redeploy both services after
changing these variables.

### Docker Compose

Add the variables to the root `.env` used by the `deploy` profile only if you
want a deployment-wide app. Then run:

```bash
docker compose --profile deploy up -d --build backend worker
```

### AWS CDK

Pass the four values through `connectorSecrets` when you want the
deployment-wide fallback:

```ts
new CtxPipe(stack, "CtxPipe", {
  // other required settings
  connectorSecrets: {
    linearClientId: cdk.SecretValue.secretsManager("linear/client-id"),
    linearClientSecret: cdk.SecretValue.secretsManager("linear/client-secret"),
    linearWebhookSecret: cdk.SecretValue.secretsManager("linear/webhook-secret"),
    // Optional when AUTH_BASE_URL already produces the registered callback:
    linearRedirectUri: cdk.SecretValue.unsafePlainText(
      "https://app.example.com/api/v1/integrations/linear/callback",
    ),
  },
});
```

The construct stores these values in the connector secret and injects them into
backend and worker task definitions.

## 5. Verify the connector

1. Confirm `GET /.status` succeeds on the public backend origin.
2. Confirm the worker is running and shares the backend encryption key.
3. Open **Connectors**, select **Add connection**, then select **Connect** on
   the **Linear** row.
4. If `LINEAR_*` is unset, complete **Register Linear OAuth app**, then Connect.
5. Complete OAuth and confirm the expected Linear workspace appears.
6. In **Add to Workspaces**, choose a Workspace and a scope.
7. Merge the pull request that adds `sources/linear/<name>.md`.
8. Confirm the GitHub App delivers the merge push to
   `{AUTH_BASE_URL}/api/v1/webhook/github/<connectionId>`.
9. Confirm the connector reaches **Connected** and generated files appear under
   `linear/` in the Workspace repository.
10. Edit a mirrored Linear issue and confirm
    `POST /api/v1/webhook/linear` succeeds and the corresponding Git file
    changes.
11. Confirm the Workspace re-indexes.

ctxpipe copies Linear file uploads and explicit embedded external media into
sibling `assets/` directories in the Workspace repository. Ordinary link-only
attachments stay links. ctxpipe never crawls them. GitHub pull requests and
commits stay references. The limits are 25 MiB for each asset and 100 MiB for
each Linear entity. An unsafe, failed, or oversized asset leaves a Linear link
or a textual stub. Give the destination repository the same sensitivity as the
selected Linear scope.

Initial sync proves OAuth, worker, and GitHub access. The webhook step
separately proves Linear webhook delivery and signature configuration.

## Troubleshooting

### “Linear OAuth is not configured”

Neither the connection nor the deployment has a Linear client ID and secret.
Register the app in the wizard, or set `LINEAR_CLIENT_ID` and
`LINEAR_CLIENT_SECRET` on the backend and the worker if you want a deployment-wide app.

### Linear reports a redirect URI mismatch

Compare the authorize request's `redirect_uri` with the application setting
character for character. If you can, leave `LINEAR_REDIRECT_URI` unset, so that ctxpipe
derives it from the public `AUTH_BASE_URL`. Use the override only behind a proxy
with a different external callback.

### OAuth succeeds but sync later fails

The worker must decrypt the saved client secret. It needs the same
`AUTH_SECRET` / `CONNECTION_SECRETS_ENCRYPTION_KEY` as the backend. When you
use the environment variable fallback, the worker needs `LINEAR_CLIENT_ID` and
`LINEAR_CLIENT_SECRET`. Check outbound HTTPS and the worker logs. Check if
someone revoked the application authorization in Linear.

### The source pull request cannot open

If **Add to Workspaces** reports an error, confirm that the selected GitHub App
installation still has write access to the repository of the Workspace. Also
confirm that the Workspace repository uses format 2 or higher. Below that, the
dialog shows **Needs the format upgrade first.** next to the Workspace.

### Webhook endpoint returns 503

No webhook signing secret is present on the matching Linear connection or in
`LINEAR_WEBHOOK_SECRET`.

### Webhook endpoint returns 401

The signing secret does not match the Linear application that sent the event, a
proxy changed the raw body, or the event timestamp is stale. Do not parse and
re-serialize the body in a gateway before forwarding it. A secret saved on one
connection does not authorize events for another.

### Initial sync works but later edits do not appear

This is a webhook problem, not an OAuth problem. Confirm that webhooks are
enabled on the application, the public URL is reachable, the relevant resource
categories are selected, and requests reach `/api/v1/webhook/linear`.

## User guide

See [Linear connector](/docs/connections/source-connectors/linear) for scope,
repository layout, review workflow, and user-facing recovery steps.
