# Turn Labeled GitHub Issues Into Pull Requests for a Next.js App

Yes. Label a GitHub issue on a Next.js monorepo and an agent finds the workspace it concerns, reproduces it, fixes it and opens a pull request closing the issue.

[Run this on Rush](https://cloud.getrush.ai/run/github-issue-to-pr/nextjs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The run starts from the labelled issue. An automation's `github` trigger on `issues.labeled` adds the issue event after the prompt, and the repository in `resources` is cloned through your GitHub App installation, so the agent reads the report and its comments before it opens a file. In a monorepo like documenso/documenso the first decision is which workspace the report is about. The root `package.json` declares npm workspaces under `apps/*` and `packages/*`, pins `npm@11.19.1` and Node 24 or newer, and runs everything through Turborepo. Two of its apps are Next.js: `apps/docs`, the documentation site on `next` 16.3 with Fumadocs (`fumadocs-core`, `fumadocs-mdx`, `fumadocs-ui`), and `apps/openpage-api`, a Next.js app that is only route handlers over `@documenso/prisma`. The signing product itself lives in `apps/remix` on React Router, so a report about signing goes elsewhere, and the agent says so in the pull request rather than guessing.

A docs report leads into `apps/docs/content/docs`, where every page is MDX under `users`, `developers`, `self-hosting`, `concepts`, `compliance` and `policies`, ordered by each folder's `meta.json`. `apps/docs/src/lib/source.ts` builds the Fumadocs loader with `baseUrl: '/docs'`, and `src/app/docs/[[...slug]]/page.tsx` renders a page from `source.getPage(params.slug)`, calls `notFound()` for a slug the loader does not know, and builds metadata and an Open Graph image path from the page's slugs. `src/app/sitemap.ts` lists every page the loader returns, `robots.ts` points at it, and `llms.txt`, `llms-full.txt` and `llms.mdx` routes serve the same content as text. A wrong link, a page missing from the sidebar, a stale `description` or a broken Mermaid block is therefore either a content fix in one MDX file, a `meta.json` ordering change, or a change in these few source files, and the repository's `WRITING_STYLE.md` sets the tone the fix must keep.

An openpage-api report is about numbers. `apps/openpage-api/app/growth/route.ts` lists seven routes such as `total-users`, `new-users` and `completed-documents`; each handler, for example `app/growth/new-users/route.ts`, calls a function in `lib/growth/` and returns JSON with `Cache-Control: public, s-maxage=3600, stale-while-revalidate=7200` through the wildcard CORS helper in `lib/cors.ts`. `lib/growth/get-user-monthly-growth.ts` runs a Kysely query that groups `User.createdAt` by month with a cumulative window sum, formats labels as `MMM yyyy` with Luxon, and hands the result to `lib/add-zero-month.ts`, which prepends a zero month and appends the current month. A report of an off-by-one month, a missing current month or a cumulative total that drops goes to one of those three files, and the agent reproduces it first: it starts the `postgres:15` from `docker/development/compose.yml`, runs `npm run prisma:migrate-dev` and `npm run prisma:seed`, starts the app with `npm run dev:openpage-api` on port 3003 and requests the route.

The fix follows the repository's own rules. `AGENTS.md` asks for `type` over `interface`, functional components, no `'use client'` directive and no one-line `if`, and it says not to run `npm run build` at the root because it takes minutes; the agent runs `npm run types:check -w @documenso/docs` (which is `fumadocs-mdx && next typegen && tsc --noEmit`) or `npx tsc --noEmit` in the app it touched, and `npm run lint`, which is `biome check .` with a 120-column line width. The branch follows `CONTRIBUTING.md`'s `feat/doc-999-short-name` pattern with the issue number, and the pull request title follows Conventional Commits because `semantic-pull-requests.yml` rejects any other title.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Fix the GitHub issue that follows this prompt in this monorepo. Read the issue and its comments first, then the root package.json, turbo.json and AGENTS.md. Decide which workspace the report concerns: apps/docs (Next.js with Fumadocs, MDX under apps/docs/content/docs) or apps/openpage-api (Next.js route handlers over Prisma). If the report is about the signing app under apps/remix, stop and say so in a comment instead of changing it. Install with npm ci --no-audit and run npm run prisma:generate as .github/actions/node-install does. For a docs report, find the MDX file, meta.json or file under apps/docs/src that produces the problem, fix it in the voice WRITING_STYLE.md describes, and run npm run types:check -w @documenso/docs and npm run build -w @documenso/docs. For an openpage-api report, start the Postgres named in docker/development/compose.yml, run npm run prisma:migrate-dev and npm run prisma:seed, start the app with npm run dev:openpage-api, request the route to reproduce the wrong output, fix the function under apps/openpage-api/lib, request it again and quote both responses. Run npm run lint and fix what Biome reports in files you changed. Do not run npm run build at the root and do not touch apps/remix, package-lock.json or any workflow. Open a pull request on a branch named with the issue number, with a Conventional Commits title, whose body starts with Closes and the issue number, explains the cause in one paragraph, lists the files and quotes the commands you ran with their output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that touches one workspace. For a docs issue that is an MDX file or two under `apps/docs/content/docs`, sometimes a `meta.json`, rarely `src/lib/source.ts` or the `[[...slug]]` page; for a metrics issue it is one file under `apps/openpage-api/lib` and, where the route's headers or CORS were the cause, the route handler. Nothing under `apps/remix`, `packages/` or `.github/` changes, and `package-lock.json` is untouched.

The description starts with `Closes #<n>`, names the workspace, explains the cause in a paragraph, and quotes what the agent ran: `types:check` for the docs app, `biome check`, and for the API the two JSON responses from port 3003 before and after the change. The title passes the Conventional Commits check, so the `Validate PR Name` workflow goes green with the rest of CI.

A reviewer reads the cause paragraph against the issue, opens the diff to confirm it stays inside one workspace, and checks the quoted output against the claims. The run's transcript holds every command, so a doubtful step can be replayed before merging.

## Run it on every GitHub issue labelled for the agent

Add an automation to the Project with this prompt and a `github` trigger on `issues.labeled`, with the label you reserve for the agent in `config.labels` and, if you want to limit who may hand work off, the maintainers' GitHub logins in `config.authors`. The trigger adds the issue event after the prompt and fills in nothing, so the agent reads the number from the event. Only a label applied by an owner, member or collaborator fires it, and the automation's `max_runs_per_hour`, between 1 and 30, bounds how many issues it takes on in an hour; each one runs in its own sandbox and opens its own pull request.

From your own server instead, a handler that receives GitHub's `issues` webhook sends `POST /o/{org}/sessions` when the label matches, with the issue number written into `input` and a `request_id` that is a UUID v5 of the delivery id, so a redelivered webhook returns the run it already started rather than a second one. Give that key a `webhook_url` and Rush POSTs `run.completed`, `run.failed` or `run.cancelled` when the turn ends, signed per Standard Webhooks, with `data.session_url` to read for the pull request.

## Why run it on Rush?

A monorepo like this one needs Node 24, an npm workspace install, a Prisma client generated before anything type-checks, and for the metrics app a Postgres with migrations and seed data. That is an afternoon on a laptop that is not already set up, and it is why small docs and metrics issues sit. The sandbox does the whole setup per issue, runs the app's own `types:check` and Biome, and keeps the output in the transcript.

The result is a pull request that closes the issue with the cause and the evidence written down, not a patch with a note to try it. Several labelled issues become several runs at once, each on its own branch, and the pull request a reviewer disagrees with is closed without undoing anything else.

## Frequently asked questions

### The signing app in this repository is not Next.js. What does the agent do with an issue about it?

It stops. The prompt tells it to comment and leave the code alone when the report is about `apps/remix`, which runs on React Router and Hono. The page is for the two Next.js workspaces, the Fumadocs site and the metrics API; a monorepo with one Next.js app is the simpler case of the same prompt.

### Will it run the whole Playwright suite?

No. `e2e-tests.yml` builds the signing app and runs `packages/app-tests` against it with Postgres, Redis, Inbucket and Gotenberg from the compose file, which has nothing to do with a docs or metrics fix. The agent runs the checks that cover the workspace it changed: `types:check`, a build of that one app, Biome, and for the API a live request before and after.

### Does it follow the repository's pull request rules?

Yes. The title follows Conventional Commits because `semantic-pull-requests.yml` fails any other title and comments on the pull request; the branch carries the issue number as `CONTRIBUTING.md` asks; the code follows `AGENTS.md`: `type` over `interface`, no `'use client'`, no one-line `if`. CONTRIBUTING.md also says the maintainers are not accepting external pull requests, so on this repository the run makes sense on your own fork or your own monorepo, not upstream.

### What if the metrics route is right and the issue is wrong?

The reproduction decides. If the request to port 3003 returns what the code is meant to return, the agent says so with the response quoted, explains the behaviour of `add-zero-month.ts` or the cumulative window, and opens no pull request. A comment with evidence is a better outcome than a change that makes a correct number wrong.

## More Next.js jobs

- [Find Why Signups Dropped in a Next.js App](https://getrush.ai/run/investigate-conversion-drop/nextjs/)
- [Investigate a Sentry Error Spike in a Next.js App](https://getrush.ai/run/investigate-sentry-spike/nextjs/)
- [Investigate Slow API Routes in a Next.js App](https://getrush.ai/run/investigate-slow-api-routes/nextjs/)

## The same job on other stacks

- [Turn Labeled GitHub Issues Into Pull Requests for a Phoenix App](https://getrush.ai/run/github-issue-to-pr/phoenix/)
- [Turn GitHub Issues into Pull Requests for a Python Project](https://getrush.ai/run/github-issue-to-pr/python/)
- [Turn Labeled GitHub Issues Into Pull Requests for a Rails App](https://getrush.ai/run/github-issue-to-pr/rails/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
