{"record":{"id":"1cd3f191b01a2448","repo":"ultraworkers/claw-code","slug":"missing-flag-value-missing-value-for-cwd-usage","errorCode":null,"errorMessage":"missing_flag_value: missing value for --cwd.\nUsage: --cwd <path>, -C <path>, or --directory <path>","messagePattern":"missing_flag_value: missing value for --cwd\\.\nUsage: --cwd <path>, -C <path>, or --directory <path>","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust/crates/rusty-claude-cli/src/main.rs","lineNumber":786,"sourceCode":"        )\n    }\n}\n\nimpl std::error::Error for InvalidOutputPathError {}\n\nfn split_global_cwd_args(\n    args: &[String],\n) -> Result<(Vec<String>, Option<PathBuf>), Box<dyn std::error::Error>> {\n    let mut filtered = Vec::with_capacity(args.len());\n    let mut cwd = None;\n    let mut index = 0;\n\n    while index < args.len() {\n        let arg = &args[index];\n        match arg.as_str() {\n            \"--cwd\" | \"-C\" | \"--directory\" => {\n                let value = args.get(index + 1).ok_or_else(|| {\n                    io::Error::new(\n                        io::ErrorKind::InvalidInput,\n                        \"missing_flag_value: missing value for --cwd.\\nUsage: --cwd <path>, -C <path>, or --directory <path>\",\n                    )\n                })?;\n                cwd = Some(validate_global_cwd(value)?);\n                index += 2;\n            }\n            flag if flag.starts_with(\"--cwd=\") => {\n                let value = &flag[6..];\n                cwd = Some(validate_global_cwd(value)?);\n                index += 1;\n            }\n            flag if flag.starts_with(\"--directory=\") => {\n                let value = &flag[12..];\n                cwd = Some(validate_global_cwd(value)?);\n                index += 1;\n            }\n            flag if global_flag_takes_value(flag) => {","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/ultraworkers/claw-code/blob/08106b0c3771ef5b4a5aa176acccd460e88b7325/rust/crates/rusty-claude-cli/src/main.rs#L768-L804","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before — flag with no value\nclaw --cwd\nclaw -C\n\n# after — value attached via = or as next token\nclaw --cwd=/repo/main\nclaw -C /repo/main serve","handlingStrategy":"validation","validationCode":"fn validate_cwd_args(args: &[String]) -> Result<(), String> {\n    for (i, a) in args.iter().enumerate() {\n        if matches!(a.as_str(), \"--cwd\" | \"-C\" | \"--directory\") && i + 1 >= args.len() {\n            return Err(format!(\"{a} needs a value; use {a}=<path>\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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)"],"tags":["cli","argument-parsing","cwd","usage-error","rust"],"backgroundTag":"cli-flag-missing-value","analyzedSha":"08106b0c3771ef5b4a5aa176acccd460e88b7325","analyzedAt":"2026-08-18T00:29:38.590Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}