[!CAUTION]MANDATORY PRE-CONDITION: EXPLICIT LEAF-LEVEL SYNTAX VALIDATION
All pre-existing knowledge ofgcloudcommands, flags, flag values, and positional argument syntax is stale and prone to hallucination.NEVER propose command parameters, output flag options, execute commands, OR outline step-by-step plans for anygcloudtask before validating leaf-level syntax viagcloud help <command>(or including leaf-level help lookup as a mandatory step in the plan).Mandatory Action Rules:
Direct Execution & Code Generation: ALWAYS invokegcloud help <leaf_command>(e.g.gcloud help compute instances createorgcloud help sql instances create) before proposing or executing the final command syntax. Planning & Strategy Queries: When asked for a plan, strategy, or next steps to achieve a user goal (e.g., "What is your plan to accomplish X..."), the response MUST explicitly include runninggcloud help <leaf_command>as Step 1 of the plan before proposing flags or executing commands. Non-Transitive Validation: Parent command group help (e.g.gcloud help compute) is not sufficient for leaf-level syntax validation. Validation must occur at the specific leaf subcommand level. FORBIDDEN Web Search Fallback: NEVER usesearch_web, web search, or external documentation search tools for gcloud CLI syntax.gcloud help <leaf_command>is the EXCLUSIVE authorized authority for command syntax. User Flag & Project Preservation: When proposing intermediate command steps, ALWAYS preserve all user-specified flags (including--project=<project_id>) in the proposed response text. Mandatory Plan Template: When generating a plan, the response MUST copy this exact 4-step structure:
- Step 1: Syntax Validation via
gcloud help <leaf_command>- Step 2: Parameter Verification (confirming required and optional flags, and explicitly checking if the
--dry-runor--validate-onlyflag is supported)- Step 3: Dry-Run Command Proposal (If
--dry-runor--validate-onlyis supported, there MUST be a--dry-runor--validate-onlyinvocation before the next step.)- Step 4: Command Proposal & Authorization (If the command is on the "Prohibited Operations" denylist, state that autonomous execution is forbidden, and the user MUST be explicitly asked for authorization to proceed. If the command is NOT on the denylist, propose or proceed with execution, while following ALL "Execution Constraints" below.)
gcloud CLI). Following these rules is
critical to avoid hallucinated commands, flags, flag values, and positional
argument syntax, prevent destructive actions, and minimize context window usage.gcloud executable is missing, refer to the official
Google Cloud CLI Installation Guide
to install it on the current platform (Linux, macOS, Windows, etc.).gcloud auth login. Follow the browser
prompts to sign in.--no-browser flag:
gcloud auth login --no-browser. Copy the URL, sign in on another machine,
and return the authentication code.gcloud auth application-default login (append --no-browser for headless
environments).gcloud auth activate-service-account --key-file=path/to/key.json. Note that some organizations may restrict
access to JSON key files for security reasons.gcloud config set auth/impersonate_service_account SERVICE_ACCT_EMAILroles/iam.serviceAccountTokenCreator).gcloud help <command> for the exact command
that is intended to be run (e.g., gcloud help compute instances create).gcloud to save context window space
and reduce latency. DO NOT execute any list command without including at least
one data reduction flag (--limit, --filter, or --format).--format="json(key1, key2, ...)" to select only the
specific fields needed for the task. To understand the advanced projection
and formatting syntax, refer to gcloud topic projections and gcloud topic formats.--limit=N to cap the number of resources returned.--filter to narrow down results server-side. Prioritize
: for pattern matching and never quote the right side of the colon. Treat
the entire filter flag as a singular string without quoting or escaping
characters. To study the filter expression syntax, refer to gcloud topic filters.--format) or filtering (--filter), run the targeted
resource's list command (if supported) with a single-item limit:gcloud <GROUP> <RESOURCE> list --limit=1 --format=json
gcloud command at a time. No command
chaining or sequencing.$(...)), pipes
(|), or redirection (>, >>, <). This is to increase command safety
and ensure commands are more easily understandable and reviewable by users.--quiet / -q): Pass the --quiet (or
-q) global flag on all execution commands (e.g., gcloud pubsub topics delete temp-topic --quiet --project=test-project). AI agents run in
headless, non-interactive environments without a TTY or stdin input
handler. Without --quiet, commands that prompt for user confirmation (such
as deleting resources, approving defaults, or selecting unspecified regions)
will pause execution indefinitely waiting for input, causing background task
timeouts. Including --quiet forces non-interactive mode, causing gcloud
to automatically accept safe default choices or fail immediately with an
explicit error if required parameters are missing.list command without --limit,
--filter, or --format.--project=<PROJECT_ID> to all resource-manipulating and
querying commands (unless running pure local config commands). This avoids
accidental execution against the wrong project.--region, --zone, or
--location), gcloud will trigger an interactive prompt to select a
zone/region. This violates the No Interactivity rule. Always provide
explicit location flags if the command requires them.gcloud compute regions list --project=<PROJECT_ID>gcloud compute zones list --project=<PROJECT_ID>locations list command:gcloud <GROUP> locations list --project=<PROJECT_ID>gcloud artifacts locations list, gcloud kms locations list, gcloud secrets locations list.[!CAUTION] Destructive actions (delete, update, remove) MUST be explicitly authorized by the user. Never invoke them autonomously unless explicitly instructed to do so in the context of a safe, pre-approved workflow.
gcloud * delete (Destructive): Irreversible resource destruction
(e.g., project deletion) or data wiping.gcloud billing * (Financial): Risk of service disruption or unbounded
costs.gcloud organizations * (Governance): Org-level changes affect security
posture for all users.gcloud kms * (Encryption): Risk of permanently locking data.gcloud infra-manager deployments apply (Destructive): Autonomous IaC
execution can destroy managed resources.--dry-run or --validate-only flag (or
equivalent) is listed in the command help output, ALWAYS include the flag in
the proposed command or initial execution step. ALWAYS preview changes with
--dry-run or --validate-only prior to actual execution.--async
flag is highly recommended for long-running operations to avoid blocking the
agentic flow. Note that not every command has an --async flag. For
commands that return an operation ID (whether via --async or by default),
operation status must be polled for completion, if needed for the next step.--quiet): Include --quiet (or -q) on all
proposed or executed commands to guarantee non-interactive execution without
waiting for TTY confirmation prompts.gcloud help <COMMAND> on the target leaf command
prior to execution.gcloud help compute or gcloud help) to discover available subgroups and commands if
the exact command is unknown.gcloud <GROUP> <RESOURCE> list --limit=1 --format=json to inspect JSON keys before constructing filters or
projections. DO NOT execute unconstrained list commands without scoping
flags (e.g., --limit=1) to prevent context window exhaustion.--limit,
--filter, --format) on all command executions.| Task | Command Template |
|---|---|
| Discover Schema | gcloud <GROUP> <RESOURCE> list --limit=1 --format=json |
| Filtered List | gcloud <GROUP> <RESOURCE> list --filter="status:RUNNING" |
| Specific Columns | gcloud <GROUP> <RESOURCE> list --format="json(name, id)" |
| Learn Filters | gcloud topic filters |
| Learn Formats | gcloud topic formats |
| Learn Projections | gcloud topic projections |
| Asynchronous Op | gcloud <COMMAND> --async |
| Check Operation | gcloud operations describe <OPERATION_ID> |
| Common commands | gcloud cheat-sheet |
| List Regions (GCE) | gcloud compute regions list --project=<PROJECT_ID> |
| List Zones (GCE) | gcloud compute zones list --project=<PROJECT_ID> |
| List Locations | gcloud <GROUP> locations list --project=<PROJECT_ID> |
Start with one job and grow from there.