charmbracelet/crush · error

env -S requires a program

Error message

env -S requires a program

What it means

In parseEnvShebang, the -S (split-string) flag was given to env but no program followed it, so there is nothing to execute after tokenization. The parser rejects '-S' with an empty remainder.

Source

Thrown at internal/shell/dispatch.go:342

	}

	useSplit := false
	if strings.HasPrefix(rest, "-") {
		var flag, after string
		if idx := strings.IndexAny(rest, " \t"); idx >= 0 {
			flag = rest[:idx]
			after = strings.TrimLeft(rest[idx+1:], " \t")
		} else {
			flag = rest
			after = ""
		}
		if flag != "-S" {
			return nil, fmt.Errorf("unsupported env flag: %s", flag)
		}
		useSplit = true
		rest = after
		if rest == "" {
			return nil, errors.New("env -S requires a program")
		}
	}

	if rest == "" {
		return nil, errors.New("env: missing program name")
	}

	var prog, remainder string
	if idx := strings.IndexAny(rest, " \t"); idx >= 0 {
		prog = rest[:idx]
		remainder = strings.TrimLeft(rest[idx+1:], " \t")
	} else {
		prog = rest
	}

	sb := &shebang{interpreter: prog}
	if remainder != "" {
		if useSplit {

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Append the interpreter (and any arguments) after -S: '#!/usr/bin/env -S node --max-old-space-size=4096'.
  2. If no arguments are needed, drop -S entirely: '#!/usr/bin/env node'.
  3. Lint scripts for env shebangs that end with a flag and no program.

Example fix

// before
#!/usr/bin/env -S
// after
#!/usr/bin/env -S python3 -u
Defensive patterns

Strategy: validation

Validate before calling

line, _ := bufio.NewReader(f).ReadString('\n')
if strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), "#!")) == "/usr/bin/env -S" || strings.HasSuffix(strings.TrimSpace(line), "-S") {
    return errors.New("env -S shebang missing program")
}

Try / catch

if err := dispatch(script); err != nil {
    if strings.Contains(err.Error(), "-S requires a program") {
        return fmt.Errorf("%s: -S needs an interpreter argument", script)
    }
    return err
}

Prevention

When it happens

Trigger: A shebang such as '#!/usr/bin/env -S' with nothing after the flag, or '#!/usr/bin/env -S ' (only whitespace).

Common situations: Copying portable-shebang examples and dropping the interpreter, or scripts generated for long-argument shebang workarounds where the arguments were stripped.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/bf140addbb8d0896. Report an issue: GitHub.