Tutorials
How to Automate Next.js Upgrades with GitHub Actions Using next upgrade --ci
Next.js 16.5 RC introduces next upgrade --ci, which prepares scheduled framework upgrades through GitHub Actions. Learn how to configure upgrade policies, agent credentials, and pull request reviews.
A Next.js application can remain on the same framework version for months without anyone noticing.
Eventually, an update becomes necessary. Sometimes because of a security advisory, sometimes because a newer release introduces changes the project needs.
Updating the dependency itself is usually straightforward. The less predictable part comes afterward: migration changes, deprecated APIs, modified configuration, and tests that no longer pass.
On November 28, 2026, Next.js released 16.5.0-rc.0, introducing a new option for its upgrade CLI:
next upgrade --ci
The command prepares a GitHub Actions workflow that periodically checks for Next.js updates and uses a hosted coding agent to perform migrations when necessary.
Rather than modifying the main branch automatically, the workflow proposes changes through pull requests.
There is one detail worth understanding before configuring it: this feature is still experimental, and its first public release is a Release Candidate.
What does next upgrade —ci actually create?
The command does not immediately upgrade the application.
It first prepares the automation itself.
After checking the repository and asking for your preferences, the CLI creates a setup pull request containing:
.github/workflows/next-upgrade.yml
The workflow references Vercel’s next-upgrade-action, pinned to a specific commit.
Once the setup PR is reviewed and merged, GitHub Actions can begin checking for available updates.
If an upgrade is required, a hosted agent modifies the application, attempts to verify its changes, and opens another pull request.
These are two separate pull requests with different purposes.
flowchart TD
A["Run next upgrade --ci"] --> B["Setup pull request"]
B --> C["Review and merge"]
C --> D["Scheduled GitHub Actions run"]
D --> E{"Upgrade available?"}
E -->|No| F["Stop"]
E -->|Yes| G["Coding agent runs migration"]
G --> H["Upgrade pull request"]
H --> I["Review, tests and merge decision"]
The setup PR establishes the automation.
The upgrade PR contains the actual code changes.
Nothing in this process requires automatically merging an AI-generated migration into production.
1. Check whether your project is supported
The initial implementation has narrower requirements than the general Next.js upgrade command.
It supports standalone Next.js applications using npm, pnpm, or Yarn Classic (Yarn 1).
The application needs a single committed lockfile alongside its package.json.
For example:
my-next-app/
├── app/
├── package.json
├── pnpm-lock.yaml
└── next.config.ts
The repository must already exist on GitHub.com, with an origin remote pointing to it.
The lockfile must be committed to the repository’s default branch.
Currently unsupported configurations include:
| Configuration | Supported |
|---|---|
| Standalone npm project | Yes |
| Standalone pnpm project | Yes |
| Yarn 1 project | Yes |
| Monorepo using workspaces | No |
| Yarn 2 and newer | No |
| Bun | No |
Both App Router and Pages Router applications are supported.
The restriction is primarily about how the scheduled workflow identifies and installs a single application, not which Next.js routing system the application uses.
Before continuing, check the repository:
git remote -v
git status --short
Make sure the relevant project files and lockfile have been committed.
Also install the GitHub CLI if it is not already available.
Check authentication:
gh auth status
If necessary, sign in:
gh auth login
The authenticated account needs permission to push changes and create workflow files in the repository.
2. Run the new upgrade setup command
From the application’s directory, execute:
npx [email protected] upgrade --ci
This runs the CLI from the published 16.5 Release Candidate.
It does not mean your application’s installed next dependency must already be version 16.5.
The CLI examines the existing project before preparing the workflow.
You can also choose the update policy directly.
For security updates:
npx [email protected] upgrade --ci security
For new stable versions:
npx [email protected] upgrade --ci latest
The two policies behave differently.
security looks for updates required by relevant security advisories.
latest checks for new stable Next.js releases.
Neither policy means every workflow run will modify the application.
If no applicable upgrade exists, the workflow stops without starting a coding agent.
For most production applications, security-only upgrades may be a reasonable initial choice because they limit how frequently migrations are proposed.
3. Choose the coding agent
During setup, the CLI asks which hosted coding agent should perform the upgrades.
The initial implementation supports:
- Codex with an OpenAI API key.
- Claude Code with an Anthropic API key.
It may also ask you to choose the agent’s model and reasoning effort.
Those settings determine the agent configuration saved in the generated workflow.
The agent is responsible for more than changing a version number.
When an upgrade is available, it receives migration instructions and attempts to update the application accordingly.
That may involve changing configuration, applying documented migrations, and running appropriate verification commands.
However, the presence of an AI agent does not guarantee that every migration will be correct.
The resulting changes still need to be reviewed and tested.
There is also a cost consideration: using a hosted agent requires the corresponding provider’s credentials, and API usage may incur charges.
4. Review the generated GitHub Actions workflow
The setup PR introduces a workflow resembling the following:
name: Next.js upgrade
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
upgrade:
uses: vercel/next-upgrade-action/.github/workflows/next-upgrade.yml@<commit-sha>
with:
policy: security
agent: codex
next-version: 16.5.0-rc.0
app-path: .
secrets:
agent-credential: ${{ secrets.NEXT_UPGRADE_AGENT_CREDENTIAL }}
publish-token: ${{ secrets.NEXT_UPGRADE_PUBLISH_TOKEN }}
This is a simplified illustration. The actual generated workflow contains additional settings, including the selected model and related configuration. The commit SHA must be the real value generated by the CLI, not the placeholder above.
There are several interesting details.
First, the reusable workflow is pinned to a specific commit rather than a moving branch.
That reduces the risk of automatically executing an unexpected newer version of the workflow.
Second, the generated configuration records the Next.js CLI version used during setup.
Third, the default schedule is daily:
schedule:
- cron: "0 0 * * *"
The cron expression uses UTC.
You can change it later if daily checks are unnecessary.
The workflow_dispatch trigger also allows the workflow to be started manually from GitHub Actions.
Most importantly, the workflow does not automatically install a new Next.js version every day.
It first checks whether an upgrade is needed under the configured policy.
5. Configure the required GitHub secrets
The workflow uses two repository secrets.
| Secret | Purpose |
|---|---|
NEXT_UPGRADE_AGENT_CREDENTIAL |
Authenticates the selected coding agent |
NEXT_UPGRADE_PUBLISH_TOKEN |
Allows the workflow to publish upgrade branches and pull requests |
For Codex, the first secret contains an OpenAI API key.
For Claude Code, it contains an Anthropic API key.
The second secret requires a GitHub fine-grained personal access token.
According to the Next.js implementation, that token should be restricted to the target repository and have read/write access to Contents and Pull requests.
You can create it from GitHub’s fine-grained token settings.
Avoid giving the token access to every repository when it only needs to publish upgrades to one application.
The setup CLI can guide you through registering both secrets.
Alternatively, add them under:
Repository Settings → Secrets and variables → Actions
You can also use GitHub CLI:
gh secret set NEXT_UPGRADE_AGENT_CREDENTIAL
gh secret set NEXT_UPGRADE_PUBLISH_TOKEN
These commands prompt for the secret values.
Do not put the credentials directly into the workflow YAML or commit them to the repository.
A related operational detail is token expiration.
When the fine-grained personal access token expires, the workflow may no longer be able to publish upgrade pull requests.
The token therefore needs to be renewed or replaced before its expiration date if the automation is expected to continue running.
6. What happens during a scheduled run?
Once the setup PR is merged, GitHub Actions can execute the workflow.
The first check concerns existing upgrade work.
If an earlier upgrade pull request is still open, the workflow stops rather than generating another competing migration.
Otherwise, it checks for an available update.
If the current application already satisfies the chosen policy, the run ends without invoking the hosted agent.
If an upgrade is available, the agent attempts to perform it and publishes a pull request containing the proposed changes.
This keeps the actual application update separate from the scheduled check.
It also prevents the workflow from repeatedly creating upgrade PRs while an earlier proposal remains unresolved.
After the first setup, you can manually test the workflow through:
GitHub → Actions → Next.js upgrade → Run workflow
Running it manually follows the same general checks. It does not force an upgrade when no matching target is available.
7. Review the upgrade PR before merging
An automated migration should be reviewed like any other dependency upgrade.
Start with the dependency changes and the lockfile.
Then inspect configuration changes, deleted or renamed APIs, and any modifications to application behavior.
A successful build is useful evidence, but it does not establish that the application behaves exactly as intended.
A migration might compile while changing routing, caching, authentication, or request handling.
For a production repository, the upgrade PR should pass the project’s normal CI checks and any required branch-protection rules.
It is also worth inspecting the automation itself before merging the original setup PR.
The workflow executes an external reusable workflow and grants a hosted agent access to the repository’s code and its configured credentials.
Confirm that the referenced commit belongs to the expected repository, the token permissions are appropriately restricted, and the generated workflow does not expose secrets to unrelated jobs.
The setup being generated by an official CLI does not remove the need to inspect what will run in your repository.
What if the CLI refuses to configure the project?
Several problems can prevent setup.
A missing committed lockfile is one example.
A workspace-based monorepo is another.
The CLI may also reject a project when the Git remote is not hosted on GitHub.com or when the current GitHub account cannot create workflow files.
If GitHub CLI authentication is missing, run:
gh auth login
If GitHub CLI lacks the required workflow scope, its authentication can be refreshed:
gh auth refresh -h github.com -s workflow
Do not try to bypass the package-manager restrictions by copying an arbitrary generated workflow into an unsupported monorepo.
The automated upgrade action needs to understand where the application lives, which lockfile controls installation, and which commands should be used to modify and verify dependencies.
The current implementation deliberately limits those combinations.
Support for more complex repository structures may change in later releases.
Is this ready for production?
The new command is available in Next.js 16.5.0-rc.0, released November 28, 2026.
That is not the final stable 16.5 release.
Next.js also labels the agent-based upgrade functionality as experimental and subject to change.
So the new automation is more appropriate for evaluation than for immediate adoption across critical repositories without additional review.
Still, it addresses a real maintenance problem.
Dependency update notifications tell developers that a new version exists. They do not necessarily perform migrations, resolve compatibility issues, or verify that the application still works.
next upgrade --ci adds an automated path for preparing those changes.
It also retains an important boundary: the agent proposes an upgrade through a pull request rather than silently changing the main branch.
The new feature does not eliminate the need to maintain a Next.js application.
It changes how upgrade work is initiated and prepared.
For supported standalone projects, that can reduce repetitive maintenance while leaving the final decision about merging each update with the repository’s maintainers.