> For the complete documentation index, see [llms.txt](https://pharaoh.so/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pharaoh.so/docs/guides/pr-guard.md).

# Set Up PR Guard

PR Guard runs automated structural checks on every pull request. It catches unreachable exports, regression risk, test gaps, and breaking changes before they merge. The same analysis you get from Pharaoh's tools, applied automatically on every push to a PR branch.

## The workflow

### 1. Enable PR Guard

Ask your AI tool:

```
Enable PR Guard on my-org/my-repo.
```

This calls `pharaoh_account` with `enable_pr_guard`. PR Guard activates immediately for the specified repo.

### 2. Open a pull request

Push a branch and open a PR as usual. Pharaoh runs checks automatically via the GitHub Checks API. No workflow files, no CI config, no manual triggers.

The checks cover:

* **Unreachable exports** - new functions or exports that aren't wired to any production entry point (HTTP handler, cron job, CLI command)
* **Regression risk** - functions in the diff scored by complexity, caller count, churn, and exposure
* **Test coverage gaps** - changed or added functions that lack test files
* **Breaking changes** - modifications to shared functions that have callers in other modules

### 3. Read the results

Results appear as a GitHub Check on the PR. The summary shows:

* Total findings by category
* Per-function details with risk scores
* Specific callers affected by the changes

Click into the check details for the full per-function analysis.

### 4. Iterate

PR Guard re-runs on every push to the PR branch. Fix a finding, push, and the check updates. No manual re-trigger needed.

### 5. Disable if needed

Ask your AI tool:

```
Disable PR Guard on my-org/my-repo.
```

This calls `pharaoh_account` with `disable_pr_guard`.

## What to look for

* **Unreachable exports** - the most common structural defect in PRs. Code that compiles and passes unit tests but is never called from any production path. This happens when someone adds a function and forgets to register it with a router or export it from a barrel file.
* **HIGH regression risk** - functions in the diff with high complexity, many callers, and recent churn. These deserve line-by-line review. LOW risk functions with no external callers can be approved faster.
* **Test gaps on changed functions** - modifying a function without updating or adding tests is a risk signal. PR Guard flags it so the reviewer can decide whether to require coverage.

## Tips

* Enable PR Guard on your most active repos first. High-churn repos produce the most PRs and benefit most from automated structural checks.
* PR Guard is a Pro add-on. Free tier shows preview results (non-blocking) so you can evaluate before upgrading. Pro gets full blocking checks - the PR can't merge until findings are addressed.
* Findings are per-function, not per-file. A PR touching 10 files might only flag 2 functions - the ones with high caller counts or missing tests.
* PR Guard checks complement but don't replace human review. Structural analysis catches wiring and risk issues. Code logic, naming, and design decisions still need a human.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pharaoh.so/docs/guides/pr-guard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
