Quickstart
Add Morph to a Next.js app with one command, then see it in your app.
1. Set it up#
In your app's folder:
npm init usemorph@latest
Answer y when it shows you the plan. It signs you in with GitHub (the first time), creates your Morph app, and adds Morph to your code.
2. Try it#
npm run dev
Sign in to your app and open a page. The Morph box is in the bottom-right corner. Ask for something:
- "Put the chart on top at full width."
- "Make the sidebar text bigger."
- "Add a notes box I can jot things down in."
Undo goes back one change, Reset goes back to your original app, and Code shows what the AI wrote.
3. Go live#
Once, when you deploy:
- Add
MORPH_SECRET_KEYfrom.env.localto your host's environment variables (e.g. Vercel → Settings → Environment Variables). - Allow your live address:
npx usemorph origins add https://your-app.com - Run
usemorph syncon every deploy, so Morph knows when your pages change:"build": "next build && usemorph sync"
That's it. Deploying has the details.
What init does#
Morph's AI reads your pages, the components they use and your sign-in code once (nothing is stored, and .env files are never read). It then shows you every change before writing anything:
Pages:
src/app/dashboard/page.tsx → surface "dashboard": Revenue chart, Latest orders, Budget, …
src/components/side-nav.tsx → surface "app-shell": Logo, Navigation links, …
src/app/sign-in/page.tsx skipped (sign-in pages have no signed-in user to customize for)
Changes:
edit src/app/layout.tsx (+1 lines)
new src/app/api/morph-token/route.ts (+12 lines)
edit src/app/dashboard/page.tsx (+19 lines)
edit src/components/side-nav.tsx (+8 lines)
key create your Morph app and put its secret key in .env.local
run npm install @usemorph/react @usemorph/node
| File | What it adds |
|---|---|
app/layout.tsx |
<MorphProvider> around your app |
app/api/morph-token/route.ts |
The token endpoint, which tells Morph which user is signed in |
| Your signed-in pages | <MorphSurface> around the content and <Section name="…"> around each part |
| Your sidebar or header | <MorphSurface id="app-shell" shell>, so users can change it too. Navigation is marked keep. |
.env.local |
MORPH_SECRET_KEY. It's never put in your code and never printed. |
Each change only adds Morph's tags. Remove them and you get your original files back.
If init can't tell how your app knows who's signed in, the token endpoint has a TODO(morph) line. Fill it in (see Connecting your sign-in). Until then Morph stays off and your app looks exactly as before.
Good to know#
- Running
initagain is safe. Pages already set up are skipped, and it keeps using the app inMORPH_SECRET_KEY. Delete that key only if you want a new, empty Morph app: users' saved changes belong to the app. - See the plan without changing anything:
npm init usemorph@latest -- --dry-run - Without Morph's AI:
npm init usemorph@latest -- --no-aiuses built-in rules. To have your own coding agent do the setup, give it the instructions fromnpx @usemorph/cli agent-prompt.
Next#
- Sections and rules: rename parts, protect them with
keep, tag new ones. - Data and actions: let users build new views from your data.