zed-industries/zed · error
Working directory cannot be empty
Error message
Working directory cannot be empty
What it means
Before sending session/new or session/load, Zed derives the session's cwd from the first entry of the work_dirs PathList; remaining entries become additional_directories (when the agent supports them). An empty list leaves no cwd to send — ACP requires one — so this error is thrown before any RPC is made.
Source
Thrown at crates/agent_servers/src/acp.rs:1481
self,
session_id: acp::SessionId,
mcp_servers: Vec<acp::McpServer>,
) -> acp::ResumeSessionRequest {
acp::ResumeSessionRequest::new(session_id, self.cwd)
.additional_directories(self.additional_directories)
.mcp_servers(mcp_servers)
}
}
fn session_directories_from_work_dirs(
work_dirs: &PathList,
supports_additional_directories: bool,
) -> Result<SessionDirectories> {
let mut ordered_paths = work_dirs.ordered_paths();
let cwd = ordered_paths
.next()
.cloned()
.ok_or_else(|| anyhow!("Working directory cannot be empty"))?;
let additional_directories = if supports_additional_directories {
ordered_paths.cloned().collect()
} else {
Vec::new()
};
Ok(SessionDirectories {
cwd,
additional_directories,
})
}
fn work_dirs_from_session_info(cwd: PathBuf, additional_directories: Vec<PathBuf>) -> PathList {
let mut seen_paths = HashSet::default();
let mut paths = Vec::with_capacity(1 + additional_directories.len());
seen_paths.insert(cwd.clone());
paths.push(cwd);View on GitHub (pinned to bc538def45)
Solutions
- Open a folder in the project so the work-dir list is non-empty, then retry
- When building the request programmatically, always pass at least one existing directory
Example fix
// before — no working directory open_session(&project, PathList::default(), cx) // after — first entry becomes the session cwd open_session(&project, PathList::new(vec![worktree_abs_path]), cx)
Defensive patterns
Strategy: validation
Validate before calling
if work_dirs.ordered_paths().next().is_none() {
// no cwd to send; require at least one directory before opening a session
return Err(anyhow::anyhow!("provide a working directory"));
} Try / catch
On 'Working directory cannot be empty', prompt the user to open a folder (creating a worktree) or supply a directory, then retry the session open.
Prevention
- Never construct session requests without at least one work directory; the first entry is the cwd
- Guard agent-panel entry points on the project having at least one folder worktree
When it happens
Trigger: open_or_create_session or load_session invoked with an empty work_dirs PathList — e.g. the project has no worktrees open, or a programmatic caller built the request without any directories.
Common situations: The agent panel is used in a window where only a single file (no folder) is open; a caller constructs a session request with an empty path list.
Related errors
- session was closed before load completed
- message not found
- no thread found with ID: {id:?}
- Project state not found for session
- Session not found
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/224727a99b27fd18.
Report an issue: GitHub.