GitHub Action

Automatically update your context files on every push to main. The GitHub Action runs livectx and commits the updated files back to your repository.

Basic Setup

Create a workflow file at .github/workflows/update-context.yml:

.github/workflows/update-context.yml
name: Update Context

on:
  push:
    branches: [main]
    paths-ignore:
      - 'CONTEXT.md'
      - 'SYSTEM_PROMPT.md'

permissions:
  contents: write

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

      - uses: skridlevsky/livectx@v1
        with:
          anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}

      - name: Commit changes
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add CONTEXT.md SYSTEM_PROMPT.md
          git diff --staged --quiet || git commit -m "docs: update context [skip ci]"
          git push

What's [skip ci]?

When a commit message contains [skip ci], GitHub Actions won't run workflows on that commit. This prevents infinite loops.

Action Inputs

InputDescriptionRequired
anthropic-api-keyAnthropic API keyOne of*
openrouter-api-keyOpenRouter API keyOne of*
providerLLM provider (anthropic/openrouter)No
modelModel to useNo
output-dirOutput directory for filesNo
basicSkip AI analysisNo

* Either anthropic-api-key or openrouter-api-key is required (unless basic mode)

Action Outputs

OutputDescription
context-filePath to generated CONTEXT.md
prompt-filePath to generated SYSTEM_PROMPT.md
token-estimateEstimated token count of output

Using OpenRouter

OpenRouter gives you access to multiple LLM providers (Claude, GPT-4, Gemini, etc.):

.github/workflows/update-context.yml
- uses: skridlevsky/livectx@v1
  with:
    openrouter-api-key: ${{ secrets.OPENROUTER_API_KEY }}
    provider: openrouter
    model: anthropic/claude-3.5-sonnet

Handling Merge Conflicts

Short answer: There aren't any.

The workflow only runs after code is merged to main. Since context is regenerated from the latest merged state, there's nothing to conflict with.

For PRs, context is generated as a preview artifact (not committed), so developers can review what will change without merge conflicts.

Recommended .gitattributes

Add this to handle rare edge cases:

.gitattributes
CONTEXT.md linguist-generated=true merge=ours
SYSTEM_PROMPT.md linguist-generated=true merge=ours

This:

  • Marks files as generated (excluded from language stats)
  • Tells git to keep the current version on conflicts (since it will be regenerated anyway)

PR Preview Workflow

Generate context as a preview on pull requests without committing:

.github/workflows/preview-context.yml
name: Preview Context

on:
  pull_request:
    branches: [main]

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

      - uses: skridlevsky/livectx@v1
        id: livectx
        with:
          anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
          output-dir: ./context-preview

      - name: Upload preview
        uses: actions/upload-artifact@v4
        with:
          name: context-preview
          path: ./context-preview/
          retention-days: 7

      - name: Comment on PR
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: '📝 Context preview generated! Check the artifacts tab.\n\nEstimated tokens: ~${{ steps.livectx.outputs.token-estimate }}'
            })

Scheduled Updates

Regenerate context on a schedule (useful for repos with infrequent commits):

.github/workflows/scheduled-context.yml
name: Scheduled Context Update

on:
  schedule:
    - cron: '0 0 * * 1'  # Every Monday at midnight
  workflow_dispatch:      # Allow manual trigger

permissions:
  contents: write

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

      - uses: skridlevsky/livectx@v1
        with:
          anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}

      - name: Commit changes
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add CONTEXT.md SYSTEM_PROMPT.md
          git diff --staged --quiet || git commit -m "docs: weekly context update [skip ci]"
          git push

Setting Up Secrets

Add your API key as a repository secret:

  1. Go to your repository on GitHub
  2. Navigate to Settings → Secrets and variables → Actions
  3. Click New repository secret
  4. Name: ANTHROPIC_API_KEY (or OPENROUTER_API_KEY)
  5. Value: Your API key
  6. Click Add secret

Security note

Repository secrets are encrypted and only exposed to GitHub Actions workflows. They're never visible in logs or to users without admin access.