Gcp Context
npx machina-cli add skill yu-iskw/google-cloud-observability-plugin/gcp-context --openclawGCP Context Detection
Detect the currently active Google Cloud project and authenticated account.
Purpose
Provides the necessary context for subsequent gcloud commands by identifying the active project ID and user account.
Inputs
None.
Behavior
- Run
gcloud config get-value projectto retrieve the active project ID. - Run
gcloud config get-value accountto retrieve the active account email. - Verify if a project is set; if not, suggest the user to set one using
gcloud config set project [PROJECT_ID]. - Verify if an account is authenticated; if not, suggest
gcloud auth login. - Check for ADC (Application Default Credentials) if running in a non-interactive environment.
Output
Returns a JSON object containing projectId and account.
{
"projectId": "my-project-id",
"account": "user@example.com"
}
References
Source
git clone https://github.com/yu-iskw/google-cloud-observability-plugin/blob/main/skills/gcp-context/SKILL.mdView on GitHub Overview
GCP Context Detection identifies the currently active Google Cloud project and authenticated account. It provides the necessary context for subsequent gcloud commands, ensuring operations run under the correct project and user.
How This Skill Works
It runs gcloud config get-value project to retrieve the active project ID and gcloud config get-value account to retrieve the signed-in user email. If no project or account is set, it suggests commands to fix: gcloud config set project [PROJECT_ID] or gcloud auth login. It also checks for Application Default Credentials in non-interactive environments.
When to Use It
- Starting a new shell session to ensure subsequent gcloud commands target the correct project
- Diagnosing errors about missing or incorrect project or account
- Automating deployments in CI/CD where ADC or explicit credentials are required
- Switching between multiple GCP projects or user accounts
- Auditing scripts and automation to verify the current GCP context before actions
Quick Start
- Step 1: Run the context detection to fetch projectId and account
- Step 2: Review the JSON output and confirm the values are set as expected
- Step 3: If needed, set the project with gcloud config set project [PROJECT_ID] or login with gcloud auth login
Best Practices
- Check projectId and account early in a session and log the values for traceability
- Prefer explicit project configuration in scripts with gcloud config set project
- Use gcloud auth login for interactive users and ADC for non-interactive automation
- Validate ownership of the active project before making changes
- Re-verify context after switching projects, accounts, or environments
Example Use Cases
- A developer runs the context detector before deploying a Cloud Run service to ensure the correct project
- A CI job asserts the detected projectId and account before gcloud deploy
- A script prints the context to logs to aid troubleshooting
- An admin switches between prod and staging projects and checks the current context
- A non-interactive workflow uses ADC and validates the active account automatically