CI Auto-Sync

Keep Codehabits team intelligence fresh by syncing automatically after every merged PR using GitHub Actions.

Team conventions drift when PRs merge but intelligence files stay stale. Codehabits can sync automatically on every merged PR via a GitHub Actions workflow generated by npx @codehabits/cli setup-action.

Generate the workflow

From your repository root:

Terminal
npx @codehabits/cli setup-action

This creates .github/workflows/codehabits-sync.yml (or similar) configured for your default branch.

Create a CI token

The workflow needs a Codehabits API token stored as a repository secret:

Terminal
npx @codehabits/cli token create --name "CI"

Add the token as CODEHABITS_TOKEN in your GitHub repository secrets (Settings → Secrets and variables → Actions).

What the workflow does

  1. Triggers when a PR is merged to your default branch
  2. Runs npx @codehabits/cli sync --ci
  3. Commits updated .codehabits/, skills, and AGENTS.md
  4. Pushes changes back to the default branch

Example workflow

.github/workflows/codehabits-sync.yml
name: codehabits Sync

on:
  pull_request:
    types: [closed]
    branches: [main]

permissions:
  contents: write

jobs:
  sync:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
      - name: Sync Codehabits Intelligence
        env:
          CODEHABITS_TOKEN: ${{ secrets.CODEHABITS_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: npx @codehabits/cli@latest sync --ci
      - name: Commit updated intelligence
        run: |
          git config user.name "codehabits[bot]"
          git config user.email "bot@codehabits.dev"
          git add .codehabits/ AGENTS.md .cursor/skills/ || true
          git diff --staged --quiet || git commit -m "chore: sync codehabits intelligence"
          git push

Org repos

For GitHub organization repositories, ensure the repo is linked to a team workspace when you first ran enable. CI sync uses the same token and repo registration.

Manual sync

For ad-hoc updates without CI, run npx @codehabits/cli sync locally and commit the changes. See the CLI reference for flags and options.