nikivdev/code · error
Session file not found for Codex session {}
Error message
Session file not found for Codex session {} What it means
Thrown while building cross-project context for a Codex-provider session: neither the session record's stored session_path nor a filesystem lookup via find_codex_session_file() could locate the underlying Codex session file. Reading a Codex session's context requires that file, so the code bails naming the session id.
Source
Thrown at src/ai.rs:15900
// Read context since checkpoint (or full if since_ts is None)
let (context, _last_ts) = read_cross_project_context(session, since_ts.as_deref(), count)?;
Ok(context)
}
/// Read context from a cross-project session.
fn read_cross_project_context(
session: &CrossProjectSession,
since_ts: Option<&str>,
max_count: Option<usize>,
) -> Result<(String, Option<String>)> {
if session.provider == Provider::Codex {
let session_file = session
.session_path
.clone()
.or_else(|| find_codex_session_file(&session.session_id));
let Some(session_file) = session_file else {
bail!(
"Session file not found for Codex session {}",
session.session_id
);
};
return read_codex_cross_project_context(session, &session_file, since_ts, max_count);
}
if session.provider == Provider::Cursor {
let session_file = session
.session_path
.clone()
.or_else(|| find_cursor_session_file(&session.session_id));
let Some(session_file) = session_file else {
bail!(
"Session file not found for Cursor session {}",
session.session_id
);
};
return read_cursor_cross_project_context(session, &session_file, since_ts, max_count);View on GitHub (pinned to a747e741ae)
Solutions
- Confirm the Codex session file exists under ~/.codex (sessions dir) for that session id
- Re-save or re-link the session with the correct session_path pointing at the file
- Set/verify the Codex home env var so find_codex_session_file searches the right root
- Remove the stale session entry and recreate it from a fresh Codex run
Example fix
// before f ai context --session abc123 # file cleaned from ~/.codex/sessions // after ls ~/.codex/sessions | grep abc123 # confirm, or re-run codex and re-save the session f ai sessions remove abc123 && f ai sessions save --name abc123
Defensive patterns
Strategy: validation
Validate before calling
# shell: locate the Codex session file before requesting context
FILE=$(find ~/.codex -name "*${SESSION_ID}*" -print -quit)
[ -n "$FILE" ] || { echo "no Codex file for $SESSION_ID"; exit 1; }
f ai context --session "$SESSION_ID" Try / catch
// fall back to full-session recreate when the file is gone
match cross_context(session) {
Err(e) if e.to_string().contains("Session file not found for Codex") => {
eprintln!("codex transcript missing; recreating session");
recreate_codex_session(&session.session_id)
}
other => other,
} Prevention
- Store session_path explicitly when saving Codex sessions
- Exclude ~/.codex from cleanup/backup-prune tooling
- Re-save sessions after moving CODEX_HOME or changing machines
- Verify session files exist after Codex upgrades
When it happens
Trigger: get/read cross-project context is called for a session with provider == Codex where session.session_path is None and find_codex_session_file(session_id) returns None (file moved/deleted, different CODEX_HOME, session id not matching any file in ~/.codex/sessions).
Common situations: Codex sessions cleaned up by disk hygiene tools; Codex home relocated via env var so the default lookup path misses; session saved on another machine; Codex upgraded and changed its session file naming/rollout subfolders.
Related errors
- fzf not found on PATH – install it to use fuzzy selection.
- failed to resume codex session {}
- Session file not found for Cursor session {}
- Could not find agent file for '{}'
- connect is only supported for Codex sessions; use `f codex c
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/fb8ccbdbf04b3caa.
Report an issue: GitHub.