# How do I call a context tool from GitHub Actions before an AI code review?


URL: https://getunblocked.com/answers/call-context-tool-github-actions-before-ai-code-review/
Published: 2026-11-26T17:00:00Z
Updated: 2026-11-25T12:32:31Z
Author: Brandon Waselnuk
Categories: Context Engine, Engineering Insights

**Short answer:** Add a step before the reviewer in a pull\_request workflow. Store an Unblocked API token as a repository secret, list the changed directories with gh pr diff --name-only, and run unblocked context-research once per area. Write the answers to a file, then have Claude Code's GitHub Action read that file before it comments.

---
For a GitHub Actions AI code review, put the context call in its own step, ahead of the reviewer. The workflow fires on `pull_request` and asks a context engine about each directory the PR touches. With Unblocked, that step runs `unblocked context-research` with an API token from a GitHub secret, and gets back a cited JSON summary of past bugs, reverts, incidents and design decisions. **A context pre-step** is a CI step that gathers history about the changed code and hands it to the reviewer as input. Teams we work with run this shape, then score risk or post a review. Others run headless Claude Code in Actions with the Unblocked MCP server.

## Set the trigger and store the token

Trigger on `pull_request`. GitHub runs it by default on `opened`, `synchronize` and `reopened`; add `ready_for_review` with `types` ([GitHub events reference](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows)). A `paths` filter skips docs-only PRs ([GitHub workflow syntax](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax)).

