JanDeDobbeleer/oh-my-posh · error
Error, unknown registry key: '%s
Error message
Error, unknown registry key: '%s
What it means
WindowsRegistryKeyValue splits the input on the first backslash and maps the root portion to an HKEY handle. Only HKCR, HKCC, HKCU, HKLM and HKU (long and short forms) are accepted; any other root key string hits the default branch and returns this error. Note the message has a stray unbalanced quote ('%s with no closing ').
Source
Thrown at src/runtime/terminal_windows.go:167
if len(regKey) != 0 {
regPath = strings.TrimSuffix(regPath, `\`+regKey)
}
}
var key registry.Key
switch rootKey {
case "HKCR", "HKEY_CLASSES_ROOT":
key = windows.HKEY_CLASSES_ROOT
case "HKCC", "HKEY_CURRENT_CONFIG":
key = windows.HKEY_CURRENT_CONFIG
case "HKCU", "HKEY_CURRENT_USER":
key = windows.HKEY_CURRENT_USER
case "HKLM", "HKEY_LOCAL_MACHINE":
key = windows.HKEY_LOCAL_MACHINE
case "HKU", "HKEY_USERS":
key = windows.HKEY_USERS
default:
err := fmt.Errorf("Error, unknown registry key: '%s", rootKey)
log.Error(err)
return nil, err
}
k, err := registry.OpenKey(key, regPath, registry.READ)
if err != nil {
log.Error(err)
return nil, err
}
_, valType, err := k.GetValue(regKey, nil)
if err != nil {
log.Error(err)
return nil, err
}
var regValue *WindowsRegistryValue
View on GitHub (pinned to 0976794618)
Solutions
- Use one of the supported roots: HKCR/HKEY_CLASSES_ROOT, HKCC/HKEY_CURRENT_CONFIG, HKCU/HKEY_CURRENT_USER, HKLM/HKEY_LOCAL_MACHINE, HKU/HKEY_USERS - spelled exactly, uppercase.
- Check for typos (HKML, HKLU, etc.) in the configured path.
- Ensure no leading character consumed the root: input must start with the root key, not "\".
- If the value truly lives elsewhere, locate the correct hive (e.g. HKCU for per-user settings).
Example fix
// before registry = "HKML\SOFTWARE\Microsoft\Windows" // after registry = "HKLM\SOFTWARE\Microsoft\Windows"
Defensive patterns
Strategy: validation
Validate before calling
var validRoots = []string{"HKCR","HKEY_CLASSES_ROOT","HKCC","HKEY_CURRENT_CONFIG","HKCU","HKEY_CURRENT_USER","HKLM","HKEY_LOCAL_MACHINE","HKU","HKEY_USERS"}
func validRegistryRoot(p string) bool {
root, _, _ := strings.Cut(p, "\\")
return slices.Contains(validRoots, root)
} Type guard
func hasKnownRegistryRoot(s string) bool {
root, _, ok := strings.Cut(s, "\\")
if !ok { return false }
switch root {
case "HKCR","HKCC","HKCU","HKLM","HKU",
"HKEY_CLASSES_ROOT","HKEY_CURRENT_CONFIG",
"HKEY_CURRENT_USER","HKEY_LOCAL_MACHINE","HKEY_USERS":
return true
}
return false
} Try / catch
val, err := term.WindowsRegistryKeyValue(input)
if err != nil && strings.Contains(err.Error(), "unknown registry key") {
// correct the root key or disable the registry-dependent segment
return nil
} Prevention
- Use the exact uppercase short forms: HKLM, HKCU, HKCR, HKCC, HKU
- Double-check for transposed letters (HKML is a common typo)
- Remember matching is case-sensitive: lowercase roots fail
- Validate configured registry paths in CI against the accepted root list
When it happens
Trigger: Calling WindowsRegistryKeyValue with an unrecognized root key such as "HKCRU", "HKEY_CURRENT_CONFIG_", lowercase "hklm", a typo like "HKML", or an empty root because the input began with a backslash.
Common situations: Typoed root keys in prompt configs (HKML instead of HKLM); case-sensitive matching means "hklm\..." also fails; a template variable expanding to an unexpected prefix.
Related errors
- Error, malformed registry path: '%s'
- unable to delete font file after registry key open error
- unable to open HKEY_CURRENT_USER
- unable to delete font file after registry key set error
- Error, no formatter for type: %d
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/0984b1bcace46e7a.
Report an issue: GitHub.