I built agentic-code-reviewer, an open-source tool that reviews GitHub pull requests with a LangGraph agent.
How it works: a GitHub webhook fires when a PR is opened or updated. The agent analyzes the diff for security issues, performance problems, architecture issues and testing gaps, then comments on the PR with line-specific suggestions. Review history is stored in PostgreSQL.
Stack: LangGraph, Node.js + Express, Octokit, PostgreSQL, OpenAI or Claude (configurable). Where I’d like input:
How do you handle diffs that exceed the context window: chunk by file, or summarise first?
I’d chunk by file, not summarise first. Your comments are line-specific, and a GitHub review comment needs a file path and a line in the diff, which a summary throws away.
octokit.rest.pulls.listFiles already gives you one patch per file. Fan those out with Send, one reviewer call per file, and concat the findings with a reducer. A last node then dedupes and posts. If one file’s patch is still too big, split it on the @@ hunk headers. Each header carries its own line numbers, so your comments still map.
You can drop lockfiles and generated code first. Also, listFiles returns 30 files per page (use octokit.paginate), stops at 3,000, and some files have no patch.
Chunk-by-file with Send, then split leftover oversized patches on the @@ hunk headers, is the right default for line-specific review comments.
The gap that approach leaves is cross-file breakage: a renamed export, a changed function signature, or a missing test in another file won’t show up in a per-file patch. After the per-file fan-out, a small second pass that only sees the import graph and the exported typings / signatures (not the full file bodies) usually catches those. The reducer can merge that pass with the file-level findings before you dedupe and post.
If the webhook fires on every synchronize, I’d also skip files whose patch has not changed since the last review commit, and keep the previous comments on those files. That keeps the graph cheap and avoids flooding the PR with repeat suggestions.
One extra step I’d add after the per-file reviewers and before Octokit is a deterministic validation gate. Have each reviewer return structured findings such as `{path, line, side, severity, explanation}`. Validate that the path exists in the fetched PR diff and that the proposed line is actually commentable on the specified diff side. A line inferred from the model’s text alone should never go straight to `createReview`; if it can’t be anchored, put the finding in the overall summary instead.
Also capture the PR’s `head.sha` when you ingest the webhook, then fetch it again immediately before publishing. If the head changed while the graph was reviewing files, discard that run’s comments and review the new revision. Use `(repo, PR number, head SHA, reviewer version)` as an idempotency key for webhook retries and a persisted posting state so `synchronize` events don’t duplicate reviews.
A useful regression test is to push another commit while the per-file reviews are in flight: the old run should post nothing, while the new run should produce comments only on valid changed lines.