# Turn Linear Issues into Pull Requests for a Next.js App

An agent lets a team owner rename the team from a Next.js app's Team page, logs it as activity, and adds one Vitest test that passes against a real Postgres.

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

## What the agent does

Before changing anything the agent reads `app/(dashboard)/dashboard/page.tsx`, the actions in `app/(login)/actions.ts`, `lib/auth/middleware.ts`, `lib/db/queries.ts` and the `ActivityType` enum in `lib/db/schema.ts`, and runs the baseline. `pnpm build` already fails there, prerendering `/pricing` with `Invalid API Key provided: sk_test_*ummy` from Stripe.

It adds `getTeamMemberRole` to `lib/db/queries.ts`, an `updateTeamName` action that checks the caller's `team_members.role` on the server, an `UPDATE_TEAM_NAME` activity with its icon on the Activity page, and a Team name card that non-owners see without the form. There is no migration: `UPDATE_TEAM_NAME` is stored as plain text in `activity_logs.action`.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Do the work the Linear issue given as a resource describes: let a team owner rename the team from the settings page. Read the issue and its comments first. Follow this app's patterns: a zod schema and a validatedActionWithUser server action in app/(login)/actions.ts, a Drizzle update in lib/db, an ActivityType entry logged through logActivity, and a card on the Team page with the existing Input and Button components and useActionState. Only members whose role is owner may rename. Run pnpm db:migrate against a local Postgres, then pnpm build and tsc --noEmit, and exercise the page in the browser. If the project has no test runner, add Vitest with one test for the new action rather than a full harness. Open a pull request whose description links the issue and quotes the build result. Do not merge.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    },
    {
      "url": "https://linear.app/your-org/issue/ENG-42"
    }
  ]
}
```

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

Tried on nextjs/saas-starter at 6e33e58: 9 files changed, 858 insertions(+), 6 deletions(-), 607 lines of it in `pnpm-lock.yaml` from adding Vitest. The issue was written for this trial and appended after the request in place of a Linear issue. `npx tsc --noEmit` exited 0, and the new `pnpm test` ended `Tests  1 passed (1)` against an embedded Postgres 17 the run installed from npm. `pnpm build` exits 1 on `/pricing` before and after the change, because the `.env` the run wrote holds a dummy Stripe key; with `export const dynamic = 'force-dynamic'` added to that page, a temporary edit it reverted, the build exited 0.

For the reviewer: run the build in CI with a real Stripe test key. The Activity page lists only the current user's entries, so a rename shows only to the owner who made it; the run left that unchanged.

## Run it on every Linear issue labeled agent

An automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` runs the recipe's issue-neutral prompt with the labelled issue as its context.

## Why run it on Rush?

The build was already red in this sandbox, on the dummy Stripe key the run wrote, and the run said so. It checked the rest separately: a temporary `force-dynamic` build, reverted before the diff, and a Vitest test that mocks only `cookies()` from `next/headers` while hitting real Postgres for the member refusal, a 101-character name, trimming and the activity row.

## Frequently asked questions

### Is the owner rule checked on the server?

Yes. `updateTeamName` reads the role from `team_members` for the caller's own team, not `users.role`, so a forged form post from a member is rejected. The run noted that `inviteTeamMember` has no such check, and left it.

### What did the browser run show?

Signed up as an owner, the run saw the Team name card, saved a rename and got "Team name updated successfully.", and the Activity page listed "You renamed the team". A second user with the `member` role saw the name and no form.

## More Next.js jobs

- [Upgrade a Next.js App to Tailwind CSS v4](https://getrush.ai/run/migrate-tailwind-v4/nextjs/)
- [Plan a Linear Issue Against a Next.js Codebase](https://getrush.ai/run/plan-linear-issues/nextjs/)
- [QA a Next.js App in a Real Browser](https://getrush.ai/run/qa-in-browser/nextjs/)

## The same job on other stacks

- [Turn Linear Issues Into Pull Requests for a Nuxt App](https://getrush.ai/run/linear-issue-to-pr/nuxt/)
- [Turn Linear Issues Into Pull Requests for a Phoenix App](https://getrush.ai/run/linear-issue-to-pr/phoenix/)
- [Turn Linear Issues Into Pull Requests for a Rails App](https://getrush.ai/run/linear-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/)
