nikivdev/code · error
Session name '{}' already exists. Use a different name or re
Error message
Session name '{}' already exists. Use a different name or remove it first. What it means
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.
Source
Thrown at src/ai.rs:15069
session_provider,
codex_launch_target,
explicit_session_requested,
)
}
/// Save a session with a name.
fn save_session(name: &str, id: Option<String>) -> Result<()> {
let session_id = match id {
Some(id) => id,
None => get_most_recent_session_id()?
.ok_or_else(|| anyhow::anyhow!("No sessions found. Start an AI session first."))?,
};
let mut index = load_index()?;
// Check if name already exists
if index.sessions.contains_key(name) {
bail!(
"Session name '{}' already exists. Use a different name or remove it first.",
name
);
}
let session_provider = read_sessions_for_project(Provider::All)?
.into_iter()
.find(|session| session.session_id == session_id)
.map(|session| session.provider)
.unwrap_or(Provider::Claude);
let saved = SavedSession {
id: session_id.clone(),
provider: provider_name(session_provider).to_string(),
description: None,
saved_at: chrono::Utc::now().to_rfc3339(),
last_resumed: None,
};View on GitHub (pinned to a747e741ae)
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
Example fix
// before f ai sessions save --name work // error: name already exists // after f ai sessions remove work f ai sessions save --name work
Defensive patterns
Strategy: validation
Validate before calling
# shell: check the name is free before saving if f ai sessions list | grep -qxF "$NAME"; then echo "name '$NAME' taken; pick another"; exit 1 fi f ai sessions save --name "$NAME"
Try / catch
// treat 'already exists' as retry-with-new-name
match save_session(name, data) {
Err(e) if e.to_string().contains("already exists") => {
let unique = format!("{}-{}", name, timestamp());
save_session(&unique, data)?;
}
other => other?,
} Prevention
- 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
When it happens
Trigger: Calling the session-save command with `--name <name>` (or equivalent) where `<name>` already exists in the sessions index loaded via load_index().
Common situations: 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.
Related errors
- fzf not found on PATH – install it to use fuzzy selection.
- failed to resume codex session {}
- failed to resume {} session {}
- Session '{}' not found in saved sessions
- Session not found
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/f0782aedfe49e9a8.
Report an issue: GitHub.