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

  1. 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.
  2. Check for typos (HKML, HKLU, etc.) in the configured path.
  3. Ensure no leading character consumed the root: input must start with the root key, not "\".
  4. 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

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


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/0984b1bcace46e7a. Report an issue: GitHub.