**A Team Access Token** is an Unblocked API token whose requests are attributed to the team, not a person ([Unblocked Context API](https://docs.getunblocked.com/api-reference/context-overview)). Create one (or a personal token) under Settings, API Tokens, and limit the data sources it can read ([Unblocked headless setup](https://docs.getunblocked.com/unblocked-mcp/install-claude-code)). Save it as a repository secret such as `UNBLOCKED_API_TOKEN` and pass it through `env`; GitHub says to "avoid passing secrets between processes from the command line" ([GitHub secrets docs](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets)). The CLI reads `UNBLOCKED_API_TOKEN` from the environment ([Unblocked CLI auth](https://docs.getunblocked.com/unblocked-cli/cli-auth)).

Two limits. Forked-repo runs get no secrets, so this works on branch PRs only. And a team token "can access every document in the data sources selected." Anything it pulls can land in a PR comment, so pick sources accordingly. Data Shield filters answers for people; it does not narrow what a bot token can reach.

## Ask only about the areas the PR changed

Cost and latency scale with question count, so ask about areas, not files. `gh pr diff --name-only` lists changed files, and `--exclude` drops lockfiles ([GitHub CLI manual](https://cli.github.com/manual/gh_pr_diff)). GitHub CLI is preinstalled on hosted runners and needs `GH_TOKEN` ([GitHub CLI in workflows](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-github-cli)). Collapse that to the top two directory levels and cap it at five. Eight frontier models caught only 15 to 31% of human-flagged issues from the diff alone ([SWE-PRBench, March 2026](https://arxiv.org/abs/2603.26130)). Yet all eight got worse as raw context grew; a short diff-with-summary prompt beat a longer full-context one.

Ask two to four plain questions per area, for example:

- What bugs, reverts or incidents have involved this directory?
- What design decisions or constraints apply here?
- Is related work open or abandoned?

`context-research` takes `--effort low|medium|high`, where higher "is slower but more thorough" ([Unblocked CLI query docs](https://docs.getunblocked.com/unblocked-cli/cli-query)). Use `low` on every push. Add `concurrency` with `cancel-in-progress: true` so a new push cancels the old run, plus `timeout-minutes`. For which questions earn their place, see [what teams have the reviewer ask](https://getunblocked.com/answers/filter-noisy-ai-code-review-comments/).

## A workflow sketch with the CLI

The CLI route keeps the context call outside the model, so you see exactly what was asked ([how the CLI and MCP fit together](https://getunblocked.com/blog/unblocked-context-engine-for-agents/)). The installer puts the binary in `~/.local/bin/` ([Unblocked CLI install](https://docs.getunblocked.com/unblocked-cli/cli-install)). The reviewer is [Claude Code's GitHub Action](https://code.claude.com/docs/en/github-actions), which by default reads workspace files without asking ([action usage docs](https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md)).

```yaml
name: Review with context
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    paths:
      - "services/**"
concurrency:
  group: review-${{ github.event.pull_request.number }}
  cancel-in-progress: true
jobs:
  review:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 1
      - name: Ask Unblocked about changed areas
        continue-on-error: true
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          UNBLOCKED_API_TOKEN: ${{ secrets.UNBLOCKED_API_TOKEN }}
          PR: ${{ github.event.pull_request.number }}
          REPO: ${{ github.repository }}
        run: |
          curl -fsSL https://getunblocked.com/install.sh | bash
          gh pr diff "$PR" --repo "$REPO" --exclude '*.lock' > pr.diff
          gh pr diff "$PR" --repo "$REPO" --name-only --exclude '*.lock' \
            | cut -d/ -f1-2 | sort -u | head -n 5 > areas.txt
          while read -r area; do
            echo "## $area" >> context.md
            "$HOME/.local/bin/unblocked" context-research --effort low \
              --query "Past bugs, reverts, incidents and design decisions for $area" \
              | jq -r '.summary' >> context.md
          done < areas.txt
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: |
            Read context.md (team history per changed area), then review pr.diff.
            Comment only on real problems and link the sources you relied on.
          claude_args: |
            --max-turns 10
            --allowedTools "mcp__github_inline_comment__create_inline_comment"
```


The PR number and repo reach the script through `env`, never `${{ }}` inside `run`, which is the mistake behind the [Copilot Autofix incident at Snowflake](https://getunblocked.com/blog/copilot-autofix-snowflake-incident/). With `continue-on-error`, the review runs even if the context step fails.

## Or attach the MCP server to Claude Code instead

**Headless Claude Code** is Claude Code running with no person at the keyboard, here inside an Actions job. To let it decide what to ask, pass an MCP config file for the Unblocked server with `--mcp-config` in `claude_args`. The server URL is `https://getunblocked.com/api/mcpsse`, with the token sent as an `Authorization: Bearer` header ([Unblocked headless setup](https://docs.getunblocked.com/unblocked-mcp/install-claude-code)). The action's docs write that file from a secret in an earlier step, to `/tmp/mcp-config.json` ([action configuration docs](https://github.com/anthropics/claude-code-action/blob/main/docs/configuration.md)). They don't say whether a step's `env` reaches Claude, so don't rely on `${VAR}` in it. Add `mcp__unblocked__context_research` to `--allowedTools`.

|  | CLI pre-step | MCP inside the reviewer |
| --- | --- | --- |
| Who picks the questions | Your script | The model |
| Calls per run | Fixed, one per area | Varies; cap with --max-turns |
| Best for | History of changed areas | "Why was it built this way" follow-ups |


Each MCP call counts against a daily limit of 10,000 tool calls per team on team tokens ([Unblocked rate limits](https://docs.getunblocked.com/api-reference/rate-limits)), so tell the prompt to ask once per changed area.

## Where people stay in the loop

Neither route merges or blocks anything; a human decides. For a score instead of comments, Unblocked's risk assessment endpoint takes a PR URL and "does not post comments, reviews, or statuses to the pull request" ([Unblocked API reference](https://docs.getunblocked.com/api-reference/code-reviews/create-risk-assessment)).

"I'm impressed by how well Unblocked understands the context of a PR and delivers genuinely useful feedback. Unlike other tools that focus on typos or some questionable improvements that I often reject, Unblocked consistently surfaces real problems in the code, including hidden bugs," says Agata Grdal, Senior Software Engineer at TravelPerk.

For a hosted reviewer instead, see [giving CodeRabbit or Copilot review team context over MCP](https://getunblocked.com/answers/give-coderabbit-copilot-code-review-team-context-mcp/) and [how the AI code review tools compare](https://getunblocked.com/blog/best-ai-code-review-tools/).

## Read more

- [Best AI Code Review Tools in 2026, Compared](https://getunblocked.com/blog/best-ai-code-review-tools/)
- [The Snowflake Copilot Autofix Incident: An AI Approved Removing a Guardrail Nobody Told It About](https://getunblocked.com/blog/copilot-autofix-snowflake-incident/)

## Related answers

- [What enterprise search works for a 50 to 300 person engineering team when Glean feels like too much?](https://getunblocked.com/answers/enterprise-search-mid-size-engineering-team/)
- [How do we cut ramp-up time for engineers joining a large existing codebase?](https://getunblocked.com/answers/cut-ramp-up-time-large-codebase/)
- [How do I give Claude Code docs for our internal SDK that isn't on the public internet?](https://getunblocked.com/answers/claude-code-docs-internal-sdk/)
- [Which AI assistants answer engineering questions in Slack with links to their sources?](https://getunblocked.com/answers/ai-assistant-engineering-questions-slack-sources/)
