Vibe coding with Claude Code course Β· Module 11: Spotify clone
Deployment: Claude Makes the Preview, You Approve Production
In this lesson13
Sea Shanty Sounds runs on your computer but the crew wants to listen to shanties in port, on their phones. It is time to set sail: build the app on a server and give it an address on the internet. That is deployment. Claude Code will do it in a minute and that is exactly the danger. An agent works faster than you read, and a production deployment is seen at once by every user.
What you will learn
- tell a preview deployment from a production one and know when each is created;
- keep the values of variables on the platform, and only
.env.examplein the repository; - let in images from an external server through
images.remotePatternsinnext.config.ts; - write a
/deployskill that only you can run and that deploys only a preview; - add an
askrule for deployment commands and know what auto mode does with production; - promote a preview to production with your own hand and have a way back.
What can go wrong
Three things sink ships most often. A secret lands in the repository or in the code sent to the browser. A new version breaks the site for everyone at once. An agent deploys something you know nothing about, because it "wanted to check that it works". Each of them gets its own lock in this lesson.
Preview and production
The course deploys to Vercel. Its documentation describes three environments: local, preview (Preview) and production (Production). A preview is a version to check under a separate address that does not touch the main site. It appears when you push a branch other than the production one, open a pull request or run vercel without the --prod flag. Production comes from the production branch, usually main, or from vercel --prod. There is one exception that an agent gladly forgets: the first deployment of a new project is always production, even without --prod and from another branch.
The request: prepare, do not deploy
Request for Claude Code:
Prepare Sea Shanty Sounds for deployment on Vercel. Do not deploy.
1. Album covers from images.unsplash.com in the player through
next/image, and in next.config.ts images.remotePatterns only for
that host.
2. The address of the recordings folder from NEXT_PUBLIC_AUDIO_BASE_URL,
locally defaulting to /audio.
3. .env.example with the names of the variables the code reads, without
values. Check that Git does not ignore it.
At the end the check commands from CLAUDE.md and git status --short."Do not deploy" stands first on purpose. According to the auto mode documentation, a boundary you state in the conversation works for the classifier like a ban until you lift it.
What Claude wrote: a variable instead of an address
Sea Shanty Sounds has no secrets today. It does have a value that differs between environments: the address of the recordings folder. Open lib/catalog.ts in Cursor:
const AUDIO_BASE_URL = process.env.NEXT_PUBLIC_AUDIO_BASE_URL ?? "/audio";?? takes the right side when the left one does not exist, so locally the recordings still come from public/audio. You know the NEXT_PUBLIC_ prefix from lesson 8_4: Next.js writes such a value into the code for the browser at build time. We built the project with the variable set, and in a file from .next/static/chunks there stood let o="https://szanty.example.test/audio". For a public address that is fine, for a key never. Next to the code Claude saved .env.example:
# Address of the recordings folder. Empty locally: the app takes /audio from public/.
# On Vercel set it separately for Preview and Production.
NEXT_PUBLIC_AUDIO_BASE_URL=The file shows names, never values. Claude avoided the trap from lesson 8_5 on its own: it added the line !.env.example to .gitignore, and git status --short showed the new file.
You enter the values on the platform. According to the Vercel documentation, in the project you choose Environment Variables in the side menu, give a name, tick the environments (Production, Preview, Development) and a type: Config stays readable for authorized people, and a Secret can only be overwritten after saving. A change applies only to new deployments, so after it you have to deploy again.
What Claude wrote: images from an external server
The player shows a cover through the Image component from lesson 3_1, and the cover address stands in the album data. next/image passes the photo through an optimizer on your server, so Next.js must know which hosts it may fetch from. Open next.config.ts:
images: {
remotePatterns: [
{ protocol: "https", hostname: "images.unsplash.com", pathname: "/**", search: "" },
],
},The entry lets in only https, only this host, any path (/**) and addresses without parameters (search: ""). We checked it after npm run build and npm start: a cover from images.unsplash.com came back from the optimizer with code 200, while the same address with ?w=1280, an address over http and a photo from another host got 400 with the message "url" parameter is not allowed. Without this entry npm run dev returned the page with a 500 error and the message hostname "images.unsplash.com" is not configured under images.
A typical agent mistake is an option from old tutorials, images: { domains: ["images.unsplash.com"] }. For us npx tsc --noEmit and npm run lint said nothing, and the build passed with a warning that images.domains is deprecated in favor of images.remotePatterns. The Next.js documentation explains that domains cannot restrict the protocol, port or path. You read a warning in a build as carefully as an error.
The /deploy skill: only you raise the anchor
You met skills in lesson 6_1, and the disable-model-invocation field was there next to the form. Here it matters most.
Request for Claude Code:
Save a /deploy skill in .claude/skills/deploy/. Only I can run it.
The skill checks that the project is linked to Vercel, runs the
check commands from CLAUDE.md, stops on uncommitted changes and
deploys only a preview through npx vercel deploy. No --prod,
--temporary or promote.Open .claude/skills/deploy/SKILL.md. The header looks like this:
---
name: deploy
description: Deploys Sea Shanty Sounds to Vercel as a preview version. Never deploys production.
disable-model-invocation: true
---The skills documentation gives deployment as the model example of this field: you do not want Claude to deploy just because the code looks finished. If Claude tries to run the skill although your message has no /deploy, Claude Code blocks the call. Below the header stand the steps:
1. Check that the .vercel directory exists (the project linked with vercel link). If it does not, stop: the first deployment of a new project on Vercel always goes to production, so the captain links and deploys it.
2. Run all commands from the "Check commands" section of CLAUDE.md. If any of them fails, stop and show the result.
3. Run git status --short. If there are uncommitted changes, stop and ask.
4. Deploy a preview with one command: npx vercel deploy. No --prod, no --environment, no --temporary, no vercel promote.
5. Show the preview address from the command output and a list of things to check in the browser: the player, album covers, the search.The .vercel directory is created by vercel link. In an unlinked project npx vercel deploy --dry answered for us Error: Project is not linked. with advice to run vercel link first. The ban on --temporary has a reason too: according to the Vercel documentation that flag deploys without an account and always to production, and Vercel recommends it among other cases when an agent deploys.
Safety belts: the ask rule
The skill watches what Claude does on your command. A rule in .claude/settings.json watches every command, also one issued outside the skill:
{
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)", "Read(!.env.example)"],
"ask": ["Bash(vercel*)", "Bash(npx vercel*)", "Bash(git push *)"]
}
}You know deny from lessons 8_4 and 8_5. ask makes Claude Code ask for your consent at every matching command, and the permissions documentation says that such a question appears in auto mode too. The missing space before the asterisk is deliberate: Bash(npx vercel*) also catches npx vercel@latest deploy. Two rules are needed because npx is not among the wrappers that Claude Code strips before matching. The third watches Git: when Vercel is connected to the repository, a push to main is a production deployment, and the auto mode classifier by default lets through a push to any branch of your repository. A rule matches the text of a command, so it is not a security boundary: sh -c with the same command does not fall under it.
Auto mode and production
According to the documentation the auto mode classifier by default blocks, among other things, production deployments and migrations. That is the last line of defense, not the first. A boundary stated in the conversation can vanish when the conversation is compacted, and the documentation itself advises a deny rule when you need a guarantee. That is why production is not Claude's step but yours.
You promote production
/deploy ends with a preview address. You open it in the browser and click what the crew will click: Play, covers, the search. Only then in the Vercel dashboard do you open Deployments, the three dots menu next to the chosen deployment and Promote to Production. The documentation warns that promoting a preview builds the app anew with production variables. The same promotion is done by vercel promote <address> in your own terminal, outside Claude's session. According to the documentation Vercel builds new projects on the newest Node.js LTS it offers (as of November 2026: 26.x). When you test locally on another version, pin it in the engines field of package.json.
The way back
Before you promote, you know where you will turn back to. Instant Rollback in the dashboard (the production deployment tile on the project page) or vercel rollback points the domains at an earlier deployment without building again, so the variables stay as that deployment had them. After a rollback Vercel turns off automatic assignment of production domains: new pushes to main will not reach the site until you promote some deployment.
Captain's review
- The skill. The
/deployheader hasdisable-model-invocation: true, and the steps contain no--prod,--temporaryorpromote. - Secrets. Search the project for
NEXT_PUBLIC_: the hits should be only public addresses.git statusshows.env.exampleand does not show.env.local. - Images.
next.config.tshasremotePatterns, notdomains, and the build prints no warnings. - The consent question. Ask Claude for
npx vercel --version: Claude Code should ask for consent. A typical agent mistake is a deployment "just to check" throughvercel --prodor--temporary; theaskrule stops it before it starts.
Next step
Ask for a commit, for example "Covers, .env.example, the /deploy skill and ask rules". Do the first deployment yourself, because it will be production anyway: import the repository in the Vercel dashboard or run npx vercel login and npx vercel in your own terminal. Every later one starts with /deploy and ends with your click. In the editor below a simulation of this voyage is waiting: deploy a preview, check it, promote it, then break a version and roll it back with one button.
Remember: a captain raises the anchor with their own hand, however good the crew, and before leaving port knows which harbor to run to when the storm breaks.
Code for this lesson: App.jsx
// A deployment voyage in simulation: preview, promotion, rollback and an agent that wants to "just check"
import { useState } from 'react';
const ENV = {
Preview: 'https://test.example.test/audio',
Production: 'https://szanty.example.test/audio',
};
export default function App() {
const [deployments, setDeployments] = useState([]);
const [current, setCurrent] = useState(null); // id of the deployment on the production domain
const [autoAssign, setAutoAssign] = useState(true);
const [version, setVersion] = useState(1);
const [brokenCode, setBrokenCode] = useState(false);
const [hiddenBug, setHiddenBug] = useState(false);
const [autoMode, setAutoMode] = useState(true);
const [askRule, setAskRule] = useState(true);
const [prompt, setPrompt] = useState(null);
const [log, setLog] = useState([]);
const linked = deployments.length > 0;
const live = deployments.find((d) => d.id === current);
function say(line) {
setLog((l) => [line, ...l].slice(0, 8));
}
function addDeployment(target, broken) {
const d = { id: `dpl_${deployments.length + 1}`, target, version, broken, checked: false };
setDeployments((list) => [d, ...list]);
setVersion((v) => v + 1);
return d;
}
// Captain: vercel link and the first deployment (always production)
function firstDeploy() {
const d = addDeployment('Production', false);
setCurrent(d.id);
say(`${d.id}: the first deployment of a new project went to production`);
}
// /deploy: check commands, then a preview only
function runDeploySkill() {
if (!linked) {
say('/deploy: no .vercel directory, stopping. Link the project and do the first deployment yourself.');
return;
}
if (brokenCode) {
say('/deploy: npm run test -- --run: 2 failed. Stopping, deploying nothing.');
return;
}
const d = addDeployment('Preview', hiddenBug);
say(`/deploy: tests, lint, types and build are green. Preview ${d.id} is ready.`);
}
function checkPreview(preview) {
setDeployments((list) => list.map((d) => (d.id === preview.id ? { ...d, checked: true } : d)));
say(preview.broken
? `${preview.id}: in the browser the covers do not load, although the tests were green`
: `${preview.id}: in the browser it plays, covers and search work`);
}
// Promote to Production: a new build with production variables
function promote(preview) {
const d = addDeployment('Production', preview.broken);
setCurrent(d.id);
setAutoAssign(true);
say(`Promote to Production: ${preview.id} built anew as ${d.id} with Production variables`);
}
function shipBrokenToProduction() {
const d = addDeployment('Production', true);
setCurrent(d.id);
say(`${d.id}: a version with a bug that nobody checked went to production`);
}
// Instant Rollback: domains go back to the previous production deployment, with no build
function rollback() {
const production = deployments.filter((d) => d.target === 'Production');
const previous = production[production.findIndex((d) => d.id === current) + 1];
if (!previous) {
say('Instant Rollback: there is no earlier production deployment.');
return;
}
setCurrent(previous.id);
setAutoAssign(false);
say(`Instant Rollback: the domain points at ${previous.id}. Automatic domain assignment is off.`);
}
// The agent wants to run a production deployment "just to check"
function agentProdDeploy() {
const command = 'npx vercel deploy --prod';
if (askRule) {
setPrompt(command);
say(`Ask rule: Claude Code asks for consent to ${command}`);
} else if (autoMode) {
say(`Auto mode: the classifier blocked ${command} (a production deployment)`);
} else {
setPrompt(command);
say(`Manual mode: Claude Code asks for consent to ${command}`);
}
}
function answerPrompt(allow) {
if (allow) {
shipBrokenToProduction();
} else {
say('You refused. Production is unchanged.');
}
setPrompt(null);
}
return (
<div className="min-h-screen bg-gray-950 p-4 text-white">
<div className="mx-auto max-w-xl space-y-4">
<div className="rounded-xl bg-gray-900 p-3 text-sm">
<p className="text-gray-400">Production domain</p>
{live ? (
<p className={live.broken ? 'text-red-400' : 'text-green-400'}>
{live.id} (v{live.version}) {live.broken ? 'breaks the player' : 'plays correctly'}
</p>
) : (
<p className="text-gray-500">Nothing has set sail yet.</p>
)}
<p className="mt-1 text-xs text-gray-400">
Automatic domain assignment: {autoAssign ? 'on' : 'off after the rollback'}
</p>
</div>
<div className="flex flex-wrap gap-2 text-sm">
<button type="button" onClick={firstDeploy} disabled={linked} className="rounded bg-gray-700 px-3 py-1 disabled:opacity-40">
Captain: vercel link and the first deployment
</button>
<button type="button" onClick={runDeploySkill} className="rounded bg-white px-3 py-1 font-semibold text-black">
/deploy
</button>
<button type="button" onClick={rollback} disabled={!linked} className="rounded bg-gray-700 px-3 py-1 disabled:opacity-40">
Instant Rollback
</button>
<button type="button" onClick={agentProdDeploy} className="rounded bg-red-800 px-3 py-1">
Claude: I will deploy production just to check
</button>
</div>
<div className="space-y-1 text-sm">
<label className="flex items-center gap-2">
<input type="checkbox" checked={brokenCode} onChange={(e) => setBrokenCode(e.target.checked)} />
Code with a bug (tests red)
</label>
<label className="flex items-center gap-2">
<input type="checkbox" checked={hiddenBug} onChange={(e) => setHiddenBug(e.target.checked)} />
A bug the tests do not catch (visible only in the browser)
</label>
<label className="flex items-center gap-2">
<input type="checkbox" checked={askRule} onChange={(e) => setAskRule(e.target.checked)} />
Ask rule: Bash(npx vercel*)
</label>
<label className="flex items-center gap-2">
<input type="checkbox" checked={autoMode} onChange={(e) => setAutoMode(e.target.checked)} />
Auto mode (without it: Manual)
</label>
</div>
{prompt && (
<div className="rounded-xl bg-amber-900 p-3 text-sm">
<p>Claude wants to run: <code>{prompt}</code></p>
<div className="mt-2 flex gap-2">
<button type="button" onClick={() => answerPrompt(false)} className="rounded bg-white px-3 py-1 text-black">Deny</button>
<button type="button" onClick={() => answerPrompt(true)} className="rounded bg-gray-700 px-3 py-1">Allow</button>
</div>
</div>
)}
<ul className="space-y-2">
{deployments.map((d) => (
<li key={d.id} className="rounded-xl bg-gray-900 p-3 text-sm">
<p>
<strong>{d.id}</strong> v{d.version} {d.target === 'Preview' ? 'Preview' : 'Production'}
{d.id === current && <span className="ml-2 text-green-400">on the domain</span>}
</p>
<p className="text-xs text-gray-400">NEXT_PUBLIC_AUDIO_BASE_URL = {ENV[d.target]}</p>
{d.target === 'Preview' && (
<div className="mt-2 flex gap-2">
<button type="button" onClick={() => checkPreview(d)} disabled={d.checked} className="rounded bg-gray-700 px-2 py-1 disabled:opacity-40">
{d.checked ? 'Checked' : 'Check in the browser'}
</button>
<button type="button" onClick={() => promote(d)} disabled={!d.checked} className="rounded bg-green-700 px-2 py-1 disabled:opacity-40">
Promote to Production
</button>
</div>
)}
</li>
))}
</ul>
<div className="rounded-xl bg-black p-3 font-mono text-xs text-green-400">
<p className="text-gray-400">Voyage log (newest on top):</p>
{log.map((line, i) => <p key={i}>{line}</p>)}
</div>
</div>
</div>
);
}Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. The Sea Shanty Sounds project already has its first deployment on Vercel. What creates a preview deployment?
2. Where does the production value of NEXT_PUBLIC_AUDIO_BASE_URL go, and what travels in the repository?
These are 2 of 3 questions for this lesson. Solve the rest in the game.
Hands-on tasks in the game
- Click in order
Click the elements to build an ask rule that asks for consent at every npx vercel command:
- Vertical ordering
A bug reached production. Order the steps of the way back: