CodeNavi in your PR review bot (GitHub Actions / Forgejo Actions)¶
A CI review bot is a coding agent run headless on a runner: a workflow fires on a pull
request, the agent reads the diff, and posts a review. Any bot that can load an MCP
server can use CodeNavi as its eyes on the codebase, and the one tool a reviewer
actually needs, diff_impact, is built for exactly this job.
The bot reads your diff; your codebase never leaves the box. The index, the embedder, the call graph and the search all stay on the CodeNavi host. What leaves is the diff the runner already has and the answers the bot asks for, not the repository. CI review is usually the moment a team first pipes whole repos to a cloud model. With CodeNavi in the loop, the model asks questions about the code instead of reading it.
This page shows the recipe for Anthropic's
claude-code-action on GitHub and its
Forgejo-capable fork on a self-hosted
forge. The same --mcp-config / --allowedTools shape works for any headless agent that
takes Claude Code CLI arguments.
What the bot gets¶
| Tool | Why a reviewer wants it |
|---|---|
diff_impact |
Paste the PR's unified diff → every caller of every symbol the diff touches, test files flagged separately. Blast radius before merge; no competitor's bot has this. |
impact_analysis |
Blast radius of one named symbol (when the diff touches a hub). |
find_callers |
Who calls this function, reverse call-graph lookup. |
semantic_search |
"Is there already a helper for this?", concept search, not grep. |
read_file |
Read the flagged files (lock-free, safe to batch). |
Keep the allowlist to these five plus read-only git diff and git grep. A review bot has no business
reindexing or writing notes; the defaults below give it none of that.
Prerequisites¶
- A running CodeNavi with the PR's repository indexed (
list_codebasesshows its name, a single-codebase install is usuallydefault). CODENAVI_AUTH_TOKENset in the server's.env, never run an unauthenticated endpoint that a runner can reach.- The runner can reach the CodeNavi host: LAN, tailnet, or a tunnel, see remote-access.md. GitHub-hosted runners cannot see your LAN; use a self-hosted runner or a tunnel. Forgejo runners are self-hosted by definition.
- Two repository (or org) secrets:
CODENAVI_URL: e.g.http://codenavi.internal:8765/mcp/myrepo(scoped: every search is pinned to that codebase, whatever the prompt asks for)CODENAVI_AUTH_TOKEN: the bearer token from the server's.envANTHROPIC_API_KEY(or the Bedrock / Vertex / Foundry equivalent the action supports).
The MCP config¶
Both workflows below pass the same JSON to Claude Code's --mcp-config:
{
"mcpServers": {
"codenavi": {
"type": "http",
"url": "${{ secrets.CODENAVI_URL }}",
"headers": { "Authorization": "Bearer ${{ secrets.CODENAVI_AUTH_TOKEN }}" }
}
}
}
The server name codenavi is what the tool names hang off: Claude Code exposes MCP tools
as mcp__<server>__<tool>, so the allowlist names mcp__codenavi__diff_impact and so on.
Rename the server and the allowlist must follow.
GitHub Actions¶
.github/workflows/codenavi-review.yml:
name: CodeNavi PR review
on:
pull_request: # never pull_request_target, see "Keep it quiet and safe"
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore: ['**/*.lock', '**/package-lock.json', '**/pnpm-lock.yaml']
concurrency: # a new push cancels the review of the old one
group: codenavi-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
if: github.event.pull_request.draft == false && !endsWith(github.actor, '[bot]')
runs-on: self-hosted # must reach the CodeNavi host; see Prerequisites
permissions:
contents: read
pull-requests: write
issues: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # full history so `git diff` against the base works
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
use_sticky_comment: true # one comment per PR, updated on each push
prompt: |
Review this pull request using CodeNavi.
1. Run `git diff origin/${{ github.base_ref }}...HEAD` and pass the full
output to mcp__codenavi__diff_impact (depth 2). The CodeNavi index
shows the base branch, not this PR; that is expected.
2. For every non-test file it flags, read_file it and check whether the
change breaks the caller. Use find_callers / impact_analysis on any
symbol marked ⚠ Hub.
3. Use semantic_search once to check whether the diff re-implements
something that already exists.
4. For each env var, config key or route the diff renames or removes,
run `git grep -n <old name>` in this checkout and list every
reference the PR left stale (code, tests, docs, compose, CI config).
5. Post one review comment: blast radius (files + callers), concrete
breakages with file:line, stale references, and a merge/hold
recommendation. At most five findings, highest severity first.
Keep one or two CodeNavi searches in flight, never a burst: they serialize on the GPU.
claude_args: |
--mcp-config '{"mcpServers":{"codenavi":{"type":"http","url":"${{ secrets.CODENAVI_URL }}","headers":{"Authorization":"Bearer ${{ secrets.CODENAVI_AUTH_TOKEN }}","X-CodeNavi-Tools":"diff_impact,impact_analysis,find_callers,semantic_search,read_file"}}}}'
--allowedTools "Bash(git diff:*),Bash(git grep:*),mcp__codenavi__diff_impact,mcp__codenavi__impact_analysis,mcp__codenavi__find_callers,mcp__codenavi__semantic_search,mcp__codenavi__read_file"
--max-turns 25 --model claude-sonnet-5-5
Forgejo Actions (self-hosted forge)¶
Anthropic's action is GitHub-only. The vtmocanu/claude-code-action fork adds native Forgejo support (REST-only, dedicated bot user, platform auto-detection). Two Forgejo-specific facts shape the workflow:
- Forgejo runners pre-fetch every
uses:reference before evaluatingif:, and resolve shortowner/repo@v1refs against the instance's default actions source (code.forgejo.orgby default, which mirrorsactions/checkoutbut not this fork). Mirror the action into your forge and reference it by full URL. - There is no
claude[bot]: create a bot user (claude), give it arepo+user:readtoken, and pass its identity explicitly. The fork'sdocs/forgejo.mdwalks through it.
.forgejo/workflows/codenavi-review.yml:
name: CodeNavi PR review
on:
pull_request: # never pull_request_target, see "Keep it quiet and safe"
types: [opened, synchronize, reopened]
paths-ignore: ['**/*.lock', '**/package-lock.json', '**/pnpm-lock.yaml']
concurrency: # a new push cancels the review of the old one
group: codenavi-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
if: github.event.pull_request.draft == false # Forgejo sets draft for a "WIP:" title
runs-on: ubuntu-latest # a label your registered runner carries
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: https://forge.example.com/actions/claude-code-action@v1 # your mirror
with:
platform: "forgejo" # always explicit; the URL heuristic misfires on GHES
use_sticky_comment: true # declared by the fork; see "Keep it quiet and safe"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.CLAUDE_BOT_TOKEN }}
bot_id: "42" # curl -s https://forge.example.com/api/v1/users/claude | jq .id
bot_name: "claude"
bot_email: "claude@example.com"
prompt: |
Review this pull request using CodeNavi.
1. Run `git diff origin/${{ github.base_ref }}...HEAD` and pass the full
output to mcp__codenavi__diff_impact (depth 2). The CodeNavi index
shows the base branch, not this PR; that is expected.
2. For every non-test file it flags, read_file it and check whether the
change breaks the caller. Use find_callers / impact_analysis on any
symbol marked ⚠ Hub.
3. Use semantic_search once to check whether the diff re-implements
something that already exists.
4. For each env var, config key or route the diff renames or removes,
run `git grep -n <old name>` in this checkout and list every
reference the PR left stale (code, tests, docs, compose, CI config).
5. Post one review comment: blast radius (files + callers), concrete
breakages with file:line, stale references, and a merge/hold
recommendation. At most five findings, highest severity first.
Keep one or two CodeNavi searches in flight, never a burst: they serialize on the GPU.
claude_args: |
--mcp-config '{"mcpServers":{"codenavi":{"type":"http","url":"${{ secrets.CODENAVI_URL }}","headers":{"Authorization":"Bearer ${{ secrets.CODENAVI_AUTH_TOKEN }}","X-CodeNavi-Tools":"diff_impact,impact_analysis,find_callers,semantic_search,read_file"}}}}'
--allowedTools "Bash(git diff:*),Bash(git grep:*),mcp__codenavi__diff_impact,mcp__codenavi__impact_analysis,mcp__codenavi__find_callers,mcp__codenavi__semantic_search,mcp__codenavi__read_file"
--max-turns 25 --model claude-sonnet-5-5
The fork's docs/forgejo.md also lists what Forgejo does not have (no commit signing,
no GraphQL, different webhook event names), none of it affects the CodeNavi part.
The three things that bite people¶
The default tool profile does not list read_file. It lists diff_impact, find_callers,
impact_analysis and semantic_search (before 1.3.73 the default also hid the first three). The
X-CodeNavi-Tools header in both recipes lists exactly the five tools the bot uses, so it calls
them directly and pays for no other tool description (CN-1061). That needs a 1.3.71 server; on an older one, drop the header and start the server the
bot talks to with CODENAVI_TOOL_PROFILE=full.
diff_impactmatches the diff's line numbers against the index. The index must cover the PR's base branch and be fresh. Reindex the codebase (incremental: seconds) on merges to the base branch; a webhook or a cron on the CodeNavi host does it (see webhooks.md). A stale index turns a blast radius into a guess. The result is a lower bound either way, the call graph is name-based and static.- The runner must reach the CodeNavi host, and only the CodeNavi host must be
reachable. Scope
CODENAVI_URLto/mcp/<codebase>so every search is pinned to the PR's codebase, note thatlist_codebasesstill returns every index's name on a scoped endpoint; scoping pins queries, it does not hide the catalog. KeepCODENAVI_AUTH_TOKENa secret, not a variable, and do not put the reindex or note tools on the allowlist. - One or two searches in flight. Searches serialize on their GPU phases; a
burst queues and, past 15 s, returns busy. The prompt says so, and
--max-turnskeeps a runaway review bounded. Measured on a one-line rename PR (laravel testbed, list price): Sonnet 5.5 $0.16 in 8 turns / 26 s; Opus 5.5 $0.38 in 10 turns / 55 s, same findings. The recipe pins Sonnet; a larger diff costs more.
Keep it quiet and safe¶
A review bot that comments on every push gets muted within a week. Both recipes carry the guards below:
- Skip what nobody reads. Draft PRs, bot PRs (Dependabot, Renovate) and lockfile-only
changes get no review (
if:+paths-ignore). On GitHub the review runs when a draft is marked ready (ready_for_review). Forgejo has no such event: a draft is a PR whose title starts withWIP:, removing the prefix triggers nothing, and the review runs on the next push. Forgejo bots are ordinary users with no[bot]suffix, so the Forgejo recipe skips that check; addgithub.actor != 'renovate'(your bot's login) if you run one. - One review per PR, not one per push.
concurrencywithcancel-in-progressdrops the stale run when a new commit lands;use_sticky_comment: trueupdates the bot's one comment instead of posting a new one. The Forgejo fork declares the same input; if it does not hold on your forge, tell the bot in the prompt to find and edit its own previous comment. - Few findings, ranked. The prompt caps the comment at five findings. Raise it only if your team asks for more.
- Never use
pull_request_targetfor this job. It runs fork PRs with the base repo's secrets and a write token. The diff is untrusted text handed to an agent that can post to your PR: a fork could put instructions in a code comment and the bot would act on them with yourCODENAVI_AUTH_TOKENand API key in scope. CodeNavi scans what it indexes for prompt injection; a PR diff is never indexed, so that scan does not cover it. Plainpull_requestgives fork PRs no secrets, so on a fork the job fails at the CodeNavi connection and reviews nothing, which is the safe outcome. Forgejo adds a gate before that: a fork PR's workflows wait on a trust panel on the PR (Deny / Approve once / Approve always). Use Approve once, which asks again for every new commit; never Approve always for someone you would not give write access.
Verified on Forgejo 15.0.7 with forgejo-runner v13.2.1 (2026-11-16, stub jobs in place of
the review step): a lockfile-only PR started no run; a second push within a minute cancelled
the first run; a WIP: PR's job was skipped; base-repo runs saw the repository secret; a
fork PR waited for approval, also after that user's earlier PR was merged, and once approved
its run saw the repository secret as empty. Forgejo reports
the push event as synchronized; listing synchronize matches it.
Verify before wiring the workflow¶
Run the same thing from a shell on the runner (or any box that can reach the host), if this works, the workflow will:
export CODENAVI_URL=http://codenavi.internal:8765/mcp/myrepo
export CODENAVI_AUTH_TOKEN=...
claude -p "call list_codebases, then run diff_impact on this diff: $(git diff HEAD~1)" \
--mcp-config "{\"mcpServers\":{\"codenavi\":{\"type\":\"http\",\"url\":\"$CODENAVI_URL\",\"headers\":{\"Authorization\":\"Bearer $CODENAVI_AUTH_TOKEN\"}}}}" \
--allowedTools "mcp__codenavi__list_codebases,mcp__codenavi__diff_impact"
Verified run (laravel testbed, one-line hunk inside Str::snake): diff_impact at depth 2
returned 156 affected files, 79 code, 77 test, with the Eloquent relation/foreign-key
hubs flagged, and the review correctly noted the hunk was comment-only so the realistic
test set was SupportStrTest + SupportStringableTest. Wide radius on a trivial hunk is
expected: it is the static lower-bound the reviewer then narrows.
Verified run of the prompt above (2026-11-15, claude -p with the recipe's allowlist, laravel
testbed): a PR renaming REDIS_HOST to REDIS_HOSTNAME in config/database.php only.
diff_impact found no symbols (config arrays have no call graph, and the bot reported impact
as unknown, not zero); step 4's git grep found all 20 stale references in 6 files, including
phpunit.xml.dist, the InteractsWithRedis test trait and bin/test.sh, and the bot
recommended hold with a env('REDIS_HOSTNAME', env('REDIS_HOST', ...)) fallback. Step 4 uses
git grep, not CodeNavi's grep_search, because the runner's checkout is the PR branch and
covers every tracked file, while grep_search reads the indexed base and skips file types
the index does not take (.dist, for one).
Verified run with the X-CodeNavi-Tools header (2026-11-15, dev server at 1.3.71 code, same
allowlist, laravel testbed, a PR changing Str::limit's default $end from '...' to '…'):
the bot's tool list held exactly the five CodeNavi tools, it called diff_impact and the hidden
find_callers directly with no reveal step, and it recommended hold. It found the seven
SupportStrTest assertions that now fail and that Stringable::limit keeps the old default.
diff_impact listed 58 files because it matches limit by name (query-builder ->limit() calls),
and the bot filtered those out. 9 turns, $0.17 with Sonnet 5.5.
Rerun the same day after CN-1062: diff_impact listed 2 files (Stringable.php,
SupportStrTest.php) and the 57 query-builder calls apart, as method-name-only matches. The bot
named the 2 and set the 57 aside without reading them, and also found the stale '...' defaults in
Str::words/Stringable::words and two more failing test files. 10 turns, $0.17.
A 401 means the token does not match the server's .env; an Unknown codebase error
means the /mcp/<name> scope is wrong, list_codebases on the unscoped /mcp shows the
real names. Full status codes: api-reference.md.
Other headless agents¶
The recipe is not Claude-specific. Any agent that runs headless and loads MCP servers from
a config file works the same way, the only thing that changes is the config shape
(Codex: ~/.codex/config.toml with bearer_token_env_var; Antigravity: serverUrl +
literal token; see connecting-codex.md and
connecting-antigravity.md). Give the bot the same five tools
and the same prompt.