{"record":{"id":"f8ada781f5171c1c","repo":"ultraworkers/claw-code","slug":"agent-already-exists","errorCode":"agent_already_exists","errorMessage":"agent_already_exists: agent '{name}' already exists at {}","messagePattern":"agent_already_exists: agent '(.+?)' already exists at (.+?)","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust/crates/commands/src/lib.rs","lineNumber":3822,"sourceCode":"    }\n    names.sort();\n    Ok(names)\n}\n\nfn create_agent(name: &str, cwd: &Path) -> std::io::Result<CreatedAgent> {\n    let Some(name) = sanitize_skill_invocation_name(name) else {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidInput,\n            \"invalid_agent_name: agent name must contain at least one alphanumeric character\",\n        ));\n    };\n    let root = cwd.join(\".claw\").join(\"agents\");\n    let path = root.join(format!(\"{name}.toml\"));\n    if path.exists() {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::AlreadyExists,\n            format!(\n                \"agent_already_exists: agent '{name}' already exists at {}\",\n                path.display()\n            ),\n        ));\n    }\n\n    fs::create_dir_all(&root)?;\n    fs::write(\n        &path,\n        format!(\n            \"name = \\\"{name}\\\"\\ndescription = \\\"Describe when to use this agent.\\\"\\nmodel_reasoning_effort = \\\"medium\\\"\\n\"\n        ),\n    )?;\n\n    Ok(CreatedAgent { name, path })\n}\n\nfn default_skill_install_root() -> std::io::Result<PathBuf> {\n    if let Ok(claw_config_home) = env::var(\"CLAW_CONFIG_HOME\") {","sourceCodeStart":3804,"sourceCodeEnd":3840,"githubUrl":"https://github.com/ultraworkers/claw-code/blob/08106b0c3771ef5b4a5aa176acccd460e88b7325/rust/crates/commands/src/lib.rs#L3804-L3840","documentation":"Thrown by `create_agent` when the `/agents create <name>` slash command finds that `<cwd>/.claw/agents/<name>.toml` already exists (commands/src/lib.rs:3818). The collision check uses the SANITIZED name — lowercased, restricted to a-z, 0-9, '-', '_', '.' — so two differently-typed names that sanitize identically collide on the same file. Returned as `io::ErrorKind::AlreadyExists` from the command handler.","triggerScenarios":"Running `/agents create reviewer` twice in the same workspace; creating `Code Review` after `code-review` (both sanitize to `code-review`); a stale `.claw/agents/<name>.toml` left behind by a previous session or teammate.","commonSituations":"Re-running workspace bootstrap scripts that create agents; teammates committing `.claw/agents/` to the repo; case/punctuation variants of an existing agent name silently mapping to the same sanitized file.","solutions":["Pick a different agent name whose sanitized form differs (check `.claw/agents/` for the exact colliding file shown in the message).","If the existing agent is stale, delete or edit `.claw/agents/<name>.toml` directly and re-run the command.","List existing agents first (`/agents`) before creating to avoid the collision."],"exampleFix":"# before\n/agents create reviewer   # agent_already_exists: 'reviewer' already exists at .claw/agents/reviewer.toml\n\n# after (pick a name that does not collide after sanitization)\nls .claw/agents\n/agents create reviewer-2","handlingStrategy":"validation","validationCode":"fn agent_toml_path(name: &str, cwd: &Path) -> PathBuf {\n    cwd.join(\".claw\").join(\"agents\").join(format!(\"{name}.toml\"))\n}\n\n// before create_agent:\nif agent_toml_path(raw_name, cwd).exists() { /* pick another name or edit it */ }","typeGuard":null,"tryCatchPattern":"if let Err(e) = create_agent(name, cwd) {\n    if e.kind() == std::io::ErrorKind::AlreadyExists {\n        // name collision after sanitization: offer to edit existing .claw/agents/<name>.toml\n    } else { return Err(e); }\n}","preventionTips":["List `.claw/agents/` before creating","Remember names are sanitized (lowercase, [a-z0-9-_.]) so 'Code Review' and 'code-review' collide","Commit or deliberately gitignore `.claw/agents/` so team collisions are visible"],"tags":["agents","slash-commands","filesystem","already-exists"],"backgroundTag":"file-already-exists","analyzedSha":"08106b0c3771ef5b4a5aa176acccd460e88b7325","analyzedAt":"2026-08-18T00:29:38.590Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}