ultraworkers/claw-code · error · std::io::Error
missing_flag_value: missing value for --cwd. Usage: --cwd <p
Error message
missing_flag_value: missing value for --cwd. Usage: --cwd <path>, -C <path>, or --directory <path>
What it means
Returned by split_global_cwd_args in the claw CLI parser when --cwd (or its aliases -C / --directory) appears as the last argument with no value following it. The parser strips global cwd flags before subcommand dispatch and requires a consume-able next token; finding none, it raises io::Error(InvalidInput) with the missing_flag_value message and usage hint. It is a pure command-line usage error — nothing is executed.
Source
Thrown at rust/crates/rusty-claude-cli/src/main.rs:786
)
}
}
impl std::error::Error for InvalidOutputPathError {}
fn split_global_cwd_args(
args: &[String],
) -> Result<(Vec<String>, Option<PathBuf>), Box<dyn std::error::Error>> {
let mut filtered = Vec::with_capacity(args.len());
let mut cwd = None;
let mut index = 0;
while index < args.len() {
let arg = &args[index];
match arg.as_str() {
"--cwd" | "-C" | "--directory" => {
let value = args.get(index + 1).ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidInput,
"missing_flag_value: missing value for --cwd.\nUsage: --cwd <path>, -C <path>, or --directory <path>",
)
})?;
cwd = Some(validate_global_cwd(value)?);
index += 2;
}
flag if flag.starts_with("--cwd=") => {
let value = &flag[6..];
cwd = Some(validate_global_cwd(value)?);
index += 1;
}
flag if flag.starts_with("--directory=") => {
let value = &flag[12..];
cwd = Some(validate_global_cwd(value)?);
index += 1;
}
flag if global_flag_takes_value(flag) => {View on GitHub (pinned to 08106b0c37)
Solutions
- Supply the value inline: claw --cwd /path/to/dir <subcommand>
- Prefer the equals form so a missing value is impossible to leave dangling: claw --cwd=/path/to/dir
- In scripts, guard the variable: : "${SESSION_DIR:?SESSION_DIR must be set}" before using it after --cwd
- Check the usage hint in the message: only --cwd <path>, -C <path>, --directory <path> are accepted spellings
Example fix
# before — flag with no value claw --cwd claw -C # after — value attached via = or as next token claw --cwd=/repo/main claw -C /repo/main serve
Defensive patterns
Strategy: validation
Validate before calling
fn validate_cwd_args(args: &[String]) -> Result<(), String> {
for (i, a) in args.iter().enumerate() {
if matches!(a.as_str(), "--cwd" | "-C" | "--directory") && i + 1 >= args.len() {
return Err(format!("{a} needs a value; use {a}=<path>"));
}
}
Ok(())
} Prevention
- Prefer the --cwd=/path form — the value is syntactically attached and cannot be left off
- In scripts, fail fast on unset variables: : "${DIR:?DIR must be set}" before building the command
- When wrapping claw in shell/CI code, quote and default the value: claw --cwd "${SESSION_DIR:?}" ...
- Remember the accepted spellings: --cwd, -C, --directory (space or = form only)
When it happens
Trigger: Running `claw --cwd` or `claw -C` or `claw --directory` as the final token, e.g. `claw --cwd` (nothing after), `claw mcp list --cwd` (flag placed last after a subcommand in some shell completions), or a script that builds the command from an unset variable: claw --cwd "$SESSION_DIR" with SESSION_DIR empty-set to nothing and the flag left dangling only when the var expands to zero args after it.
Common situations: Shell scripts interpolating a possibly-unset variable right after --cwd; typos/truncated commands from history editing; wrapper scripts that append flags conditionally but append the flag without its value; CI YAML where the value lives on a continued line that got dropped.
Related errors
- rustyline editor should initialize
- HOME is not set (on Windows, set USERPROFILE or HOME, or use
- credentials file must contain a JSON object
- session file was removed during save (possible concurrent mo
- session file was removed during write (possible concurrent m
AI-assisted analysis of ultraworkers/claw-code@08106b0c37 (2026-08-18).
Data as JSON: /api/errors/1cd3f191b01a2448.
Report an issue: GitHub.