Deploy to Vercel
Deploy any project to Vercel. Always deploy as preview (not production) unless the user explicitly asks for production.
The goal is to get the user into the best long-term setup: their project linked to Vercel with git-push deploys. Every method below tries to move the user closer to that state.
Step 1: Gather Project State
Run all four checks before deciding which method to use:
CODEBLOCK0
Team selection
If the user belongs to multiple teams, present all available team slugs as a bulleted list and ask which one to deploy to. Once the user picks a team, proceed immediately to the next step — do not ask for additional confirmation.
Pass the team slug via --scope on all subsequent CLI commands (vercel deploy, vercel link, vercel inspect, etc.):
CODEBLOCK1
If the project is already linked (.vercel/project.json or .vercel/repo.json exists), the orgId in those files determines the team — no need to ask again. If there is only one team (or just a personal account), skip the prompt and use it directly.
About the .vercel/ directory: A linked project has either:
- -
.vercel/project.json — created by vercel link (single project linking). Contains projectId and orgId. - INLINECODE12 — created by
vercel link --repo (repo-based linking). Contains orgId, remoteName, and a projects array mapping directories to Vercel project IDs.
Either file means the project is linked. Check for both.
Do NOT use vercel project inspect, vercel ls, or vercel link to detect state in an unlinked directory — without a .vercel/ config, they will interactively prompt (or with --yes, silently link as a side-effect). Only vercel whoami is safe to run anywhere.
Step 2: Choose a Deploy Method
Linked (.vercel/ exists) + has git remote → Git Push
This is the ideal state. The project is linked and has git integration.
- 1. Ask the user before pushing. Never push without explicit approval:
CODEBLOCK2
- 2. Commit and push:
git add .
git commit -m "deploy: <description of changes>"
git push
Vercel automatically builds from the push. Non-production branches get preview deployments; the production branch (usually
main) gets a production deployment.
- 3. Retrieve the preview URL. If the CLI is authenticated:
sleep 5
vercel ls --format json
The JSON output has a
deployments array. Find the latest entry — its
url field is the preview URL.
If the CLI is not authenticated, tell the user to check the Vercel dashboard or the commit status checks on their git provider for the preview URL.
Linked (.vercel/ exists) + no git remote → vercel deploy
The project is linked but there's no git repo. Deploy directly with the CLI.
CODEBLOCK5
Use --no-wait so the CLI returns immediately with the deployment URL instead of blocking until the build finishes (builds can take a while). Then check on the deployment status with:
CODEBLOCK6
For production deploys (only if user explicitly asks):
vercel deploy [path] --prod -y --no-wait
Not linked + CLI is authenticated → Link first, then deploy
The CLI is working but the project isn't linked yet. This is the opportunity to get the user into the best state.
- 1. Ask the user which team to deploy to. Present the team slugs from Step 1 as a bulleted list. If there's only one team (or just a personal account), skip this step.
- 2. Once a team is selected, proceed directly to linking. Tell the user what will happen but do not ask for separate confirmation:
CODEBLOCK8
- 3. If a git remote exists, use repo-based linking with the selected team scope:
vercel link --repo --scope <team-slug>
This reads the git remote URL and matches it to existing Vercel projects that deploy from that repo. It creates
.vercel/repo.json. This is much more reliable than
vercel link (without
--repo), which tries to match by directory name and often fails when the local folder and Vercel project are named differently.
If there is no git remote, fall back to standard linking:
vercel link --scope <team-slug>
This prompts the user to select or create a project. It creates
.vercel/project.json.
- 4. Then deploy using the best available method:
- If a git remote exists → commit and push (see git push method above)
- If no git remote →
vercel deploy [path] -y --no-wait --scope <team-slug>, then
vercel inspect <url> to check status
Not linked + CLI not authenticated → Install, auth, link, deploy
The Vercel CLI isn't set up at all.
- 1. Install the CLI (if not already installed):
CODEBLOCK11
- 2. Authenticate:
vercel login
The user completes auth in their browser. If running in a non-interactive environment where login is not possible, skip to the
no-auth fallback below.
- 3. Ask which team to deploy to — present team slugs from
vercel teams list --format json as a bulleted list. If only one team / personal account, skip. Once selected, proceed immediately.
- 4. Link the project with the selected team scope (use
--repo if a git remote exists, plain vercel link otherwise):
CODEBLOCK13
- 5. Deploy using the best available method (git push if remote exists, otherwise
vercel deploy -y --no-wait --scope <team-slug>, then vercel inspect <url> to check status).
No-Auth Fallback — claude.ai sandbox
When to use: Last resort when the CLI can't be installed or authenticated in the claude.ai sandbox. This requires no authentication — it returns a Preview URL (live site) and a Claim URL (transfer to your Vercel account).
CODEBLOCK14
Arguments:
- -
path - Directory to deploy, or a .tgz file (defaults to current directory)
Examples:
CODEBLOCK15
The script auto-detects the framework from package.json, packages the project (excluding node_modules, .git, .env), uploads it, and waits for the build to complete.
Tell the user: "Your deployment is ready at [previewUrl]. Claim it at [claimUrl] to manage your deployment."
No-Auth Fallback — Codex sandbox
When to use: In the Codex sandbox where the CLI may not be authenticated. Codex runs in a sandboxed environment by default — try the CLI first, and fall back to the deploy script if auth fails.
- 1. Check whether the Vercel CLI is installed (no escalation needed for this check):
CODEBLOCK16
- 2. If
vercel is installed, try deploying with the CLI:
CODEBLOCK17
- 3. If
vercel is not installed, or the CLI fails with "No existing credentials found", use the fallback script:
CODEBLOCK18
The script handles framework detection, packaging, and deployment. It waits for the build to complete and returns JSON with previewUrl and claimUrl.
Tell the user: "Your deployment is ready at [previewUrl]. Claim it at [claimUrl] to manage your deployment."
Escalated network access: Only escalate the actual deploy command if sandboxing blocks the network call (sandbox_permissions=require_escalated). Do not escalate the command -v vercel check.
Agent-Specific Notes
Claude Code / terminal-based agents
You have full shell access. Do NOT use the /mnt/skills/ path. Follow the decision flow above using the CLI directly.
For the no-auth fallback, run the deploy script from the skill's installed location:
bash ~/.claude/skills/deploy-to-vercel/resources/deploy.sh [path]
The path may vary depending on where the user installed the skill.
Sandboxed environments (claude.ai)
You likely cannot run vercel login or git push. Go directly to the no-auth fallback — claude.ai sandbox.
Codex
Codex runs in a sandbox. Check if the CLI is available first, then fall back to the deploy script. Go to the no-auth fallback — Codex sandbox.
Output
Always show the user the deployment URL.
- - Git push: Use
vercel ls --format json to find the preview URL. If the CLI isn't authenticated, tell the user to check the Vercel dashboard or commit status checks. - CLI deploy: Show the URL returned by
vercel deploy --no-wait. Use vercel inspect <url> to check build status and report it to the user. - No-auth fallback: Show both the preview URL and the claim URL:
CODEBLOCK20
Do not curl or fetch the deployed URL to verify it works. Just return the link.
Troubleshooting
Network Egress Error (claude.ai)
If deployment fails due to network restrictions on claude.ai, tell the user:
CODEBLOCK21
Escalated Network Access (Codex / sandboxed environments)
If deployment fails due to network issues (timeouts, DNS errors, connection resets) in a sandboxed environment, rerun with escalated permissions (sandbox_permissions=require_escalated). Do not escalate the initial CLI availability check — only escalate the actual deploy command.
Example guidance to the user:
CODEBLOCK22
CLI Auth Failure
If vercel login or vercel deploy fails with authentication errors, fall back to the no-auth deploy script (claude.ai or Codex variant, depending on the environment).
部署到 Vercel
将任意项目部署到 Vercel。始终以预览模式部署(非生产环境),除非用户明确要求部署到生产环境。
目标是让用户进入最佳长期设置:将项目与 Vercel 关联,并通过 git 推送实现自动部署。以下每种方法都旨在让用户更接近这一状态。
第一步:收集项目状态
在决定使用哪种方法之前,先运行以下四项检查:
bash
1. 检查是否存在 git 远程仓库
git remote get-url origin 2>/dev/null
2. 检查是否已本地关联到 Vercel 项目(存在任一文件即表示已关联)
cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null
3. 检查 Vercel CLI 是否已安装并完成身份验证
vercel whoami 2>/dev/null
4. 列出可用团队(如果已通过身份验证)
vercel teams list --format json 2>/dev/null
团队选择
如果用户属于多个团队,以项目符号列表形式展示所有可用团队标识,并询问要部署到哪个团队。用户选择团队后,立即进入下一步——无需额外确认。
在所有后续 CLI 命令(vercel deploy、vercel link、vercel inspect 等)中通过 --scope 参数传递团队标识:
bash
vercel deploy [path] -y --no-wait --scope
如果项目已关联(存在 .vercel/project.json 或 .vercel/repo.json),这些文件中的 orgId 决定了团队归属——无需再次询问。如果只有一个团队(或个人账户),跳过提示直接使用。
关于 .vercel/ 目录: 已关联的项目包含以下任一文件:
- - .vercel/project.json — 由 vercel link 创建(单个项目关联)。包含 projectId 和 orgId。
- .vercel/repo.json — 由 vercel link --repo 创建(基于仓库的关联)。包含 orgId、remoteName 以及将目录映射到 Vercel 项目 ID 的 projects 数组。
任一文件存在即表示项目已关联。请检查这两个文件。
不要在未关联的目录中使用 vercel project inspect、vercel ls 或 vercel link 来检测状态——如果没有 .vercel/ 配置文件,这些命令会进行交互式提示(或使用 --yes 时,会静默关联并产生副作用)。只有 vercel whoami 可以在任何位置安全运行。
第二步:选择部署方法
已关联(存在 .vercel/)+ 有 git 远程仓库 → Git 推送
这是理想状态。项目已关联并集成了 git。
- 1. 在推送前询问用户。 未经明确批准绝不推送:
此项目已通过 git 连接到 Vercel。我可以提交并推送以触发部署。
是否继续?
- 2. 提交并推送:
bash
git add .
git commit -m deploy: <变更描述>
git push
Vercel 会自动从推送构建。非生产分支获得预览部署;生产分支(通常是 main)获得生产部署。
- 3. 获取预览 URL。 如果 CLI 已通过身份验证:
bash
sleep 5
vercel ls --format json
JSON 输出包含一个 deployments 数组。找到最新条目——其 url 字段即为预览 URL。
如果 CLI 未通过身份验证,告知用户查看 Vercel 仪表板或 git 提供商上的提交状态检查以获取预览 URL。
已关联(存在 .vercel/)+ 无 git 远程仓库 → vercel deploy
项目已关联但没有 git 仓库。直接使用 CLI 部署。
bash
vercel deploy [path] -y --no-wait
使用 --no-wait 让 CLI 立即返回部署 URL,而不是等待构建完成(构建可能需要一些时间)。然后使用以下命令检查部署状态:
bash
vercel inspect
生产环境部署(仅在用户明确要求时):
bash
vercel deploy [path] --prod -y --no-wait
未关联 + CLI 已通过身份验证 → 先关联,再部署
CLI 可用但项目尚未关联。这是让用户进入最佳状态的机会。
- 1. 询问用户要部署到哪个团队。 以项目符号列表形式展示第一步中的团队标识。如果只有一个团队(或个人账户),跳过此步骤。
- 2. 选择团队后,直接进入关联步骤。 告知用户将要进行的操作,但不要单独请求确认:
正在将此项目关联到 Vercel 上的 <团队名称>。这将创建一个 Vercel
项目用于部署,并启用未来 git 推送时的自动部署。
- 3. 如果存在 git 远程仓库,使用基于仓库的关联并指定团队范围:
bash
vercel link --repo --scope
这会读取 git 远程仓库 URL 并将其与从该仓库部署的现有 Vercel 项目匹配。它会创建 .vercel/repo.json。这比 vercel link(不带 --repo)可靠得多,后者尝试按目录名称匹配,当本地文件夹和 Vercel 项目名称不同时经常失败。
如果没有 git 远程仓库,回退到标准关联:
bash
vercel link --scope
这会提示用户选择或创建项目。它会创建 .vercel/project.json。
- 4. 然后使用最佳可用方法部署:
- 如果存在 git 远程仓库 → 提交并推送(参见上面的 git 推送方法)
- 如果没有 git 远程仓库 → vercel deploy [path] -y --no-wait --scope ,然后 vercel inspect 检查状态
未关联 + CLI 未通过身份验证 → 安装、认证、关联、部署
Vercel CLI 完全未设置。
- 1. 安装 CLI(如果尚未安装):
bash
npm install -g vercel
- 2. 进行身份验证:
bash
vercel login
用户在浏览器中完成身份验证。如果在无法登录的非交互式环境中运行,请跳转到下面的无认证回退方案。
- 3. 询问要部署到哪个团队——以项目符号列表形式展示 vercel teams list --format json 中的团队标识。如果只有一个团队/个人账户,跳过。选择后立即继续。
- 4. 使用选定的团队范围关联项目(如果存在 git 远程仓库则使用 --repo,否则使用普通 vercel link):
bash
vercel link --repo --scope # 如果存在 git 远程仓库
vercel link --scope # 如果没有 git 远程仓库
- 5. 使用最佳可用方法部署(如果存在远程仓库则使用 git 推送,否则使用 vercel deploy -y --no-wait --scope ,然后 vercel inspect 检查状态)。
无认证回退方案 — claude.ai 沙箱
何时使用: 在 claude.ai 沙箱中无法安装 CLI 或完成身份验证时的最后手段。这不需要身份验证——它会返回一个预览 URL(在线站点)和一个认领 URL(转移到您的 Vercel 账户)。
bash
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh [path]
参数:
- - path - 要部署的目录,或一个 .tgz 文件(默认为当前目录)
示例:
bash
部署当前目录
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh
部署特定项目
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh /path/to/project
部署现有的压缩包
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh /path/to/project.tgz
该脚本从 package.json 自动检测框架,打包项目(排除 node_modules、.git、.env),上传并等待构建完成。
告知用户: 您的部署已就绪,访问地址为 [previewUrl]。前往 [claimUrl] 认领以管理您的部署。
无认证回退方案 — Codex 沙箱
何时使用: 在 Codex 沙箱中,CLI 可能未通过身份验证。Codex 默认在沙箱环境中运行——先尝试 CLI,如果身份验证失败则回退到部署脚本。
- 1. 检查 Vercel CLI 是否已