Skip to main content
This guide covers all the ways to publish codemods to the Codemod Registry, from local development to automated CI/CD pipelines.

Authentication Methods

Codemod supports three authentication methods for publishing:
MethodBest ForSecrets RequiredSetup
Interactive LoginLocal developmentNoneNone
API KeysCI/CD pipelines, automationYes (CODEMOD_API_KEY)Create key in UI
Trusted PublishersGitHub Actions, secure CI/CDNone (uses OIDC)None for org scopes*
* If your GitHub organization name matches your package scope, trusted publishing works automatically with zero configuration. See Organization Scopes.

Interactive Login

The simplest way to authenticate for local development. Opens a browser for OAuth authentication.
# Login to the registry
npx codemod login

# Verify authentication
npx codemod whoami
After logging in, you can publish packages:
npx codemod publish

When to Use

  • Local development and testing
  • Quick one-off publishes
  • When you prefer browser-based authentication

Trusted Publishers

Trusted publishers enable passwordless publishing from GitHub Actions using OpenID Connect (OIDC). No secrets to manage or rotate.

How OIDC Works

GitHub Actions can request short-lived tokens that cryptographically prove the workflow’s identity. Codemod verifies these tokens against your configured trusted publishers.

Benefits

  • No secrets to manage: No API keys to create, rotate, or accidentally leak
  • Cryptographically secure: Tokens are signed by GitHub and verified by Codemod
  • Fine-grained control: Restrict publishing by repository, workflow, environment, or git ref
  • Short-lived tokens: Tokens expire in ~5 minutes, limiting exposure

Organization Scopes (Zero Configuration)

This is the recommended approach for organizations. If your GitHub organization name matches your package scope, trusted publishing works automatically with no UI configuration needed.
For packages under an organization scope (e.g., @my-org/my-codemod), trusted publishers work automatically when:
  1. Your GitHub organization name matches the package scope (e.g., GitHub org my-org → scope @my-org)
  2. You’ve linked your GitHub organization (see setup steps below)
Any repository in your GitHub organization can then publish packages under your scope, including new packages and updates to existing ones.

Linking Your GitHub Organization

To enable automatic trusted publishing for your organization scope, you need to install the Codemod GitHub App:
1

Install the Codemod GitHub App

  1. Install the Codemod GitHub App and select your GitHub organization (requires org admin permissions)
  2. Grant access to at least one repository
2

Sign in to Codemod

Go to Codemod platform and sign in with GitHub. Your organization will be automatically linked.
Once linked, anyone who can trigger GitHub Actions workflows (e.g., via push, release, or workflow_dispatch) in your organization’s repositories can publish codemods under that scope. The publisher identity in Codemod’s system is tied to the user who installed the GitHub App.

Complete GitHub Actions Workflow

Here’s a complete workflow file for publishing. You can create this manually or use codemod init to generate it automatically: For a single codemod repository:
# .github/workflows/publish.yml
name: Publish Codemod
on:
  push:
    tags:
      - "v*"  # Triggers on tags like v1.0.0, v2.1.3, etc.

permissions:
  id-token: write  # Required for OIDC token
  contents: read   # Required to checkout code

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Publish codemod
        uses: codemod/publish-action@v1
For a monorepo with multiple codemods: If you have multiple codemods in a single repository (e.g., in a codemods/ directory), use tags like [email protected]:
# .github/workflows/publish.yml
name: Publish Codemod
on:
  push:
    tags:
      - "*@v*"  # Triggers on tags like [email protected]

permissions:
  id-token: write
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Extract codemod name from tag
        id: extract
        run: |
          TAG="${GITHUB_REF#refs/tags/}"
          CODEMOD_NAME="${TAG%@v*}"
          echo "codemod_name=$CODEMOD_NAME" >> $GITHUB_OUTPUT

      - name: Publish codemod
        uses: codemod/publish-action@v1
        with:
          path: codemods/${{ steps.extract.outputs.codemod_name }}
You can also run npx codemod init to generate this workflow automatically. It creates the single-codemod or monorepo format based on your project structure.

Individual Packages (Manual Configuration)

For unscoped packages or cases where the GitHub org doesn’t match the package scope, configure a trusted publisher manually:
1

Configure Trusted Publisher in UI

  1. Go to codemod.com/api-keys
  2. Scroll to Trusted Publishers
  3. Click Add Trusted Publisher
  4. Select your package and enter the GitHub repository details
  5. (Optional) Add restrictions for extra security
2

Configure Your Workflow

# .github/workflows/publish.yml
name: Publish Codemod
on:
  push:
    tags:
      - "v*"

permissions:
  id-token: write  # Required for OIDC
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: codemod/publish-action@v1
FieldDescriptionExample
PackageThe package to publish to (required)my-codemod or @org/my-codemod
Repository OwnerGitHub org or usernamemy-org
Repository NameRepository namemy-codemod-repo
Once configured, any workflow in that repository can publish to the specified package.

Optional Restrictions

Add restrictions for additional security:
RestrictionDescriptionExample
Workflow PathOnly allow specific workflow files.github/workflows/publish.yml
EnvironmentRequire GitHub Environment approvalproduction
Ref PatternOnly allow specific git refsrefs/tags/v*
Example with restrictions:
name: Publish Codemod
on:
  release:
    types: [published]

permissions:
  id-token: write
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    environment: production  # Matches "Environment" restriction
    steps:
      - uses: actions/checkout@v4
      - uses: codemod/publish-action@v1

Manual OIDC Setup

If you prefer not to use the action, you can manually obtain and use the OIDC token:
name: Publish Codemod
on:
  release:
    types: [published]

permissions:
  id-token: write
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install codemod CLI
        run: npm install -g codemod@latest

      - name: Get OIDC token
        id: oidc
        uses: actions/github-script@v7
        with:
          script: |
            const token = await core.getIDToken('https://codemod.com');
            core.setOutput('token', token);
            core.setSecret(token);

      - name: Publish codemod
        env:
          CODEMOD_AUTH_TOKEN: ${{ steps.oidc.outputs.token }}
        run: codemod publish

Troubleshooting

Verify your trusted publisher configuration matches:
  • Repository owner (case-insensitive)
  • Repository name (exact match)
  • Any configured restrictions (workflow path, environment, ref pattern)
For organization scopes: Ensure the GitHub App is installed on at least one repository in your organization and you’ve signed in to Codemod with a GitHub account that has access to the organization.
Ensure your workflow has the required permissions:
permissions:
  id-token: write  # Required for OIDC token
  contents: read   # Required to checkout code
The OIDC token audience must be https://codemod.com. If using a custom registry, configure GITHUB_OIDC_AUDIENCE on the server.

API Keys

API keys allow non-interactive authentication, perfect for CI/CD pipelines and automation.

Creating an API Key

  1. Go to codemod.com/api-keys
  2. Click Create API Key
  3. Give it a descriptive name (e.g., “GitHub Actions - my-repo”)
  4. Select the permissions (typically “Publish Packages”)
  5. Copy the key (it won’t be shown again)

Using API Keys

Option 1: Login with API key
npx codemod login --api-key $CODEMOD_API_KEY
npx codemod publish
Option 2: Environment variable
CODEMOD_AUTH_TOKEN=$CODEMOD_API_KEY npx codemod publish

GitHub Actions Example

name: Publish Codemod
on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Login to Codemod Registry
        run: npx codemod login --api-key ${{ secrets.CODEMOD_API_KEY }}

      - name: Publish codemod
        run: npx codemod publish
Store your API key as a repository secret. Never commit API keys to your repository.

When to Use

  • CI/CD pipelines without GitHub Actions OIDC
  • GitLab CI, CircleCI, Jenkins, etc.
  • Automated publishing from any environment
  • When you need explicit control over credentials

Comparison

FeatureInteractive LoginAPI KeysTrusted Publishers
Secrets to manageNoneYesNone
Works locallyYesYesNo
Works in CI/CDNoYesGitHub Actions only
New package publishYesYesYes*
Token lifetimeLong-livedLong-lived~5 minutes
Rotation neededNoRecommendedNo
UI configurationNoneCreate keyNone for org scopes**
* Trusted publishers can publish new packages when using a matching organization scope. ** Organization scopes that match your GitHub org name require no configuration in Codemod platform. Individual packages require adding a trusted publisher in the UI.

Best Practices

Use Trusted Publishers

For GitHub Actions, prefer trusted publishers over API keys. No secrets to leak or rotate.

Restrict Access

When using trusted publishers, add restrictions like environment protection for sensitive packages.

Rotate API Keys

If using API keys, rotate them periodically and use the minimum required permissions.

Tag Releases

Use git tags and GitHub releases to trigger publish workflows for clear version history.

Next Steps