Jguer/yay · error

invalid option

Error message

invalid option

What it means

Parse rejects argument combinations incompatible with the requested operation. When no operation-compatible path is taken and the -c/--clean flag is present, yay cannot disambiguate it, so it prints guidance (the clean command requires an operation; did you mean -Scc or -Ycc) and returns this error. It exists because bare 'yay -c' is ambiguous in the yay CLI.

Solutions

  1. Replace bare -c with an explicit operation: 'yay -Scc' to clean the package cache or 'yay -Ycc' to clean unneeded orphan packages.
  2. If you want a combined upgrade-and-clean, use 'yay -Syu' followed by 'yay -Scc' as separate commands.
  3. Update scripts/docs that reference 'yay -c' to the current yay syntax.

Example fix

// before
$ yay -c
invalid option
// after
$ yay -Scc   # clean package cache
$ yay -Ycc   # clean unneeded orphans
Defensive patterns

Strategy: validation

Validate before calling

// before invoking the parser, reject a bare clean flag
for _, arg := range args {
    if arg == "-c" || arg == "--clean" {
        hasClean = true
    }
}
if hasClean && !hasOperation(args) {
    return fmt.Errorf("use -Scc or -Ycc instead of bare -c")
}

Try / catch

if err := settings.Parse(cfg, args); err != nil {
    if strings.Contains(err.Error(), "invalid option") {
        // print hint: -Scc / -Ycc
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Running yay with -c or --clean without an accompanying operation (e.g. 'yay -c'), which hits the ExistsArg("c", "clean") branch in the else-clause of Parse's top-level argument handling.

Common situations: Users upgrading from pacman habits ('pacman -Sc') trying 'yay -c'; scripts written for older yay versions where -c cleaned caches; typos like 'yay -cs' instead of 'yay -Scc'.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/a05cad77f2f74189. Report an issue: GitHub.

Appendix: source

Thrown at pkg/settings/parser/parser.go:669

		if err != nil {
			return err
		}
	}

	if a.Op == "" {
		if a.ExistsArg("h", "help") {
			return nil
		}

		if len(a.Targets) > 0 {
			a.Op = "Y"
		} else {
			// Handle args incompatible with -Syu
			if a.ExistsArg("c", "clean") {
				fmt.Println(gotext.Get("the clean command requires an operation to be specified"))
				fmt.Println(gotext.Get("did you mean yay -Scc (clean caches) or yay -Ycc (clean orphaned packages)?"))

				return errors.New(gotext.Get("invalid option"))
			}

			if _, err := a.parseShortOption("-Syu", ""); err != nil {
				return err
			}
		}
	}

	if a.ExistsArg("-") {
		if err := a.parseStdin(); err != nil {
			return err
		}

		a.DelArg("-")

		file, err := os.Open("/dev/tty")
		if err != nil {
			return err

View on GitHub (pinned to 328f4b4939)