Set up Code-to-Docs with GitHub
Run Code-to-Docs in GitHub Actions with the event-catalog/agents action. New to Code-to-Docs? Read the introduction first.
Before you start
You need:
- An EventCatalog in a GitHub repository (the catalog repository), with the catalog at the root of the repository.
- A GitHub repository with code to document (the source repository).
- An API key for an AI model provider.
Setup
In your source repository, add two secrets under Settings → Secrets and variables → Actions:
ANTHROPIC_API_KEY, or the key for your model provider.EVENTCATALOG_TOKEN, a GitHub token that can read your catalog repository, push branches to it and open pull requests. Or use a GitHub App.
Then add the workflow:
on:
pull_request:
types: [closed]
jobs:
code-to-docs:
# Only once the pull request is merged.
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: event-catalog/agents@v2
env:
# The key for your model's provider. This one is for the default model.
# Using another provider? Swap this variable and set `model` below.
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
with:
# The agent workflow to run.
agent: code-to-docs
# Your catalog repository, in owner/repo format.
catalog-repo: your-org/your-catalog
# A token that can read your catalog, push branches and open pull requests.
catalog-token: ${{ secrets.EVENTCATALOG_TOKEN }}
# Optional: the model to use. Defaults to anthropic/claude-sonnet-4-6.
# model: openai/gpt-5.1
Replace your-org/your-catalog with your catalog repository. Keep fetch-depth: 0: the agent needs it to compare the pull request with its base branch.
To check it works, merge a pull request that changes your architecture, such as a new event or a changed schema. The agent opens a pull request in your catalog, and comments on your pull request with a link to it.
Choose when it runs
The workflow above runs Code-to-Docs when a pull request merges, which we recommend. To run it while the pull request is open instead, so reviewers see the catalog update next to the code:
on:
pull_request:
types: [opened, synchronize, reopened]
Remove the job's if when you do. See the introduction for how the two compare.
Use pull_request events, not push to your main branch. The agent needs the pull request to compare it with its base branch and to comment on it.
Use it across your organization
Choose who reviews. To send each catalog update to the team that owns that part of the catalog, add a CODEOWNERS file to your catalog repository:
/domains/Payments/ @acme/payments-platform
/domains/Orders/ @acme/ordering-platform
Set up many repositories at once. Keep the workflow in one place as a reusable workflow, and call it from each repository:
on:
pull_request:
types: [closed]
jobs:
eventcatalog:
if: github.event.pull_request.merged == true
uses: acme/.github/.github/workflows/eventcatalog-agents.yml@main
secrets: inherit
Use organization secrets for your model provider key, and a GitHub App instead of a personal token.