Communitygithub.com

Vercel CLI (トークン認証)

アクセストークンを使用してVercel CLIでプロジェクトをデプロイおよび管理します。インタラクティブなログインではなく、トークンベースの認証でVercel CLIを操作する場合に使用します。

Vercel CLI (トークン認証) とは?

このスキルは、Vercel CLIをトークンベースの認証で使用するための包括的なガイドを提供します。従来の `vercel login` を必要とせず、環境変数 `VERCEL_TOKEN` を介して認証するため、CI/CD環境や自動化スクリプトに最適です。スキルは、トークンの特定(環境変数、.envファイル、またはユーザーへの問い合わせ)から始まり、プロジェクトIDとチームスコープの設定、デプロイ(プレビュー/本番)、環境変数の管理、ドメイン設定、デプロイの検査までをカバーします。特に、トークンをコマンドライン引数(`--token`)で渡す代わりに環境変数として設定するセキュリティ上のベストプラクティスを強調し、`vercel deploy` コマンドの実行方法や `--no-wait` オプションの使用など、効率的なデプロイ手順を詳細に説明します。Vercel CLI(バージョン35以降)と互換性があります。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/vercel-cli-with-tokens

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Vercel CLI with Tokens (トークン認証)

Vercel CLI を vercel login に依存せず、トークンベースの認証でプロジェクトをデプロイおよび管理します。

ステップ 1: Vercel トークンの特定

Vercel CLI コマンドを実行する前に、トークンの取得元を特定します。以下のシナリオを順に確認してください。

A) 環境変数 VERCEL_TOKEN が既に設定されている

printenv VERCEL_TOKEN

値が返ってきたら準備完了です。ステップ 2 に進んでください。

B) .env ファイルに VERCEL_TOKEN として記述されている

grep '^VERCEL_TOKEN=' .env 2>/dev/null

見つかった場合は、環境変数としてエクスポートします。

export VERCEL_TOKEN=$(grep '^VERCEL_TOKEN=' .env | cut -d= -f2-)

C) .env ファイルに別の名前で記述されている

Vercel トークンと思われる変数(通常 vca_ で始まります)を探します。

grep -i 'vercel' .env 2>/dev/null

出力からトークンを保持する変数を特定し、VERCEL_TOKEN としてエクスポートします。

export VERCEL_TOKEN=$(grep '^<VARIABLE_NAME>=' .env | cut -d= -f2-)

D) トークンが見つからない場合 — ユーザーに問い合わせる

上記のいずれでもトークンが得られない場合は、ユーザーに提供を依頼してください。ユーザーは Vercel アカウントのトークン管理ページ (vercel.com/account/tokens) でアクセストークンを作成できます。


重要: VERCEL_TOKEN が環境変数としてエクスポートされると、Vercel CLI はネイティブに読み取ります。--token フラグとして渡さないでください。 コマンドライン引数に機密情報を含めると、シェル履歴やプロセス一覧に公開されます。

# 悪い例 — トークンがシェル履歴やプロセス一覧に残る
vercel deploy --token "vca_abc123"

# 良い例 — CLI は環境変数 VERCEL_TOKEN を読み取る
export VERCEL_TOKEN="vca_abc123"
vercel deploy

ステップ 2: プロジェクトとチームの特定

同様に、プロジェクト ID とチームスコープを確認します。これにより、vercel link を実行しなくても CLI が適切なプロジェクトをターゲットにできます。

# 環境変数を確認
printenv VERCEL_PROJECT_ID
printenv VERCEL_ORG_ID

# または .env ファイルを確認
grep -i 'vercel' .env 2>/dev/null

