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:
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 pushWhat'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
| Input | Description | Required |
|---|---|---|
| anthropic-api-key | Anthropic API key | One of* |
| openrouter-api-key | OpenRouter API key | One of* |
| provider | LLM provider (anthropic/openrouter) | No |
| model | Model to use | No |
| output-dir | Output directory for files | No |
| basic | Skip AI analysis | No |
* Either anthropic-api-key or openrouter-api-key is required (unless basic mode)
Action Outputs
| Output | Description |
|---|---|
| context-file | Path to generated CONTEXT.md |
| prompt-file | Path to generated SYSTEM_PROMPT.md |
| token-estimate | Estimated token count of output |
Using OpenRouter
OpenRouter gives you access to multiple LLM providers (Claude, GPT-4, Gemini, etc.):
- uses: skridlevsky/livectx@v1
with:
openrouter-api-key: ${{ secrets.OPENROUTER_API_KEY }}
provider: openrouter
model: anthropic/claude-3.5-sonnetHandling 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:
CONTEXT.md linguist-generated=true merge=ours
SYSTEM_PROMPT.md linguist-generated=true merge=oursThis:
- 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:
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):
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 pushSetting Up Secrets
Add your API key as a repository secret:
- Go to your repository on GitHub
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
ANTHROPIC_API_KEY(orOPENROUTER_API_KEY) - Value: Your API key
- 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.