$npx -y skills add vercel-labs/agent-skills --skill vercel-cli-with-tokensDeploy 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".
| 1 | # Vercel CLI with Tokens |
| 2 | |
| 3 | Deploy and manage projects on Vercel using the CLI with token-based authentication, without relying on `vercel login`. |
| 4 | |
| 5 | ## Step 1: Locate the Vercel Token |
| 6 | |
| 7 | Before running any Vercel CLI commands, identify where the token is coming from. Work through these scenarios in order: |
| 8 | |
| 9 | ### A) `VERCEL_TOKEN` is already set in the environment |
| 10 | |
| 11 | ```bash |
| 12 | printenv VERCEL_TOKEN |
| 13 | ``` |
| 14 | |
| 15 | If this returns a value, you're ready. Skip to Step 2. |
| 16 | |
| 17 | ### B) Token is in a `.env` file under `VERCEL_TOKEN` |
| 18 | |
| 19 | ```bash |
| 20 | grep '^VERCEL_TOKEN=' .env 2>/dev/null |
| 21 | ``` |
| 22 | |
| 23 | If found, export it: |
| 24 | |
| 25 | ```bash |
| 26 | export VERCEL_TOKEN=$(grep '^VERCEL_TOKEN=' .env | cut -d= -f2-) |
| 27 | ``` |
| 28 | |
| 29 | ### C) Token is in a `.env` file under a different name |
| 30 | |
| 31 | Look for any variable that looks like a Vercel token (Vercel tokens typically start with `vca_`): |
| 32 | |
| 33 | ```bash |
| 34 | grep -i 'vercel' .env 2>/dev/null |
| 35 | ``` |
| 36 | |
| 37 | Inspect the output to identify which variable holds the token, then export it as `VERCEL_TOKEN`: |
| 38 | |
| 39 | ```bash |
| 40 | export VERCEL_TOKEN=$(grep '^<VARIABLE_NAME>=' .env | cut -d= -f2-) |
| 41 | ``` |
| 42 | |
| 43 | ### D) No token found — ask the user |
| 44 | |
| 45 | 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. |
| 46 | |
| 47 | --- |
| 48 | |
| 49 | **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. |
| 50 | |
| 51 | ```bash |
| 52 | # Bad — token visible in shell history and process listings |
| 53 | vercel deploy --token "vca_abc123" |
| 54 | |
| 55 | # Good — CLI reads VERCEL_TOKEN from the environment |
| 56 | export VERCEL_TOKEN="vca_abc123" |
| 57 | vercel deploy |
| 58 | ``` |
| 59 | |
| 60 | ## Step 2: Locate the Project and Team |
| 61 | |
| 62 | Similarly, check for the project ID and team scope. These let the CLI target the right project without needing `vercel link`. |
| 63 | |
| 64 | ```bash |
| 65 | # Check environment |
| 66 | printenv VERCEL_PROJECT_ID |
| 67 | printenv VERCEL_ORG_ID |
| 68 | |
| 69 | # Or check .env |
| 70 | grep -i 'vercel' .env 2>/dev/null |
| 71 | ``` |
| 72 | |
| 73 | **If you have a project URL** (e.g. `https://vercel.com/my-team/my-project`), extract the team slug: |
| 74 | |
| 75 | ```bash |
| 76 | # e.g. "my-team" from "https://vercel.com/my-team/my-project" |
| 77 | echo "$PROJECT_URL" | sed 's|https://vercel.com/||' | cut -d/ -f1 |
| 78 | ``` |
| 79 | |
| 80 | **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: |
| 81 | |
| 82 | ```bash |
| 83 | export VERCEL_ORG_ID="<org-id>" |
| 84 | export VERCEL_PROJECT_ID="<project-id>" |
| 85 | ``` |
| 86 | |
| 87 | Note: `VERCEL_ORG_ID` and `VERCEL_PROJECT_ID` must be set together — setting only one causes an error. |
| 88 | |
| 89 | ## CLI Setup |
| 90 | |
| 91 | Ensure the Vercel CLI is installed and up to date: |
| 92 | |
| 93 | ```bash |
| 94 | npm install -g vercel |
| 95 | vercel --version |
| 96 | ``` |
| 97 | |
| 98 | ## Deploying a Project |
| 99 | |
| 100 | Always deploy as **preview** unless the user explicitly requests production. Choose a method based on what you have available. |
| 101 | |
| 102 | ### Quick Deploy (have project ID — no linking needed) |
| 103 | |
| 104 | When `VERCEL_TOKEN` and `VERCEL_PROJECT_ID` are set in the environment, deploy directly: |
| 105 | |
| 106 | ```bash |
| 107 | vercel deploy -y --no-wait |
| 108 | ``` |
| 109 | |
| 110 | With a team scope (either via `VERCEL_ORG_ID` or `--scope`): |
| 111 | |
| 112 | ```bash |
| 113 | vercel deploy --scope <team-slug> -y --no-wait |
| 114 | ``` |
| 115 | |
| 116 | Production (only when explicitly requested): |
| 117 | |
| 118 | ```bash |
| 119 | vercel deploy --prod --scope <team-slug> -y --no-wait |
| 120 | ``` |
| 121 | |
| 122 | Check status: |
| 123 | |
| 124 | ```bash |
| 125 | vercel inspect <deployment-url> |
| 126 | ``` |
| 127 | |
| 128 | ### Full Deploy Flow (no project ID — need to link) |
| 129 | |
| 130 | Use this when you have a token and team but no pre-existing project ID. |
| 131 | |
| 132 | #### Check project state first |
| 133 | |
| 134 | ```bash |
| 135 | # Does the project have a git remote? |
| 136 | git remote get-url origin 2>/dev/null |
| 137 | |
| 138 | # Is it already linked to a Vercel project? |
| 139 | cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null |
| 140 | ``` |
| 141 | |
| 142 | #### Link the project |
| 143 | |
| 144 | **With git remote (preferred):** |
| 145 | |
| 146 | ```bash |
| 147 | vercel link --repo --scope <team-slug> -y |
| 148 | ``` |
| 149 | |
| 150 | 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. |
| 151 | |
| 152 | **Without git remote:** |
| 153 | |
| 154 | ```bash |
| 155 | vercel link --scope <team-slug> -y |
| 156 | ``` |
| 157 | |
| 158 | Creates `.vercel/project.json`. |
| 159 | |
| 160 | **Link to a specific project by name:** |
| 161 | |
| 162 | ```bash |
| 163 | vercel link --project <project-name> --scope <team-slug> -y |
| 164 | ``` |
| 165 | |
| 166 | If the project is already linked, check `orgId` in `.vercel/project.json` or `.vercel/repo.json` to verify it matches the intended team. |
| 167 | |
| 168 | #### Deploy after linking |
| 169 | |
| 170 | **A) Git Push Deploy — has git remote (preferred)** |
| 171 | |
| 172 | Git pushes trigger automatic Vercel deployments. |
| 173 | |
| 174 | 1. **Ask the user before pushing.** Never push without explicit approval. |
| 175 | 2. Commit and push: |
| 176 | ```bash |
| 177 | git add . |
| 178 | git commit -m "deploy: <description of changes>" |
| 179 | git push |
| 180 | ``` |
| 181 | 3. Vercel builds a |