{"record":{"id":"25ebbf1ebdd3f4d1","repo":"zed-industries/zed","slug":"is-ambiguous-in-multi-root-workspaces-please","errorCode":null,"errorMessage":"'.' is ambiguous in multi-root workspaces. Please specify a root directory explicitly.","messagePattern":"'\\.' is ambiguous in multi-root workspaces\\. Please specify a root directory explicitly\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/tools/terminal_tool.rs","lineNumber":1349,"sourceCode":"                        \"Command terminated unexpectedly. Output captured:\\n\\n{}\",\n                        content\n                    )\n                }\n            }\n        }\n    };\n    content\n}\n\nfn working_dir(cd: &str, project: &Entity<Project>, cx: &mut App) -> Result<Option<PathBuf>> {\n    let project = project.read(cx);\n\n    if cd == \".\" || cd.is_empty() {\n        let mut worktrees = project.worktrees(cx);\n\n        match worktrees.next() {\n            Some(worktree) => {\n                anyhow::ensure!(\n                    worktrees.next().is_none(),\n                    \"'.' is ambiguous in multi-root workspaces. Please specify a root directory explicitly.\",\n                );\n                Ok(Some(worktree.read(cx).abs_path().to_path_buf()))\n            }\n            None => Ok(None),\n        }\n    } else {\n        let path_style = project.path_style(cx);\n        let worktree_roots = project\n            .worktrees(cx)\n            .filter_map(|worktree| {\n                let worktree = worktree.read(cx);\n                // Skip single-file worktrees: a file can't be a working directory.\n                let root_dir = worktree.root_dir()?;\n                Some((worktree.root_name_str(), root_dir.to_path_buf()))\n            })\n            .collect::<Vec<_>>();","sourceCodeStart":1331,"sourceCodeEnd":1367,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/tools/terminal_tool.rs#L1331-L1367","documentation":"The terminal tool derives a command's working directory from the `cd` parameter. When cd is '.' or empty it defaults to the project's sole worktree root — but only when exactly one worktree exists. In a multi-root workspace there is no unambiguous default, so the tool errors out rather than silently pick the first root.","triggerScenarios":"An agent terminal/exec tool call with cd='.' (or cd omitted) in a project with two or more open worktrees (multiple folders added to the project).","commonSituations":"A second folder is added to the workspace and prompts that used to run fine now fail at working-directory resolution; the user does not realize the project is multi-root.","solutions":["Pass an explicit cd: the worktree's root name (as shown in the project panel) or an absolute path under the desired root","Remove the extra folder from the project if it was added by accident"],"exampleFix":"// before\nrun_terminal_command(command=\"cargo test\", cd=\".\")\n\n// after — name the root explicitly in a multi-root project\nrun_terminal_command(command=\"cargo test\", cd=\"my-app\")","handlingStrategy":"validation","validationCode":"let worktree_count = project.read(cx).worktrees(cx).count();\nif worktree_count > 1 {\n    // require an explicit cd (root name or absolute path) for terminal commands\n}","typeGuard":null,"tryCatchPattern":"Catch the ambiguity message and re-issue the command with cd set to a specific worktree root name or absolute root path.","preventionTips":["Always pass an explicit cd in prompts you share across machines and workspace layouts","Remember root names from the project panel are valid cd values in multi-root workspaces"],"tags":["agent","terminal","multi-root","working-directory"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}