A terminal tool for seeing and switching the cloud account your shell is pointed at: AWS profiles, gcloud configurations, and Application Default Credentials, on one screen.
It exists because gcloud config configurations activate writes to a
machine-wide file, and because ADC is a separate login from your active
gcloud configuration. Between those two facts, gcloud config list can say
staging while terraform apply goes to production, with nothing on screen to
warn you.
go install github.com/san-est/cx/cmd/cx@latest
echo 'eval "$(cx shell-init zsh)"' >> ~/.zshrc # or:
echo 'eval "$(cx shell-init bash)"' >> ~/.bashrcOr download a binary for macOS or Linux from Releases:
tar -xzf cx_<version>_<os>_<arch>.tar.gz
install -m 0755 cx ~/.local/bin/cx
echo 'eval "$(cx shell-init zsh)"' >> ~/.zshrcEvery archive carries a signed build provenance attestation, so you can confirm it was built by the release workflow from this source rather than uploaded by hand:
gh attestation verify cx_<version>_<os>_<arch>.tar.gz --repo san-est/cxOr from a clone, which is also how you get make lint:
make install # builds and installs to ~/.local/bin
echo 'eval "$(cx shell-init zsh)"' >> ~/.zshrcThe shell wrapper is required for switching, and adds the prompt segment. zsh and bash are both supported. See Why a wrapper is needed.
cx dashboard
cx status one-shot report; exits 2 if the shell can be misdirected
cx status --no-probe same, no network, instant
cx use aws <profile> point this shell at an AWS profile
cx use gcp <config> point this shell at a gcloud configuration
cx use k8s <context> point this shell at a Kubernetes context
--yes confirms a target marked production
cx add aws <name> create a key-based AWS profile
cx clear [aws|gcp|k8s|all]
drop this shell's overrides
cx prompt compact status for a shell prompt
cx shell-init [shell] print the shell wrapper (zsh or bash)
cx version print the version, revision, and platform
The dashboard borrows its shape from k9s: a context block and key map at the top, then bordered tables with a count in the title and a full-width highlight on the selected row.
╭─ cx · context ──────────────────────╮╭─ Keys ─────────────────────────╮╭─────────────────╮
│ AWS Profile: client-prod ││ <↑↓> navigate <l> login ││ ▄████▄ ██ ██ │
│ GCP Config: acme-dev ││ <enter> switch <x> clear ││ ██ ▀█▄█▀ │
│ GCP Project: acme-dev-1234 ││ <a> add <r> refresh││ ██ ███ │
│ ADC: you@example.com ││ <e> edit <q> quit ││ ██ ▄█▀█▄ │
│ GCP Pin: shell-local ││ <d> delete ││ ▀████▀ ██ ██ │
╰─────────────────────────────────────╯╰────────────────────────────────╯╰─────────────────╯
╭─ Warnings(1) ─────────────────────────────────────────────────────────────────╮
│ ⚠ ADC quota project (acme-dev) differs from active gcloud project (acme-prod) │
│ terraform and the client libraries follow ADC, not `gcloud config` │
╰───────────────────────────────────────────────────────────────────────────────╯
╭─ AWS Profiles(3) ─────────────────────────────────────────────────────────────╮
│ NAME KIND ACCOUNT SCOPE STATUS │
│ ● default static 111122223333 us-east-1 user/dev │
│ ● ▪ client-prod sso-session 999988887777 eu-west-1 AWSAdmin │
│ ✗ oldclient static+token 444455556666 eu-central-1 expired │
╰───────────────────────────────────────────────────────────────────────────────╯
▪ marks what this shell currently resolves to. Colours follow tokyonight.
The layout follows the terminal as it is resized. Narrower widths shrink the
name and scope columns first, then drop the account id, then the credential
kind; the status column keeps a minimum share, since a status clipped to val…
tells the reader nothing. The key map is a fixed width and the wordmark takes any
slack, so it keeps the same shape at every size rather than spreading into
sparse columns. The wordmark is dropped first when space runs short, then below
about 84 columns the header panels stack, and below 44 the dashboard says the
terminal is too narrow rather than drawing a broken table. Very wide terminals
are capped so rows stay readable.
The dashboard also budgets its height: tables scroll to keep the selection visible and report how many rows are hidden, rather than drawing past the bottom of the terminal, which is what leaves torn frames behind after a resize.
Keys: ↑/↓ or j/k move, enter switch, a add, e edit, d delete,
l log in, x clear, r refresh, q quit. The add menu is navigated the same
way — arrows and enter, or a number key to jump.
e opens the selected target's settings pre-filled, with the form matching how
it authenticates — the SSO fields for an SSO profile, the key fields for a
static one. The name is not editable: renaming means deleting one section and
writing another, and a half-completed rename would strand credentials under the
old name. Delete and re-add instead.
An edit leaves the stored secret alone unless you type a new one, so changing a region cannot silently blank a key.
d deletes, behind a confirmation that says what will be removed and warns when
it is the target this shell is using. A deleted AWS profile leaves any
sso-session block it referred to in place, since other profiles may share it.
Press a to add a target, then pick from the list. Creating one is a form inside cx — it writes
~/.aws/config, ~/.aws/credentials (mode 600) or ~/.config/gcloud directly:
╭─────────────────────────────────────────────────────────────╮
│ Add AWS profile (access keys) │
│ │
│ Profile name * client-prod │
│ Access key ID * AKIAEXAMPLEKEYID │
│ ▸ Secret access key * ••••••••••••• │
│ Session token optional — temporary credentials │
│ Default region eu-west-1 │
│ │
│ tab/↑↓ move · enter next, or save on the last · esc cancel │
╰─────────────────────────────────────────────────────────────╯
Only browser sign-ins leave the app, because only the vendor CLI can complete
them: l on a row runs aws sso login or gcloud auth login, and a then d
runs gcloud auth application-default login. Those suspend the dashboard and
reload when the CLI exits.
Writes edit the target section line by line and leave the rest of the file untouched, so indented sub-properties — which a parse-and-rewrite would silently drop — survive.
cx status exits 2 when it finds state that can misdirect a command, so it
can gate a script:
cx status --no-probe >/dev/null || { echo "refusing to apply"; exit 1; }cx add aws <name> creates a key-based AWS profile without opening the
dashboard:
cx add aws client-prod --region eu-west-1It asks for what the flags did not supply, and the secret is never echoed:
Access key ID: AKIAEXAMPLEKEYID
Secret access key:
Default region (optional): eu-west-1
cx: wrote AWS profile client-prod
point this shell at it with: cx use aws client-prod
Keys go to ~/.aws/credentials (mode 600) and settings to ~/.aws/config,
which is where the AWS CLI itself puts them.
| Flag | |
|---|---|
--region <region> |
default region |
--access-key <id> |
access key id; asked for if omitted |
--with-session-token |
also ask for a session token |
--force |
replace an existing profile |
A credential is never a command-line argument. A process's arguments are
readable by every other process on the machine, and they stay in shell history,
so there is no --secret-key flag; passing one is refused with an explanation
rather than quietly ignored. The secret and the session token are only ever read
from the terminal or from stdin.
Without a terminal, values are read from stdin one per line, in the order the prompts would have come, so the command can be scripted:
printf '%s\n%s\n%s\n' "$KEY_ID" "$SECRET" eu-west-1 | cx add aws client-prodReplacing an existing profile needs --force: overwriting one discards
credentials that may be the only copy.
Only key-based AWS profiles can be created this way. The others are browser
sign-ins that only the vendor CLI can complete, and the dashboard's a already
runs those.
cx prompt prints a compact summary:
~/work aws:client-prod gcp:acme-dev
A trailing ! means this shell's gcloud target comes from the machine-wide
file, so another terminal can change it out from under you:
~/work aws:default gcp:acme-prod!
It reads only local files — about 5 ms, versus roughly 800 ms for a
single gcloud config get-value — so it never stalls a prompt.
zsh has a right-hand prompt, so shell-init fills in RPROMPT for you. bash
has no equivalent, and overwriting PS1 would throw away whatever you already
have there, so it is left to you. shell-init defines a cx_prompt function
for the purpose:
PS1='\w $(cx_prompt)\$ 'Single quotes matter: PS1 is expanded on every render, so the command
substitution has to survive being assigned.
Every new terminal would otherwise start unpinned, falling back to the shared gcloud file — which means a "your target is shared" warning would be permanently true, and therefore useless.
So shell-init pins each shell, at startup, to whatever configuration was
selected at that moment. Another terminal switching afterwards cannot retarget
you, and the warning goes quiet because the hazard is gone rather than merely
reported.
One consequence worth knowing: running gcloud config configurations activate
by hand no longer affects the shell you run it in, because that shell is pinned.
Use cx use gcp <name> instead, or cx clear gcp to follow the machine-wide
setting again. CX_NO_AUTOPIN=1 disables it entirely.
Starship's own [aws] and [gcloud] modules already show the current target,
and they do honour the environment variables cx sets, so a switch shows up
immediately. What they cannot show is whether that target is safe. Add cx as
a custom module for exactly that:
[custom.cx]
command = "cx prompt --warn"
when = "cx prompt --warn"
format = "[$symbol$output]($style) "
symbol = "⚠ "
style = "bold red"
description = "cloud context hazards"Then add ${custom.cx} to your format string.
cx prompt --warn prints nothing and exits non-zero when everything is fine, so
the module disappears entirely unless there is something to say. When there is:
~/work ⚠ gcp:shared adc:acme-dev
gcp:shared— the target comes from the machine-wide file, and more than one configuration exists (with only one there is nothing to confuse it with, so this stays quiet)gcp:no-config—active_confignames a configuration that no longer existsadc:<project>— ADC will hit that project, not the one gcloud reports
Do not set shell = ["sh", "-c"] on the module. Starship pipes the command
to the shell on stdin, so the explicit -c becomes sh -c -c and the module
fails silently.
shell-init skips RPROMPT when starship is running, since starship rewrites
it on every render. Set CX_NO_RPROMPT=1 to skip it in any shell.
kubectl config use-context writes to ~/.kube/config, a file every terminal
on the machine reads. Switching context in one window silently retargets all of
them — the same hazard as gcloud config configurations activate, in a
different file.
cx use k8s prod # this shell only
cx clear k8s # back to the shared default, still pinnedThe dashboard shows them in their own pane, alongside AWS and gcloud, with the cluster and namespace each one resolves to:
╭─ Kubernetes Contexts(3) ─────────────────────────────────────────────────────────╮
│ NAME KIND CLUSTER NAMESPACE STATUS │
│ ● arn:aws:eks:eu-we… context platform payments valid │
│ ● ▪ gke_acme-p… [prod] context gke-main default valid │
│ ○ orphaned context deleted-cluster default cluster no…│
╰──────────────────────────────────────────────────────────────────────────────────╯
enter pins the selected context to this shell. A context whose cluster or user
is no longer defined is flagged there and then, rather than when a command
later fails on it.
e, d and l do not apply to a context and say so: cx reads the kubeconfig
and writes only its own overlay, so editing and deleting belong to kubectl, and
a context authenticates through whatever user its kubeconfig names.
cx status lists the same contexts and exits 2 while the selection is one
another terminal can change. The prompt segment marks it:
~/work k8s:prod! # ! means the shared kubeconfig decides this
~/work k8s:prod # pinned to this shell
Switching writes a kubeconfig overlay: a four-line file carrying nothing but
current-context, placed at the front of KUBECONFIG.
# Written by cx. Points this shell, and only this shell, at one context.
apiVersion: v1
kind: Config
current-context: 'prod'kubectl merges every file on the search path and takes current-context from
the first that sets one, so this shell is retargeted while ~/.kube/config is
never written to.
Copying the whole kubeconfig is the obvious alternative and a worse one. The copy goes stale the moment a cluster is added, and it duplicates every bearer token and client certificate into a second file on disk. The overlay holds one context name and no credentials at all.
It also makes kubectl config use-context shell-local as a side effect,
because kubectl writes current-context to the first file on the search path,
which is now cx's overlay. The habit stops being dangerous rather than being
reported forever — the same reasoning as the gcloud auto-pin.
Overlays live in $XDG_STATE_HOME/cx/kube (or ~/.local/state/cx/kube), one
per shell, named by the shell's process id. CX_KUBE_DIR overrides the
location.
cx runs kubectl config view -o json rather than parsing the kubeconfig
itself. This is a deliberate exception to reading configuration from disk: a
YAML dependency would be a third-party parser running against a file holding
client certificates, a hand-rolled one would be a YAML subset parser, and
kubectl is a Go binary that costs about 28 ms here — against gcloud's 400 ms —
and redacts every credential before cx sees the bytes.
The prompt segment does not pay that cost. It reads current-context from the
first kubeconfig that sets one, which is cx's own overlay whenever the shell is
pinned.
Some targets deserve a pause. Name them in ~/.config/cx/config, by exact name
or by glob:
[production]
aws = client-prod, *-prod
gcp = acme-prod, prod-*
k8s = prod, *-prod$XDG_CONFIG_HOME is honoured, and CX_CONFIG overrides the path outright.
Flagged targets are marked [prod] wherever they appear — the dashboard, the
context header, cx status, and the prompt segment:
~/work aws:client-prod[prod] gcp:acme-staging
Switching to one asks first:
AWS profile client-prod is marked production. Point this shell at it? [y/N]
In the dashboard, enter on a flagged row opens the same confirmation instead
of switching immediately. Anything other than an explicit y or yes is a no.
With no terminal to ask on — a script, a CI job — cx use refuses rather
than guessing:
cx: AWS profile client-prod is marked production, and there is no terminal to confirm on.
Pass --yes if this is deliberate.
A deployment script that means it says cx use aws client-prod --yes. One that
did not mean it fails loudly instead of quietly pointing itself at production.
This does not change the exit code of cx status. Deploying to production
is legitimate; a gate that fails on it would teach people to stop using the
gate. cx status still exits 2 only for state that can misdirect a command,
which is a different thing from a command aimed at production on purpose.
Matching is on the target's name rather than its account or project id, because
the prompt segment and cx status --no-probe must answer without touching the
network, and for several credential kinds the account is known only after a
probe. A malformed pattern is reported rather than ignored — a typo that
silently protects nothing is the worst way for this to fail.
Per target
| Column | Meaning |
|---|---|
▪ |
this target is what the current shell resolves to |
| kind | how credentials are obtained — sso-session, assume-role, credential_process, static, static+token |
| status | probed against STS / gcloud, concurrently, with a timeout |
static+token is highlighted because a hand-pasted session token is the only
credential kind here that expires with no way to refresh itself. It causes most
"it worked yesterday" failures.
Across targets — hazards no single row can express:
- the gcloud target comes from machine-wide
active_configrather than this shell'sCLOUDSDK_ACTIVE_CONFIG_NAME, so another terminal can retarget you active_confignames a configuration that no longer exists, which makes gcloud fall back to built-in defaults without saying so- ADC's quota project differs from the active gcloud project
- ADC authenticates as a different principal than gcloud
CLOUDSDK_CORE_PROJECT/CLOUDSDK_CORE_ACCOUNTare silently overriding the active configuration
A program cannot change the environment of the shell that started it. When cx
exits, anything it exported dies with it.
So cx does not try. The wrapper function hands it a scratch file, cx writes
the environment changes there, and the wrapper sources that file — which does
run in your shell, and so can change it. cx shell-init zsh — or bash —
prints it.
Without the wrapper installed, cx says so rather than appearing to work.
Switching only ever sets environment variables. It never runs
gcloud config configurations activate or kubectl config use-context, because
those write machine-wide state and would retarget terminals you are not looking
at. That is the bug this tool was built to detect, so it must not cause it.
Switching AWS clears ambient credential variables. The AWS CLI reads
AWS_ACCESS_KEY_ID before AWS_PROFILE. Leaving stale keys in place is how a
profile switch appears to work while commands keep hitting the old account.
Probes shell out to aws and gcloud. Using the SDKs directly would mean
reimplementing SSO token caches, credential_process helpers, and every other
resolution mechanism. Shelling out guarantees that what cx reports is exactly
what your terminal will do.
Reading configuration does not. gcloud is a Python program with roughly a
second of startup cost. The config files are a documented stable format, so cx
parses them directly, renders instantly, and fills in probe results
asynchronously.
The INI parser is hand-written. The AWS config format allows indented
sub-properties under a key (s3 = followed by an indented block). Strict INI
libraries mis-parse those as top-level keys and corrupt the section.
Emitted shell values are single-quoted. Names come from files on disk, and should not be able to run anything when the wrapper sources the script.
- Phase 1 — read-only dashboard across AWS, GCP, and ADC
- Prompt segment
- Phase 2 — switching via the shell wrapper, environment variables only
- Phase 3 — per-shell Kubernetes context, so
use-contextin one terminal cannot retarget another. Implemented as a kubeconfig overlay rather than the copy originally planned: a copy goes stale and duplicates credentials, while an overlay carries only a context name - Kubernetes pane in the dashboard
- Mark targets as production in a config file; require confirmation
- Add and re-authenticate targets from the dashboard
-
cx add aws <name>for static-key profiles from the command line
make lint # fmt + vet + test
make build
make install
Tests must not read the ambient environment. cx exports
CLOUDSDK_ACTIVE_CONFIG_NAME into every shell it is installed in, so a test
that inherits the caller's environment will pass in CI and fail on the machine
of anyone who actually uses the tool.
Patches are welcome — see CONTRIBUTING.md. In short: open an
issue before anything non-trivial, sign off every commit (git commit -s), sign
commits with a key GitHub can verify, and keep make lint green.
Because this tool touches credentials, workflows on pull requests from forks do
not run until a maintainer approves each run, and main requires code-owner
review, green checks, and resolved conversations. Contributors are also asked to
abide by the Code of Conduct.
cx reads and writes cloud credential files. If you find a way to leak a
secret, inject a command through a configuration value, or make cx report a
target other than the one the shell resolves to, please do not open a public
issue — use
private vulnerability reporting.
SECURITY.md sets out the scope, the response targets, and the
design properties that are treated as security guarantees.
Apache License 2.0. Copyright 2026 Vasil Boyadzhiev.