:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(agents): gate local CodeRabbit by run context (#106526)
Paul D'Ambra3b4dfa83e2cd
diff --git a/.agents/skills/reviewing-with-coderabbit/SKILL.md b/.agents/skills/reviewing-with-coderabbit/SKILL.mdindex 12d3b9678f55..5dd78beabbb1 100644--- a/.agents/skills/reviewing-with-coderabbit/SKILL.md+++ b/.agents/skills/reviewing-with-coderabbit/SKILL.md@@ -2,12 +2,11 @@name: reviewing-with-coderabbitdescription: >Run a CodeRabbit review over the branch from the terminal, with the `coderabbit` CLI, and record the- pass in the PR description. Use before `gh pr create`, and whenever a review of a branch is asked for:- a local review, a self-review, a CodeRabbit review, or a pre-PR review. Run it once per branch. Checks- the sign-in state before the review and asks the person whether to sign in or skip, because a- signed-out review opens a browser tab on its own. When the CLI is unavailable, the PR opens without a local pass, and no- agent review takes its place. Trigger terms: coderabbit, cr review, local review, self-review, review- my branch, pre-PR review.+ pass in the PR description. Before `gh pr create` or a requested branch review, first check+ `POSTHOG_TASK_RUN_ID` and `CI`: a cloud or CI task skips this skill without a CLI probe or user message.+ Otherwise, use this skill to check `cr` and its authentication, and offer setup or skip when a person can answer.+ Run the review once per branch. Never substitute an agent review.+ Trigger terms: coderabbit, cr review, local review, self-review, review my branch, pre-PR review.---# Reviewing with CodeRabbit@@ -21,16 +20,14 @@ It still takes time and rate limits still apply, so run it once per branch, afte## Never substitute an agent review-If the CLI is absent or rate limited, or the person chooses to skip the review, **say so and continue to `gh pr create`**.-The PR opens without a local pass.+In cloud and CI tasks, skip the CLI probe and local review without an announcement. Otherwise, offer setup or a skip only if a person can answer. If nobody can answer, the person declines, or the CLI is rate limited, continue without a local pass.Do not run `/code-review`, review subagents, or a fan-out over the diff in its place.The CodeRabbit run is covered by our plan; an agent review of a large diff bills a person's tokens and can reach hundreds of dollars on one branch.## Setup-For a person at the terminal, once per machine.-An agent never runs the sign-in command: it opens a browser.+For a person at the terminal, once per machine. An agent does not run the sign-in command: it opens a browser.Flox activation installs the pinned CLI and puts `coderabbit` and `cr` on PATH.Outside flox, install it with `brew install coderabbit`.@@ -45,30 +42,28 @@ cr auth status # confirms the session and the organization## The flow-1. Finish the work and commit.- The review reads the branch, so uncommitted edits need the matching change-scope flag (`cr review --help` lists them).-2. Check the sign-in state before any review command:+1. Check for a cloud or CI task before loading this skill:```sh- cr auth status --agent+ test -n "${POSTHOG_TASK_RUN_ID:-}" || test -n "${CI:-}"```- It prints one JSON line and never opens anything.- `"status":"authenticated"` means continue to step 3.- `"status":"not_authenticated"` means stop here and ask the person.-- Do not run `cr review` while signed out.- It starts the OAuth login itself: it opens a browser tab at the CodeRabbit sign-in page and blocks until the person completes the login or the command times out.- Ask the person which they want, with `AskUserQuestion` when it is available and a plain question otherwise:+ If the check succeeds, skip the local review and continue the task. Do not probe `cr`, load this skill, or announce the skip.+ `POSTHOG_TASK_RUN_ID` is set in PostHog cloud tasks. Absence of these markers does not prove that a person can answer.+ In any other run, check the CLI and sign-in state:- - **Sign in and run CodeRabbit.**- The person runs `cr auth login` themselves (`! cr auth login` in Claude Code), then tells you it is done.- Re-run `cr auth status --agent` to confirm, then continue to step 3.- - **Skip it this time.**- Skip to step 6, which records why, and continue from there.+ ```sh+ command -v cr >/dev/null 2>&1 && cr auth status --agent+ ```- When nobody can answer, in an unattended run, skip it and record that.+ The status command prints one JSON line and never opens anything. Continue when it succeeds and the JSON status is `authenticated`.+ If the CLI is missing or signed out and a person can answer, ask whether they want to set it up or skip this review.+ The person runs `cr auth login` themselves; the agent can tell them how to install `cr` from Setup.+ After setup, check `cr auth status --agent` again. If they decline or cannot answer, skip to step 6.+ Do not run `cr review` while signed out. It opens an OAuth browser tab and waits for sign-in.+2. Finish the work and commit.+ The review reads the branch, so uncommitted edits need the matching change-scope flag (`cr review --help` lists them).3. Run the review, scoped to the branch's base:```sh@@ -95,7 +90,7 @@ cr auth status # confirms the session and the organization5. Fix what holds, and commit the fixes.6. Record the outcome under Agent context in the PR description, as the PR template asks.After a run, that is whether it ran with `--deep`, and each finding's disposition.- After a skip, that is why: the CLI was absent, signed out, rate limited, or the person chose to skip.+ After a local skip, record why: CLI missing, signed out with no person available, setup declined, or rate limited. Cloud and CI skips need no entry.7. Continue the normal flow: `hogli ci:preflight`, then `gh pr create`.## After the PR opensdiff --git a/.github/pull_request_template.md b/.github/pull_request_template.mdindex ed414b321888..0cccb13ab1f4 100644--- a/.github/pull_request_template.md+++ b/.github/pull_request_template.md@@ -67,7 +67,7 @@<!-- Keep this short: 1-3 short paragraphs or a handful of bullets — not an exhaustive log. Include:- link to session and the tool names used, but do not include tool call results.- skills invoked: always explicitly call out any repo-provided or public skills (e.g. /django-migrations, /improving-drf-endpoints) that were invoked while producing this PR. This helps reviewers judge where and how the code was shaped by an agent.- - CodeRabbit CLI pass: each finding and its disposition (fixed, or rejected with the reason), or that the CLI was unavailable and the PR opened without a local pass. The findings only appeared in the terminal, so this is their only record.+ - CodeRabbit CLI pass (local tasks only): each finding and its disposition (fixed, or rejected with the reason), or why the local pass was skipped (CLI missing, signed out with no person available, setup declined, or rate limited). Cloud and CI skips need no entry. The findings only appeared in the terminal, so this is their only record.- decisions made along the way: what changed across the session. The reason the shipped design beats the obvious alternative goes in Changes instead, where a reviewer will actually see it.- anything else that helps reviewersWrite reviewer-facing prose. Do not paste user prompts verbatim — paraphrase the intent in your own words.@@ -87,7 +87,7 @@- Public OSS repo: no internal customers, incidents, or operational metrics.- Stack instead of stuffing: if the diff holds two or more separable steps (migration then behavior, rename then rewrite), open a stack rather than one big PR. See AGENTS.md, "Stacked PRs" and /stacking-prs.- Simplify before opening: if your agent has a behavior-preserving cleanup pass (Claude Code: `/simplify`), run it on a non-trivial diff before final tests and preflight, since it edits the tree. Skip it for small mechanical changes.-- Review before opening: invoke `/reviewing-with-coderabbit` once over the branch. If the CLI is unavailable, open the PR anyway.+- Review before opening: if `POSTHOG_TASK_RUN_ID` or `CI` is set, skip the local pass without probing `cr`, loading the skill, or announcing the skip. Otherwise invoke `/reviewing-with-coderabbit` to check the CLI and offer setup or a skip when a person can answer. Open the PR either way.- Draft by default: open new PRs as drafts (`gh pr create --draft`) — drafts run only a narrow CI subset and save runner credits. Fix CI and run affected tests locally before marking ready for review.- Labels: apply `skip-agent-review` for trivial/chore PRs that don't need Copilot or Greptile review.- When a human directed the work, the PR must be attributable to that person, even if agent-assisted.diff --git a/AGENTS.md b/AGENTS.mdindex 99cf2b94274d..0ee8f91a3d05 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -285,7 +285,7 @@ ALWAYS invoke the matching skill **first** — do not skip it, and do not attemp- `/writing-user-facing-copy` — writing or editing any text a user reads (UI labels, tooltips, empty/error states, notifications, docs, support replies), or any code change that adds or changes a visible string- `/writing-code-comments` — writing or editing a code comment in any language, or reviewing a diff that adds comments- `/writing-pr-descriptions` — writing or editing any PR body, before `gh pr create` or `gh pr edit --body`-- `/reviewing-with-coderabbit` — before `gh pr create`, and whenever a review of a branch is asked for; when the CLI is unavailable the PR opens without a local pass, never with `/code-review` or review subagents in its place+- `/reviewing-with-coderabbit` — before `gh pr create`, or when a branch review is requested, check `test -n "${POSTHOG_TASK_RUN_ID:-}" || test -n "${CI:-}"` first. If true, skip the local review without probing `cr`, loading the skill, or announcing the skip. Otherwise invoke the skill and, if a person can answer, offer setup or a skip when `cr` is missing or signed out. Never substitute `/code-review` or review subagents.**Invoke when in the area:**