helix-editor/helix · error

--working-dir must specify an initial working directory

Error message

--working-dir must specify an initial working directory

What it means

The -w/--working-dir option requires a value; when argv.next() returns None (option is the last token on the command line) the parser bails before any filesystem check.

Source

Thrown at helix-term/src/args.rs:91

                    Some(path) => args.config_file = Some(path.into()),
                    None => anyhow::bail!("--config must specify a path to read"),
                },
                "--log" => match argv.next().as_deref() {
                    Some(path) => args.log_file = Some(path.into()),
                    None => anyhow::bail!("--log must specify a path to write"),
                },
                "-w" | "--working-dir" => match argv.next().as_deref() {
                    Some(path) => {
                        args.working_directory = if Path::new(path).is_dir() {
                            Some(PathBuf::from(path))
                        } else {
                            anyhow::bail!(
                                "--working-dir specified does not exist or is not a directory"
                            )
                        }
                    }
                    None => {
                        anyhow::bail!("--working-dir must specify an initial working directory")
                    }
                },
                arg if arg.starts_with("--") => {
                    anyhow::bail!("unexpected double dash argument: {}", arg)
                }
                arg if arg.starts_with('-') => {
                    let arg = arg.get(1..).unwrap().chars();
                    for chr in arg {
                        match chr {
                            'v' => args.verbosity += 1,
                            'V' => args.display_version = true,
                            'h' => args.display_help = true,
                            _ => anyhow::bail!("unexpected short arg {}", chr),
                        }
                    }
                }
                "+" => line_number = usize::MAX,
                arg if arg.starts_with('+') => {

View on GitHub (pinned to 079a789e8c)

Solutions

  1. Provide the directory: hx -w /path/to/dir
  2. In scripts, guard: [ -n "$DIR" ] && set -- -w "$DIR" "$@"; or default DIR=${DIR:-$PWD}
  3. Distinguish from error [17]: this one means NO value was given at all

Example fix

# before
hx -w              # no value
hx -w "$DIR"        # $DIR unset/empty

# after
DIR="${DIR:-$PWD}"
hx -w "$DIR" file.rs
Defensive patterns

Strategy: validation

Validate before calling

# Script guard: refuse empty working-dir values
: "${WD:?WD must be set to an existing directory}"
exec hx -w "$WD" "$@"

Prevention

When it happens

Trigger: 'hx -w' with nothing after it; 'hx -w' as the last token of a truncated script line; a following token that the shell consumed as a redirect (e.g. 'hx -w >log' leaves no value).

Common situations: Script variable expansion to empty ('hx -w "$DIR"' with unset DIR and 'set -u' absent - the next() is None); line-wrapped commands losing the argument.

Related errors


AI-assisted analysis of helix-editor/helix@079a789e8c (2026-08-16). Data as JSON: /api/errors/42ece7b89db66520. Report an issue: GitHub.