allocate_agent_workdir

Function allocate_agent_workdir 

Source
pub fn allocate_agent_workdir(desired: &str) -> Result<String, String>
Expand description

Atomically allocate an agent working directory.

Tries to atomically create desired via std::fs::create_dir. If that fails because the directory already exists, tries <desired>-1, <desired>-2, …, up to -99. The atomic create_dir (NOT create_dir_all for the leaf) is the reservation mechanism: two concurrent callers competing for the same path race on the OS mkdir syscall and one wins; the loser sees AlreadyExists and moves on.

Caller is responsible for distinguishing auto-generated paths from user-specified ones — this function rewrites the path on collision, which would clobber a user’s intent if they pointed an agent at ~/projects/myrepo and that already had a CLAUDE.md.