Guides

Configure from the environment

Create providers from FORGES_* environment variables.

forges/env creates providers from environment variables, so a CLI or a server can pick up credentials for any forge without code for each one. Each variable has the form FORGES_<KIND>_<FIELD>, such as FORGES_GITHUB_TOKEN or FORGES_GITLAB_BASE_URL.

Create the providers

forgesFromEnv() reads the variables and passes every configured provider to createForges():

import { forgesFromEnv } from 'forges/env'

const forges = forgesFromEnv(process.env)

Report skipped forges

providersFromEnv() returns one entry for each set of variables. An entry has a factory when the variables configure a provider, and a skipped reason when they don't. The reason never contains a credential:

import { createForges } from 'forges'
import { providersFromEnv } from 'forges/env'

const entries = providersFromEnv(process.env)

for (const entry of entries) {
  if (entry.skipped) {
    console.warn(`Skipping ${entry.kind}: ${entry.skipped}`)
  }
}

const forges = createForges(
  entries.flatMap(entry => entry.factory ? [entry.factory] : []),
)

Variables

<KIND> is the forge in upper case, with underscores for hyphens: GITHUB, GITLAB, BITBUCKET, FORGEJO, GITEA, GITEE, AZURE_DEVOPS, CURSOR_ORIGIN, TANGLED or PUSHIN.

These fields set the shared provider options:

FieldEffect
TOKENSets auth to a token
BASE_URLSets baseUrl
INSTANCESets instance
INSTANCE_VERSIONSets instanceVersion
WEBHOOK_SECRETSets webhookSecret
READ_ONLYSets readOnly: true when the value is 1 or true
ENABLED1 or true creates an anonymous provider without a token. 0 or false skips the forge
DEMO_REPOSets entry.demoRepo to an owner/name repository for your code to use, and enables anonymous reads

Some forges read more fields:

ForgeFields
GitHub, Cursor OriginAPP_ID, PRIVATE_KEY and INSTALLATION_ID for app auth. Write the newlines in PRIVATE_KEY as \n
Bitbucket, Azure DevOpsUSERNAME and PASSWORD for Basic auth
Azure DevOpsORGANIZATION, which is required
TangledIDENTIFIER, PASSWORD and an optional PDS for an app password. API_URL and NOTIFICATIONS_URL set the service URLs

The provider page for each forge explains what these options do.

Configure a second instance

Add a suffix after the field to start another set of variables for the same forge. Every variable in a set has the same suffix, and entry.suffix holds it:

FORGES_GITHUB_TOKEN=ghp_...
FORGES_GITHUB_TOKEN_WORK=ghp_...
FORGES_GITHUB_BASE_URL_WORK=https://ghe.example.com/api/v3

createForges() throws when two providers share a forge and an instance. If two sets point at the same host, give one of them a different INSTANCE.

Copyright © 2026