cube-js/cube · error
context `{name}` not found in config (run `cube login --cont
Error message
context `{name}` not found in config (run `cube login --context {name}`) What it means
The CLI resolves authentication from a named context in its config file. When the user explicitly passes --context <name> (or CUBE_CONTEXT) but no context with that name exists in the config, `api()` bails with this message suggesting `cube login --context <name>` to create it.
Source
Thrown at rust/cube-cli/src/main.rs:70
}
impl Ctx {
fn new(global: &GlobalArgs) -> Result<Self> {
Ok(Self {
json: global.json,
config: config::Config::load()?,
api_url: global.api_url.clone(),
token: global.token.clone(),
context: global.context.clone(),
})
}
/// Build an authenticated API client from flags, env, or the config file.
pub fn api(&self) -> Result<client::Client> {
let ctx = self.config.context(self.context.as_deref());
if let Some(name) = &self.context {
if ctx.is_none() {
bail!("context `{name}` not found in config (run `cube login --context {name}`)");
}
}
let url = self
.api_url
.clone()
.or_else(|| ctx.map(|(_, c)| c.url.clone()))
.map(|u| util::normalize_url(&u));
// An explicit --token / CUBE_API_KEY wins and disables auto-refresh
// (it isn't tied to a stored refresh token).
let token = self
.token
.clone()
.or_else(|| ctx.map(|(_, c)| c.api_key.clone()));
match (url, token) {
(Some(url), Some(token)) => {
// Enable auto-refresh only when using the context's own access
// token and it has a refresh token saved alongside it.
let refresh = if self.token.is_none() {View on GitHub (pinned to 7d981676b3)
Solutions
- Run `cube login --context <name>` to create and authenticate the context
- Check the exact context name in the CLI config file (~/.cube/config or equivalent)
- Fix the --context flag value or the CUBE_CONTEXT env var typo
Example fix
// before cube deployments list --context prodction // after cube login --context production cube deployments list --context production
Defensive patterns
Strategy: validation
Validate before calling
const ctx = process.env.CUBE_CONTEXT || flags.context;
const cfg = JSON.parse(fs.readFileSync(configPath, "utf8"));
if (ctx && !(ctx in (cfg.contexts ?? {}))) {
throw new Error(`context '${ctx}' missing; run: cube login --context ${ctx}`);
} Type guard
const hasContext = (c: unknown): c is { contexts: Record<string, unknown> } =>
typeof c === "object" && c !== null && "contexts" in c; Try / catch
try {
run(`cube deployments list --context ${ctx}`);
} catch (e) {
if (String(e).includes("not found in config")) {
run(`cube login --context ${ctx}`);
run(`cube deployments list --context ${ctx}`);
} else throw e;
} Prevention
- Log into every named context after installing the CLI on a new machine
- Mount/copy the CLI config file into CI containers
- Use consistent context names documented for the team
When it happens
Trigger: Running any command with --context production when `cube login --context production` was never run; typos in the context name; switching machines without copying the CLI config; CI environments missing the config file.
Common situations: Multiple environments (staging/prod) managed via contexts; fresh laptop setup; sharing scripts that hard-code a context name.
Related errors
- Provided token isn't for ${dotCubeCloud.url}
- context `{name}` not found (run `cube login --name {name}`)
- not logged in: run `cube login`, or set CUBE_API_URL and CUB
- device code expired before it was authorized; run `cube logi
- authorization was denied in the browser
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/45504664777d6742.
Report an issue: GitHub.