{"record":{"id":"f0782aedfe49e9a8","repo":"nikivdev/code","slug":"session-name-already-exists-use-a-different","errorCode":null,"errorMessage":"Session name '{}' already exists. Use a different name or remove it first.","messagePattern":"Session name '(.+?)' already exists\\. Use a different name or remove it first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ai.rs","lineNumber":15069,"sourceCode":"        session_provider,\n        codex_launch_target,\n        explicit_session_requested,\n    )\n}\n\n/// Save a session with a name.\nfn save_session(name: &str, id: Option<String>) -> Result<()> {\n    let session_id = match id {\n        Some(id) => id,\n        None => get_most_recent_session_id()?\n            .ok_or_else(|| anyhow::anyhow!(\"No sessions found. Start an AI session first.\"))?,\n    };\n\n    let mut index = load_index()?;\n\n    // Check if name already exists\n    if index.sessions.contains_key(name) {\n        bail!(\n            \"Session name '{}' already exists. Use a different name or remove it first.\",\n            name\n        );\n    }\n\n    let session_provider = read_sessions_for_project(Provider::All)?\n        .into_iter()\n        .find(|session| session.session_id == session_id)\n        .map(|session| session.provider)\n        .unwrap_or(Provider::Claude);\n\n    let saved = SavedSession {\n        id: session_id.clone(),\n        provider: provider_name(session_provider).to_string(),\n        description: None,\n        saved_at: chrono::Utc::now().to_rfc3339(),\n        last_resumed: None,\n    };","sourceCodeStart":15051,"sourceCodeEnd":15087,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ai.rs#L15051-L15087","documentation":"Thrown when saving a named session to the session index: the index file maps session names to session data, and names must be unique. Before inserting, the code checks `index.sessions.contains_key(name)` and bails if the name is already taken. It is a user-facing guard against silently overwriting an existing saved session.","triggerScenarios":"Calling the session-save command with `--name <name>` (or equivalent) where `<name>` already exists in the sessions index loaded via load_index().","commonSituations":"Re-running a save command with the same mnemonic name; scripting saves that reuse a fixed name; restoring an index from backup that already contains the name; forgetting a previous save under the same alias.","solutions":["Choose a different, unique name for the new session","Run the session remove/delete command for the existing name first, then save again","List saved sessions (`f ai sessions list`) to see which entry occupies the name","If the old entry is stale, delete the sessions index entry manually in .ai/ and retry"],"exampleFix":"// before\nf ai sessions save --name work\n// error: name already exists\n// after\nf ai sessions remove work\nf ai sessions save --name work","handlingStrategy":"validation","validationCode":"# shell: check the name is free before saving\nif f ai sessions list | grep -qxF \"$NAME\"; then\n  echo \"name '$NAME' taken; pick another\"; exit 1\nfi\nf ai sessions save --name \"$NAME\"","typeGuard":null,"tryCatchPattern":"// treat 'already exists' as retry-with-new-name\nmatch save_session(name, data) {\n    Err(e) if e.to_string().contains(\"already exists\") => {\n        let unique = format!(\"{}-{}\", name, timestamp());\n        save_session(&unique, data)?;\n    }\n    other => other?,\n}","preventionTips":["Adopt a naming scheme with timestamps or branch names","List sessions before saving to spot existing names","Remove old sessions instead of reusing their names","Keep one canonical .ai index per project, not per machine copy"],"tags":["session","naming-conflict","duplicate"],"backgroundTag":"name-already-exists","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}