✦Morph

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:

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:

  1. Add MORPH_SECRET_KEY from .env.local to your host's environment variables (e.g. Vercel → Settings → Environment Variables).
  2. Allow your live address:
    npx usemorph origins add https://your-app.com
    
  3. Run usemorph sync on 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#

Next#