gcloud-cli
gcloud CLI
Overview
Operate the gcloud CLI as a safe, effective cloud assistant. Read cloud state
freely for debugging and exploration. Always ask the user before any create,
update, or delete operation. This is non-negotiable.
When to use
- The task explicitly involves
gcloudcommands or Google Cloud resource administration through the CLI. - The user needs to inspect, debug, authenticate, or operate GCP resources from the command line.
- The request is about real project state: logs, IAM, services, networking, compute, storage, or config.
- The workflow centers on CLI-driven operations rather than Terraform or application code.
Do NOT use when:
- The task is infrastructure-as-code authoring in Terraform rather than CLI operations.
- The request is for Firebase CLI usage or Google API client-library code.
- The user wants destructive changes without explicit confirmation.
Response format
Always structure the final response with these top-level sections, in this order:
- Summary — state the task, scope, and main conclusion in 1-3 sentences.
- Decision / Approach — state the key classification, assumptions, or chosen path.
- Artifacts — provide the primary deliverable(s) for this skill. Use clear subheadings for multiple files, commands, JSON payloads, queries, or documents.
- Validation — state checks performed, important risks, caveats, or unresolved questions.
- Next steps — list concrete follow-up actions, or write
Noneif nothing remains.
Rules:
- Do not omit a section; write
Nonewhen a section does not apply. - If files are produced, list each file path under Artifacts before its contents.
- If commands, JSON, SQL, YAML, or code are produced, put each artifact in fenced code blocks with the correct language tag when possible.
- Keep section names exactly as written above so output stays predictable across skills.
Workflow
1. Verify context
Before running any gcloud command, check the current authentication and
project context. Wrong project is the #1 cause of gcloud disasters.
gcloud auth list
gcloud config get-value project
gcloud config get-value account
If not authenticated, guide the user through the appropriate auth flow (see Authentication section below). If the active project looks wrong, confirm with the user before proceeding.
2. Classify the operation
Every gcloud command falls into one of two categories:
| Category | Verbs | Action |
|---|---|---|
| Read-only | list, describe, get-iam-policy, logs read, info, operations list |
Execute immediately. No confirmation needed. |
| Mutating | create, delete, update, deploy, set-iam-policy, add-iam-policy-binding, remove-iam-policy-binding, ssh, scp, start, stop, resize |
Show command + impact, ask user for approval. |
When uncertain whether a command mutates state, treat it as mutating.
3. Discover the right command
For unfamiliar services or subcommands, use the built-in help system:
# Find available command groups
gcloud --help
# Explore a service
gcloud compute --help
# Find subcommands
gcloud compute instances --help
# Get flags for a specific command
gcloud compute instances create --help
Always verify flag names via --help rather than guessing. Flags change across
gcloud versions and services.
4. Execute read-only commands freely
Run read commands without asking. These are safe and help gather context:
# List resources
gcloud compute instances list --format="table(name,zone,status)"
# Describe a specific resource
gcloud compute instances describe my-instance --zone=us-central1-a
# Read logs
gcloud logging read "resource.type=gce_instance" --limit=50 --format=json
# Check IAM
gcloud projects get-iam-policy my-project --format=json
Use --format to control output: json for parsing, table for readability,
value for scripting.
5. Confirm before mutating
For ANY create, update, or delete operation:
- State what will happen — describe the resource, the action, and the project/region it affects
- Show the exact command — the user should see precisely what will run
- Ask for explicit approval — do not proceed without a clear "yes"
Example confirmation flow:
I'm going to create a new Compute Engine instance in project
my-project:gcloud compute instances create web-server-1 \ --zone=us-central1-a \ --machine-type=e2-medium \ --image-family=debian-11 \ --image-project=debian-cloudThis will create a billable VM in
us-central1-a. Shall I proceed?
Never use --quiet on destructive commands unless the user explicitly requests
it. The --quiet flag suppresses confirmation prompts that are a safety net.
6. Verify the result
After any mutating operation, run a corresponding read command to confirm:
# After creating an instance
gcloud compute instances describe web-server-1 --zone=us-central1-a --format="table(name,status,networkInterfaces[0].accessConfigs[0].natIP)"
# After deploying to Cloud Run
gcloud run services describe my-service --region=us-central1 --format="table(status.url,status.conditions.status)"
# After updating IAM
gcloud projects get-iam-policy my-project --flatten="bindings[].members" --filter="bindings.members:user@example.com"
Authentication
Choose the auth flow based on context:
| Context | Command | Notes |
|---|---|---|
| Local development (interactive) | gcloud auth login |
Opens browser, stores user credentials |
| Application Default Credentials | gcloud auth application-default login |
For apps using Google client libraries locally |
| Service account (CI/scripts) | gcloud auth activate-service-account --key-file=KEY.json |
Use only when workload identity is unavailable |
| Workload Identity (production) | No gcloud auth needed |
Preferred for GKE, Cloud Run, Cloud Functions — no keys to manage |
| Impersonation | gcloud auth login --update-adc then use --impersonate-service-account=SA@PROJECT.iam.gserviceaccount.com |
Test SA permissions without downloading keys |
Recommendations:
- For local dev:
gcloud auth login+gcloud auth application-default login - For CI/CD: Workload Identity Federation (no keys). Fall back to service account keys only if WIF is not available.
- For production workloads: Always use Workload Identity. Never store keys.
After authenticating, always set the project:
gcloud config set project PROJECT_ID
Common service patterns
For detailed command patterns per service, see references/command-patterns.md.
Quick overview of the most common operations:
| Service | Read | Mutate |
|---|---|---|
| Compute Engine | gcloud compute instances list/describe |
gcloud compute instances create/delete/start/stop |
| Cloud Run | gcloud run services list/describe |
gcloud run deploy, gcloud run services delete |
| Cloud Functions | gcloud functions list/describe/logs read |
gcloud functions deploy/delete |
| GKE | gcloud container clusters list/describe |
gcloud container clusters create/delete/resize |
| IAM | gcloud projects get-iam-policy |
gcloud projects add-iam-policy-binding |
| Cloud Storage | gcloud storage ls/cat |
gcloud storage cp/rm/mv |
| Cloud SQL | gcloud sql instances list/describe |
gcloud sql instances create/delete/patch |
| Pub/Sub | gcloud pubsub topics list, subscriptions list |
gcloud pubsub topics create/delete |
| Logging | gcloud logging read |
gcloud logging write (rare) |
| Networking | gcloud compute networks list/describe |
gcloud compute networks create/delete |
Checklist
- Verified current auth and project context
- Classified operation as read-only or mutating
- Used
--helpto discover unfamiliar commands/flags - Executed read-only commands without blocking on confirmation
- Showed exact command and impact before any mutating operation
- Got explicit user approval before mutating
- Did NOT use
--quieton destructive commands without user request - Verified result with a read command after mutation
- Used appropriate
--formatflag for output readability
Examples
Example: Debug why a Cloud Run service is failing
User asks: "My Cloud Run service api-server in us-east1 is returning 503s,
help me debug."
Agent response (executes all reads freely, no confirmation needed):
# Check service status
gcloud run services describe api-server --region=us-east1 --format="yaml(status)"
# Check recent revisions
gcloud run revisions list --service=api-server --region=us-east1 --format="table(name,active,status)"
# Read logs for errors
gcloud logging read 'resource.type="cloud_run_revision" AND resource.labels.service_name="api-server" AND severity>=ERROR' --limit=20 --format=json
# Check if the container image exists
gcloud run revisions describe REVISION_NAME --region=us-east1 --format="value(image)"
All of these are read-only. Run them immediately and analyze the results.
Example: Create a new instance (mutating)
User asks: "Create an e2-medium instance called web-1 in us-central1-a."
Agent response:
I'll create a Compute Engine instance in project
current-project:gcloud compute instances create web-1 \ --zone=us-central1-a \ --machine-type=e2-medium \ --image-family=debian-11 \ --image-project=debian-cloudThis will create a billable e2-medium VM. Shall I proceed?
After user confirms, run the command, then verify:
gcloud compute instances describe web-1 --zone=us-central1-a --format="table(name,status,machineType,networkInterfaces[0].accessConfigs[0].natIP)"
Common mistakes
| Mistake | Fix |
|---|---|
| Running mutating commands without checking active project | Always run gcloud config get-value project first |
Guessing flag names instead of checking --help |
Use gcloud <command> --help to verify flags |
Using --quiet on delete commands by default |
Only use --quiet when user explicitly requests it |
| Not verifying mutations after execution | Run a corresponding describe or list command |
| Using service account keys in production | Use Workload Identity Federation instead |
Forgetting --format flag, getting unreadable output |
Use --format=json for parsing, --format=table(...) for display |
Running gcloud auth login in CI environments |
Use gcloud auth activate-service-account or Workload Identity |
Not specifying --zone or --region |
Always include location flags to avoid interactive prompts |
Assuming gcloud is installed/authenticated |
Verify with gcloud --version and gcloud auth list first |
| Deleting resources without confirming the project context | Double-check project with user before any delete |
Quick reference
| Operation | Command |
|---|---|
| Check auth | gcloud auth list |
| Check project | gcloud config get-value project |
| Switch project | gcloud config set project PROJECT_ID |
| List all services | gcloud services list --enabled |
| Discover commands | gcloud <group> --help |
| Format as JSON | --format=json |
| Format as table | --format="table(field1,field2)" |
| Filter results | --filter="name:prefix-*" |
| Limit output | --limit=N |
| All regions/zones | gcloud compute regions list / gcloud compute zones list |
Key principles
- Read freely, write cautiously — Read operations are safe and should run immediately to gather context. Every mutating operation requires explicit user approval, no exceptions.
- Verify context first — Always confirm the active project and account before running commands. A command in the wrong project can cause real damage.
- Discover, don't guess — Use
--helpto find correct subcommands and flags. Guessing leads to errors or worse, valid-but-wrong commands. - Verify after mutation — Always run a read command after any create, update, or delete to confirm the change took effect.
- Prefer keyless auth — Workload Identity Federation for production,
gcloud auth loginfor local dev. Service account keys are a last resort.
More from accolver/skill-maker
skill-maker
Create or iteratively improve agent skills with eval-driven refinement when the task is to build a new SKILL.md package or tune an existing skill’s trigger accuracy and performance.
26git-conventional-commits
Generate conventional commit messages from staged git changes when the task is to name or format a commit, not to review code or write release notes.
16pdf-toolkit
Operate the bundled PDF scripts to extract, OCR, create, merge, split, or convert PDFs when the task explicitly involves PDF document processing.
14nostr-event-builder
Construct valid Nostr event JSON and tag structures from requirements when the task is to create or validate concrete events rather than choose which NIPs to use.
12error-handling
Standardize application error handling—taxonomy, propagation, response shapes, logging, and correlation IDs—when the task is to improve consistency of existing error behavior across a codebase.
12pr-description
Generate pull-request descriptions from branch diffs when the task is to explain change scope, motivation, testing, risk, and reviewer guidance for a reviewable branch.
12