JanDeDobbeleer/oh-my-posh · error

unknown command %q for %q

Error message

unknown command %q for %q

What it means

During Execute, route walks the command tree matching positional tokens to child commands. If the first positional token matches no child (and no alias) of the root command, and the root has subcommands, routing fails with this error before any command runs. It mirrors cobra's message so scripts see familiar output.

Source

Thrown at src/cmdtree/cmdtree.go:245

	return cmd.execute(remaining)
}

// route walks the command tree: at each level the first token that is not a
// flag (accounting for flags that consume a value) addresses a child.
func (c *Command) route(args []string) (*Command, []string, error) {
	current := c

	for {
		name, ok := firstPositional(current, args)
		if !ok {
			return current, args, nil
		}

		child := current.findChild(name)
		if child == nil {
			if current == c && len(current.commands) > 0 {
				return nil, nil, fmt.Errorf("unknown command %q for %q", name, c.CommandPath())
			}

			return current, args, nil
		}

		args = removeFirst(args, name)
		current = child
	}
}

// firstPositional finds the first argument that cannot be a flag or a flag
// value at this command level.
func firstPositional(c *Command, args []string) (string, bool) {
	flags := c.mergedFlags()

	for i := 0; i < len(args); i++ {
		arg := args[i]

View on GitHub (pinned to 0976794618)

Solutions

  1. Run 'omp --help' (or the tool's help) and use an exact subcommand name from Available Commands.
  2. Check the binary version - the command may have been renamed/added; upgrade or use the old name.
  3. Fix typos in scripts/aliases invoking the command.
  4. If a value (not a subcommand) was intended as the first argument, restructure the invocation or use -- before it so routing doesn't treat it as a command.

Example fix

// before
args := []string{"inti", "shell"} // unknown command "inti" for "oh-my-posh"
// after
args := []string{"init", "shell"}
Defensive patterns

Strategy: try-catch

Validate before calling

func validateSubcommand(root string, valid []string, args []string) error {
    if len(args) > 0 && !slices.Contains(valid, args[0]) {
        return fmt.Errorf("%q is not a valid subcommand of %s; valid: %v", args[0], root, valid)
    }
    return nil
}

Try / catch

if err := cmd.Execute(); err != nil {
    if strings.HasPrefix(err.Error(), "unknown command") {
        fmt.Fprintf(os.Stderr, "Error: %v\nTip: run '<root> --help' to list available commands.\n", err)
        os.Exit(1)
    }
    return err
}

Prevention

When it happens

Trigger: Execute() (or SetArgs + Execute) called with os.Args whose first non-flag token is not a registered child name/alias of the root, while the root has children: e.g. 'omp foo --bar' with no 'foo' command.

Common situations: Typos in the subcommand name; invoking a command that exists in a newer/older binary version; running a script written for another tool; passing a file path as the first argument to a command that doesn't take one.

Related errors


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