Vercel CLI With Tokens

Vercel CLI With Tokens

Guides an agent to deploy and manage Vercel projects with access tokens instead of interactive login, finding the token safely and keeping it out of commands.

Skill files1 file
SKILL.md354 lines
1
---
2
name: vercel-cli-with-tokens
3
description: Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".
4
metadata:
5
author: vercel
6
version: "1.0.0"
7
---
8
9
# Vercel CLI with Tokens
10
11
Deploy and manage projects on Vercel using the CLI with token-based authentication, without relying on `vercel login`.
12
13
## Step 1: Locate the Vercel Token
14
15
Before running any Vercel CLI commands, identify where the token is coming from. Work through these scenarios in order:
16
17
### A) `VERCEL_TOKEN` is already set in the environment
18
19
```bash
20
printenv VERCEL_TOKEN
21
```
22
23
If this returns a value, you're ready. Skip to Step 2.
24
25
### B) Token is in a `.env` file under `VERCEL_TOKEN`
26
27
```bash
28
grep '^VERCEL_TOKEN=' .env 2>/dev/null
29
```
30
31
If found, export it:
32
33
```bash
34
export VERCEL_TOKEN=$(grep '^VERCEL_TOKEN=' .env | cut -d= -f2-)
35
```
36
37
### C) Token is in a `.env` file under a different name
38
39
Look for any variable that looks like a Vercel token (Vercel tokens typically start with `vca_`):
40
41
```bash
42
grep -i 'vercel' .env 2>/dev/null
43
```
44
45
Inspect the output to identify which variable holds the token, then export it as `VERCEL_TOKEN`:
46
47
```bash
48
export VERCEL_TOKEN=$(grep '^<VARIABLE_NAME>=' .env | cut -d= -f2-)
49
```
50
51
### D) No token found — ask the user
52
53
If none of the above yield a token, ask the user to provide one. They can create a Vercel access token at vercel.com/account/tokens.
54
55
---
56
57
**Important:** Once `VERCEL_TOKEN` is exported as an environment variable, the Vercel CLI reads it natively — **do not pass it as a `--token` flag**. Putting secrets in command-line arguments exposes them in shell history and process listings.
58
59
```bash
60
# Bad — token visible in shell history and process listings
61
vercel deploy --token "vca_abc123"
62
63
# Good — CLI reads VERCEL_TOKEN from the environment
64
export VERCEL_TOKEN="vca_abc123"
65
vercel deploy
66
```
67
68
## Step 2: Locate the Project and Team
69
70
Similarly, check for the project ID and team scope. These let the CLI target the right project without needing `vercel link`.
71
72
```bash
73
# Check environment
74
printenv VERCEL_PROJECT_ID
75
printenv VERCEL_ORG_ID
76
77
# Or check .env
78
grep -i 'vercel' .env 2>/dev/null
79
```
80
81
**If you have a project URL** (e.g. `https://vercel.com/my-team/my-project`), extract the team slug:
82
83
```bash
84
# e.g. "my-team" from "https://vercel.com/my-team/my-project"
85
echo "$PROJECT_URL" | sed 's|https://vercel.com/||' | cut -d/ -f1
86
```
87
88
**If you have both `VERCEL_ORG_ID` and `VERCEL_PROJECT_ID` in your environment**, export them — the CLI will use these automatically and skip any `.vercel/` directory:
89
90
```bash
91
export VERCEL_ORG_ID="<org-id>"
92
export VERCEL_PROJECT_ID="<project-id>"
93
```
94
95
Note: `VERCEL_ORG_ID` and `VERCEL_PROJECT_ID` must be set together — setting only one causes an error.
96
97
## CLI Setup
98
99
Ensure the Vercel CLI is installed and up to date:
100
101
```bash
102
npm install -g vercel
103
vercel --version
104
```
105
106
## Deploying a Project
107
108
Always deploy as **preview** unless the user explicitly requests production. Choose a method based on what you have available.
109
110
### Quick Deploy (have project ID — no linking needed)
111
112
When `VERCEL_TOKEN` and `VERCEL_PROJECT_ID` are set in the environment, deploy directly:
113
114
```bash
115
vercel deploy -y --no-wait
116
```
117
118
With a team scope (either via `VERCEL_ORG_ID` or `--scope`):
119
120
```bash
121
vercel deploy --scope <team-slug> -y --no-wait
122
```
123
124
Production (only when explicitly requested):
125
126
```bash
127
vercel deploy --prod --scope <team-slug> -y --no-wait
128
```
129
130
Check status:
131
132
```bash
133
vercel inspect <deployment-url>
134
```
135
136
### Full Deploy Flow (no project ID — need to link)
137
138
Use this when you have a token and team but no pre-existing project ID.
139
140
#### Check project state first
141
142
```bash
143
# Does the project have a git remote?
144
git remote get-url origin 2>/dev/null
145
146
# Is it already linked to a Vercel project?
147
cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null
148
```
149
150
#### Link the project
151
152
**With git remote (preferred):**
153
154
```bash
155
vercel link --repo --scope <team-slug> -y
156
```
157
158
Reads the git remote and connects to the matching Vercel project. Creates `.vercel/repo.json`. More reliable than plain `vercel link`, which matches by directory name.
159
160
**Without git remote:**
161
162
```bash
163
vercel link --scope <team-slug> -y
164
```
165
166
Creates `.vercel/project.json`.
167
168
**Link to a specific project by name:**
169
170
```bash
171
vercel link --project <project-name> --scope <team-slug> -y
172
```
173
174
If the project is already linked, check `orgId` in `.vercel/project.json` or `.vercel/repo.json` to verify it matches the intended team.
175
176
#### Deploy after linking
177
178
**A) Git Push Deploy — has git remote (preferred)**
179
180
Git pushes trigger automatic Vercel deployments.
181
182
1. **Ask the user before pushing.** Never push without explicit approval.
183
2. Commit and push:
184
```bash
185
git add .
186
git commit -m "deploy: <description of changes>"
187
git push
188
```
189
3. Vercel builds automatically. Non-production branches get preview deployments.
190
4. Retrieve the deployment URL:
191
```bash
192
sleep 5
193
vercel ls --format json --scope <team-slug>
194
```
195
Find the latest entry in the `deployments` array.
196
197
**B) CLI Deploy — no git remote**
198
199
```bash
200
vercel deploy --scope <team-slug> -y --no-wait
201
```
202
203
Check status:
204
205
```bash
206
vercel inspect <deployment-url>
207
```
208
209
### Deploying from a Remote Repository (code not cloned locally)
210
211
1. Clone the repository:
212
```bash
213
git clone <repo-url>
214
cd <repo-name>
215
```
216
2. Link to Vercel:
217
```bash
218
vercel link --repo --scope <team-slug> -y
219
```
220
3. Deploy via git push (if you have push access) or CLI deploy.
221
222
### About `.vercel/` Directory
223
224
A linked project has either:
225
- `.vercel/project.json` — from `vercel link`. Contains `projectId` and `orgId`.
226
- `.vercel/repo.json` — from `vercel link --repo`. Contains `orgId`, `remoteName`, and a `projects` map.
227
228
Not needed when `VERCEL_ORG_ID` + `VERCEL_PROJECT_ID` are both set in the environment.
229
230
**Do NOT** run `vercel project inspect` or `vercel link` in an unlinked directory to detect state — they will interactively prompt or silently link as a side-effect. `vercel ls` is safe (in an unlinked directory it defaults to showing all deployments for the scope). `vercel whoami` is safe anywhere.
231
232
## Managing Environment Variables
233
234
```bash
235
# Set for all environments
236
echo "value" | vercel env add VAR_NAME --scope <team-slug>
237
238
# Set for a specific environment (production, preview, development)
239
echo "value" | vercel env add VAR_NAME production --scope <team-slug>
240
241
# List environment variables
242
vercel env ls --scope <team-slug>
243
244
# Pull env vars to local .env.local file
245
vercel env pull --scope <team-slug>
246
247
# Remove a variable
248
vercel env rm VAR_NAME --scope <team-slug> -y
249
```
250
251
## Inspecting Deployments
252
253
```bash
254
# List recent deployments
255
vercel ls --format json --scope <team-slug>
256
257
# Inspect a specific deployment
258
vercel inspect <deployment-url>
259
260
# View build logs (requires Vercel CLI v35+)
261
vercel inspect <deployment-url> --logs
262
263
# View runtime request logs (follows live by default; add --no-follow for a one-shot snapshot)
264
vercel logs <deployment-url>
265
```
266
267
## Managing Domains
268
269
```bash
270
# List domains
271
vercel domains ls --scope <team-slug>
272
273
# Add a domain to the project — linked or env-linked directory (1 arg)
274
vercel domains add <domain> --scope <team-slug>
275
276
# Add a domain — unlinked directory (requires <project> positional)
277
vercel domains add <domain> <project> --scope <team-slug>
278
```
279
280
## Stripe Projects Plan Changes
281
282
If this project is managed by Stripe Projects. **Ask the user before running any paid or destructive plan change** — upgrades bill a real card, downgrades remove seats.
283
284
First run `stripe projects status --json` to confirm the Vercel resource's local name. The examples below assume the default (`vercel-plan`); substitute the actual name if it was renamed at `stripe projects add` time.
285
286
- **Upgrade to Pro:** `stripe projects add vercel/pro` (or `stripe projects upgrade vercel-plan pro`)
287
- **Downgrade to Hobby:** `stripe projects downgrade vercel-plan hobby`
288
289
### What Pro gives you
290
291
- $20/month platform fee, includes $20/month of usage credit.
292
- Turbo build machines (30 vCPUs, 60 GB memory) by default for new projects — significantly faster builds than Hobby.
293
- 1 deploying seat + unlimited free Viewer seats (read-only collaborators, preview comments).
294
- Higher included allocations (1 TB Fast Data Transfer, 10M Edge Requests per month).
295
- Paid add-ons available: SAML SSO, HIPAA BAA, Flags Explorer, Observability Plus, Speed Insights, Web Analytics Plus.
296
297
Full details: https://vercel.com/docs/plans/pro-plan
298
299
## Working Agreement
300
301
- **Never pass `VERCEL_TOKEN` as a `--token` flag.** Export it as an environment variable and let the CLI read it natively.
302
- **Check the environment for tokens before asking the user.** Look in the current env and `.env` files first.
303
- **Default to preview deployments.** Only deploy to production when explicitly asked.
304
- **Ask before pushing to git.** Never push commits without the user's approval.
305
- **Do not modify `.vercel/` files directly.** The CLI manages this directory. Reading them (e.g. to verify `orgId`) is fine.
306
- **Do not curl/fetch deployed URLs to verify.** Just return the link to the user.
307
- **Use `--format json`** when structured output will help with follow-up steps.
308
- **Use `-y`** on commands that prompt for confirmation to avoid interactive blocking.
309
310
## Troubleshooting
311
312
### Token not found
313
314
Check the environment and any `.env` files present:
315
316
```bash
317
printenv | grep -i vercel
318
grep -i vercel .env 2>/dev/null
319
```
320
321
### Authentication error
322
323
If the CLI fails with `Authentication required`:
324
- The token may be expired or invalid.
325
- Verify: `vercel whoami` (uses `VERCEL_TOKEN` from environment).
326
- Ask the user for a fresh token.
327
328
### Wrong team
329
330
Verify the scope is correct:
331
332
```bash
333
vercel whoami --scope <team-slug>
334
```
335
336
### Build failure
337
338
Check the build logs:
339
340
```bash
341
vercel inspect <deployment-url> --logs
342
```
343
344
Common causes:
345
- Missing dependencies — ensure `package.json` is complete and committed.
346
- Missing environment variables — add with `vercel env add`.
347
- Framework misconfiguration — check `vercel.json`. Vercel auto-detects frameworks (Next.js, Remix, Vite, etc.) from `package.json`; override with `vercel.json` if detection is wrong.
348
349
### CLI not installed
350
351
```bash
352
npm install -g vercel
353
```
354

© vercel · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…