# Code review in CI

> Review a pull request diff with zelk exec and post the structured findings from a separate GitHub Actions job.

Use this example to review a pull request diff for regressions and post a
summary with file and line references. The review runs on Linux. The result
is advisory and can be checked against the patch before anyone acts on it.

## Keep the inputs and jobs separate

The workflow checks out the trusted base commit and builds zelk at a
maintainer-selected commit. It fetches the PR ref only to compute a diff and
checks that it matches the event's head SHA. External diff and text conversion
drivers are disabled. The PR contributes patch bytes, while the base commit
supplies the scripts and schema.

The review script uses a fresh workspace and config directory, read-only
`plan` mode, `-input deny`, and bubblewrap with `-network off`. The model API
key is available for the review step, and the CLI sends the diff to the model
provider. The review refuses input over the CLI's 1 MiB stdin limit.
The workflow captures raw diagnostics in a runner-local file and prints a
fixed failure message so model-derived text stays out of the runner's
workflow command processor. The posting job runs only after a successful
review job and reads its JSON artifact. The posting step holds the write token and formats model strings
as indented code before posting a comment against the reviewed commit.

## Workflow

[Workflow source](https://github.com/barevoidco/zelk/blob/main/examples/cireview/workflow.yml)


## Build, review and output schema

[Scripts and schema source](https://github.com/barevoidco/zelk/tree/main/examples/cireview)




The script's `exec` variant passes the task as an argument and the diff as
stdin context. The `print` variant feeds both the task and diff through
stdin and pipes the JSON through `jq`. Its task counts toward the same
1 MiB limit. Both variants fail if zelk exits nonzero.

## Adapt it

1. In a public repository, place the workflow under `.github/workflows/`
   and put `build-zelk.sh`, `review.sh` and `review.schema.json` in
   `examples/cireview/` of that repository: the workflow runs
   `bash examples/cireview/build-zelk.sh` and `review.sh` from there. Land
   them on a maintainer-controlled branch. Keep the checkout ref and all executable
   inputs under maintainer control.
2. In the repository's Actions settings, add two **variables** (`vars.`):
   `ZELK_COMMIT`, the full 40-character SHA of a reviewed zelk commit, and
   `ZELK_REVIEW_MODEL`, a model served by your provider. Add two **secrets**:
   `ZELK_REVIEW_API_KEY`, the provider's key, and `ZELK_REVIEW_POST_TOKEN`, a
   separate token with Pull requests write access to this repository. The
   pinned commit must be reachable on GitHub: `build-zelk.sh` fetches it from
   `github.com/barevoidco/zelk` by SHA, so a commit that exists only in your local
   clone, or that the repository doesn't have, fails the build step. Update
   the CLI provider flags and secret mapping together if you use a different
   provider.
3. Check the repository's Actions event policy before enabling the workflow.
   GitHub can block `pull_request_target` in public repositories. Review
   GitHub's guidance before allowing it.
   [GitHub's pull_request_target security guidance](https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target)
4. To run locally, use Linux with Go, bubblewrap and jq. Run the build script
   with the pinned SHA and an absolute output path. Set `OPENAI_API_KEY` and
   `ZELK_REVIEW_MODEL`, then run the review script with `exec` or `print`,
   the binary path and a local diff file. Review which repositories may send
   patches to your provider before deploying the workflow.
5. Change the prompt, schema and posting formatter together if you need
   different fields. Keep the posting token scoped to this repository's reviews.

See [Print mode and exec](/cli/print-and-exec/#in-ci) for exit statuses and
platform sandbox defaults.
