{"record":{"id":"7364df354ae952b8","repo":"sinelaw/fresh","slug":"not-inside-a-fresh-session-set-session-id-or-run-inside-a","errorCode":null,"errorMessage":"not inside a Fresh session; set --session <id> (or run inside a Fresh workspace so $FRESH_SESSION is set)","messagePattern":"not inside a Fresh session; set --session <id> \\(or run inside a Fresh workspace so \\$FRESH_SESSION is set\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/main.rs","lineNumber":3547,"sourceCode":"/// needs to be told that is the fix, and told it in terms it can match on. The\n/// injected \"Teach Fresh CLI\" contract points at this phrasing.\nfn socket_denied_error(session: &str, socket_paths: &SocketPaths) -> anyhow::Error {\n    anyhow::anyhow!(\n        \"cannot reach the Fresh editor for session '{}': its control socket ({}) \\\n         could not be reached because connecting to it was denied. The editor is \\\n         most likely running — the socket simply lives outside this process's \\\n         sandbox. Re-run this command outside the sandbox.\",\n        session,\n        socket_paths.control.display(),\n    )\n}\n\nfn resolve_cmd_socket(session_override: Option<&str>) -> AnyhowResult<SocketPaths> {\n    let session = match session_override {\n        Some(s) if !s.trim().is_empty() => s.to_string(),\n        _ => match std::env::var(\"FRESH_SESSION\") {\n            Ok(s) if !s.trim().is_empty() => s,\n            _ => anyhow::bail!(\n                \"not inside a Fresh session; set --session <id> (or run inside a \\\n                 Fresh workspace so $FRESH_SESSION is set)\"\n            ),\n        },\n    };\n\n    let socket_paths = resolve_session(Some(&session))?;\n    socket_paths.cleanup_if_stale();\n    match socket_paths.probe_server() {\n        ServerLiveness::Alive => Ok(socket_paths),\n        // Denied rather than absent. Say so, and say what to do: a caller that\n        // can re-run outside its sandbox (an agent with an escalation path)\n        // can act on this, whereas \"no running editor\" sends it hunting for a\n        // stale session that is in fact alive and well.\n        ServerLiveness::Unreachable => Err(socket_denied_error(&session, &socket_paths)),\n        ServerLiveness::Dead => {\n            anyhow::bail!(\"no running Fresh editor for session '{}'\", session)\n        }","sourceCodeStart":3529,"sourceCodeEnd":3565,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/main.rs#L3529-L3565","documentation":"Thrown by resolve_cmd_socket when no session id is available: neither --session was given nor $FRESH_SESSION is set to a non-empty value. Command-channel subcommands (cmd/script) need a session to locate the editor's control socket.","triggerScenarios":"Running `fresh --cmd ...` or `fresh --script-file ...` in a plain shell where FRESH_SESSION is unset, or with `--session \"\"` / whitespace, without launching from inside a Fresh-spawned workspace shell.","commonSituations":"Calling fresh CLI helpers from cron/systemd/CI where the environment is stripped; opening a new terminal instead of the workspace shell; forgetting --session after copying a command out of docs.","solutions":["Pass the id explicitly: `fresh --session <id> --cmd ...`.","Run the command from a shell launched inside a Fresh workspace so $FRESH_SESSION is set.","Check `echo $FRESH_SESSION`; if empty, export it with the running editor's session id."],"exampleFix":"// before\nfresh --cmd split right\n// after\nfresh --session my-session --cmd split right","handlingStrategy":"validation","validationCode":"const session = process.env.FRESH_SESSION;\nif (!session || !session.trim()) {\n  console.error('FRESH_SESSION unset: pass --session <id> or run inside a Fresh workspace');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run fresh CLI helpers from shells spawned inside a Fresh workspace.","Pass --session explicitly in scripts/cron/CI where the env is stripped.","Sanity-check with `echo $FRESH_SESSION` before chaining commands.","Avoid `env -i` / sanitized wrappers that drop FRESH_SESSION."],"tags":["cli","session","environment-variable"],"backgroundTag":"missing-env-var","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}