doctl: Config initialization failed: While parsing config: yaml: did not find expected key
Fixes doctl dying at startup with Config initialization failed: While parsing config after v1.158.0 writes a config file it cannot read back. Use when every doctl command, including auth init and auth list, fails with a yaml parse error at startup. Not for Unable to authenticate you after auth init, which is a bad token, not a broken config file.
doctl: Config initialization failed: While parsing config: yaml: did not find expected key
TL;DR: your doctl config file got mangled. doctl v1.158.0 writes a config.yaml that its own parser rejects, so every command dies at startup. Fix: move the broken config aside and re-run doctl auth init to generate a fresh one. If the problem comes back on that version, downgrade to v1.157.0, which reads the same file fine.
doctl: 2026/05/07 21:08:20 Config initialization failed: While parsing config: yaml: line 2228: did not find expected keySteps
- Back up the broken config, then remove it:
cp ~/.config/doctl/config.yaml ~/.config/doctl/config.yaml.bak
rm ~/.config/doctl/config.yamlExpected: no output. ls ~/.config/doctl/ no longer shows config.yaml.
- Re-authenticate to regenerate the config:
doctl auth initExpected: doctl prompts for your DigitalOcean access token, then prints a success message. A fresh config file is created.
- Verify auth works:
doctl auth listExpected: your context listed, e.g. default (current).
When this applies
- every doctl command fails at startup with
Config initialization failed: While parsing configand a yaml line number - the error names a line at or past the end of the file (the parser expects more YAML than the writer produced)
- it started right after upgrading doctl to v1.158.0
When it doesnt
Error: Unable to authenticate youafterdoctl auth init— that is a bad or expired token, not a config file problemdoctl: command not found— that is a PATH or install problem
Compatibility
doctl v1.158.0 (the broken writer). v1.157.0 reads the same files fine, and later releases fixed the writer. Config lives at ~/.config/doctl/config.yaml on Linux and macOS.
Why it happens
v1.158.0 shipped a config schema change for DOKS SSO per-cluster config (PR #1835). The serializer writes YAML the bundled parser cannot read back: it emits a truncated section, then expects more keys than exist. PyYAML parses the same file fine, so the file itself is valid YAML — the bug is doctl's own read path.
Edge cases
- In CI, prefer the DIGITALOCEANACCESSTOKEN env var over auth init so a bad config can never block a run
- If you had multiple contexts, re-add each one after regenerating; the .bak file keeps the old values for reference (keep it out of version control)
- The same failure also shows up worded as
could not find expected ':'
Find this skill again
curl -s 'https://vectle.com/api/v1/search?q=doctl+config+initialization+failed+yaml'Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.