プロジェクト URL がある場合(例: https://vercel.com/my-team/my-project)、チームスラッグを抽出します。

# 例: "https://vercel.com/my-team/my-project" から "my-team" を抽出
echo "$PROJECT_URL" | sed 's|https://vercel.com/||' | cut -d/ -f1

環境変数に VERCEL_ORG_ID と VERCEL_PROJECT_ID の両方がある場合は、それらをエクスポートします。CLI はこれらを自動的に使用し、.vercel/ ディレクトリをスキップします。

export VERCEL_ORG_ID="<org-id>"
export VERCEL_PROJECT_ID="<project-id>"

注意: VERCEL_ORG_ID と VERCEL_PROJECT_ID は必ず一緒に設定してください。片方だけを設定するとエラーになります。

CLI セットアップ

Vercel CLI がインストールされ、最新バージョンであることを確認します。

npm install -g vercel
vercel --version

プロジェクトのデプロイ

ユーザーから明示的に本番環境へのデプロイがリクエストされない限り、常に プレビュー としてデプロイします。利用可能な情報に基づいて方法を選択してください。

クイックデプロイ(プロジェクト ID あり — リンク不要)

環境変数に VERCEL_TOKEN と VERCEL_PROJECT_ID が設定されている場合、直接デプロイします。

vercel deploy -y --no-wait

チームスコープを指定する場合(VERCEL_ORG_ID または --scope)。

vercel deploy --scope <team-slug> -y --no-wait

本番環境(明示的にリクエストされた場合のみ)。

vercel deploy --prod --scope <team-slug> -y --no-wait

ステータスを確認します。

vercel inspect <deployment-url>

完全なデプロイフロー(プロジェクト ID なし — リンクが必要)

トークンとチームはあるが、プロジェクト ID が事前に設定されていない場合に使用します。

まずプロジェクトの状態を確認

# プロジェクトに git リモートはあるか?
git remote get-url origin 2>/dev/null

# 既に Vercel プロジェクトにリンクされているか?
cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null

プロジェクトをリンク

git リモートがある場合(推奨)

vercel link --repo --scope <team-slug> -y

Git リモートを読み取り、一致する Vercel プロジェクトに接続します。.vercel/repo.json を作成します。ディレクトリ名でマッチングする通常の vercel link よりも信頼性が高くなります。

git リモートがない場合

vercel link --scope <team-slug> -y

.vercel/project.json を作成します。

特定のプロジェクト名でリンクする場合

vercel link --project <project-name> --scope <team-slug> -y

プロジェクトが既にリンクされている場合は、.vercel/project.json または .vercel/repo.json の orgId を確認して、目的のチームと一致するか検証します。

リンク後のデプロイ

A) Git Push デプロイ — git リモートがある場合(推奨)

Git プッシュにより、Vercel の自動デプロイがトリガーされます。

  1. プッシュ前にユーザーに確認を取ってください。 明示的な承認なしにプッシュしないでください。
  2. コミットしてプッシュします。
    git add .
    git commit -m "deploy: <変更内容の説明>"
    git push
    
  3. Vercel が自動的にビルドを実行します。本番ブランチ以外はプレビューデプロイとなります。
  4. デプロイ URL を取得します。
    sleep 5
    vercel ls --format json --scope <team-slug>
    
    deployments 配列の最新エントリを確認します。

B) CLI デプロイ — git リモートがない場合

vercel deploy --scope <team-slug> -y --no-wait

ステータスを確認します。

vercel inspect <deployment-url>

リモートリポジトリからのデプロイ(コードがローカルにクローンされていない場合)

  1. リポジトリをクローンします。
    git clone <repo-url>
    cd <repo-name>
    
  2. Vercel にリンクします。
    vercel link --repo --scope <team-slug> -y
    
  3. Git プッシュ(プッシュアクセス権がある場合)または CLI デプロイでデプロイします。

.vercel/ ディレクトリについて

リンクされたプロジェクトには、次のいずれかがあります。

  • .vercel/project.json — vercel link で作成されます。projectId と orgId が含まれます。
  • .vercel/repo.json — vercel link --repo で作成されます。orgId、remoteName、projects マップが含まれます。

VERCEL_ORG_ID と VERCEL_PROJECT_ID の両方が環境変数に設定されている場合は不要です。

リンクされていないディレクトリで vercel project inspect や vercel link を実行して状態を検出しないでください。 これらは対話的にプロンプトを表示したり、副作用としてリンクを実行したりします。vercel ls は安全です(リンクされていないディレクトリでは、スコープ内のすべてのデプロイを表示します)。vercel whoami はどこでも安全です。

環境変数の管理

# 全環境に設定
echo "値" | vercel env add VAR_NAME --scope <team-slug>

# 特定の環境(production, preview, development)に設定
echo "値" | vercel env add VAR_NAME production --scope <team-slug>

# 環境変数の一覧表示
vercel env ls --scope <team-slug>

# 環境変数をローカルの .env.local ファイルにプル
vercel env pull --scope <team-slug>

# 変数を削除
vercel env rm VAR_NAME --scope <team-slug> -y

デプロイの検査

# 最近のデプロイを一覧表示
vercel ls --format json --scope <team-slug>

# 特定のデプロイを検査
vercel inspect <deployment-url>

# ビルドログを表示(Vercel CLI v35 以降が必要)
vercel inspect <deployment-url> --logs

# ランタイムリクエストログを表示(デフォルトでライブ追跡、--no-follow でスナップショット)
vercel logs <deployment-url>

ドメインの管理

# ドメインの一覧表示
vercel domains ls --scope <team-slug>

# プロジェクトにドメインを追加 — リンク済みまたは環境変数でリンクされたディレクトリ(引数1つ)
vercel domains add <domain> --scope <team-slug>

# ドメインを追加 — リンクされていないディレクトリ(<project> の指定が必要)
vercel domains add <domain> <project> --scope <team-slug>

Stripe Projects のプラン変更

このプロジェクトが Stripe Projects で管理されている場合。有料または破壊的なプラン変更を実行する前にユーザーに確認を取ってください。 アップグレードは実際のカードに課金され、ダウングレードはシートを削除します。

まず stripe projects status --json を実行して、Vercel リソースのローカル名を確認します。以下の例ではデフォルトの vercel-plan を想定しています。stripe projects add の時点で名前が変更されている場合は、実際の名前に置き換えてください。

  • Pro にアップグレード: stripe projects add vercel/pro(または stripe projects upgrade vercel-plan pro)
  • Hobby にダウングレード: stripe projects downgrade vercel-plan hobby

Pro の特典

  • 月額 $20 のプラットフォーム料金。月額 $20 分の使用クレジットが含まれます。
  • 新しいプロジェクトではデフォルトで Turbo ビルドマシン(30 vCPU、60 GB メモリ)—— Hobby よりも大幅に高速なビルド。
  • 1 つのデプロイシートと無制限の無料 Viewer シート(読み取り専用のコラボレーター、プレビューコメント)。
  • より多くの割り当て(1 TB の Fast Data Transfer、月間 10M Edge Requests)。
  • 有料アドオンが利用可能: SAML SSO、HIPAA BAA、Flags Explorer、Observability Plus、Speed Insights、Web Analytics Plus。

詳細: https://vercel.com/docs/plans/pro-plan

動作確認事項

  • VERCEL_TOKEN を --token フラグとして渡さないでください。 環境変数としてエクスポートし、CLI がネイティブに読み取るようにしてください。
  • トークンをユーザーに問い合わせる前に環境変数を確認してください。 現在の環境と .env ファイルを最初に確認します。
  • デフォルトでプレビューデプロイを使用します。 明示的にリクエストされた場合のみ本番環境にデプロイします。
  • Git にプッシュする前に確認を取ってください。 ユーザーの承認なしにコミットをプッシュしないでください。
  • .vercel/ ファイルを直接変更しないでください。 CLI がこのディレクトリを管理します。ファイルの読み取り(例: orgId の確認)は問題ありません。
  • デプロイされた URL を curl や fetch で確認しないでください。 リンクをユーザーに返すだけにしてください。
  • 構造化された出力が後続の手順に役立つ場合は --format json を使用してください。
  • 確認を求めるコマンドでは -y を使用して、インタラクティブなブロックを回避してください。

トラブルシューティング

トークンが見つからない

環境変数と .env ファイルを確認します。

printenv | grep -i vercel
grep -i vercel .env 2>/dev/null

認証エラー

CLI が Authentication required で失敗する場合:

  • トークンが期限切れまたは無効である可能性があります。
  • 確認: vercel whoami(環境変数 VERCEL_TOKEN を使用)。
  • ユーザーに新しいトークンを依頼してください。

チームが間違っている

スコープが正しいことを確認します。

vercel whoami --scope <team-slug>

ビルド失敗

ビルドログを確認します。

vercel inspect <deployment-url> --logs

よくある原因:

  • 依存関係の欠落 — package.json が完全でコミットされていることを確認します。
  • 環境変数の欠落 — vercel env add で追加します。
  • フレームワークの設定ミス — vercel.json を確認します。Vercel は package.json からフレームワーク(Next.js、Remix、Vite など)を自動検出します。検出が間違っている場合は vercel.json で上書きします。

CLI がインストールされていない

npm install -g vercel

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

関連スキル