{"record":{"id":"9499dc7b97e35f9f","repo":"atuinsh/atuin","slug":"no-commands-found-in-history","errorCode":null,"errorMessage":"No commands found in history","messagePattern":"No commands found in history","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin/src/command/client/scripts.rs","lineNumber":248,"sourceCode":"            // Get the last N+1 commands, filtering by the default mode\n            let filters = [settings.default_filter_mode(context.git_root.is_some())];\n\n            let mut history =\n                history_db.list(filters, &context, Some(count), false, false, None).await?;\n\n            // Reverse to get chronological order\n            history.reverse();\n\n            // Skip the most recent command (which would be the atuin scripts new command itself)\n            if !history.is_empty() {\n                history.pop(); // Remove the most recent command\n            }\n\n            // Format the commands into a script\n            let commands: Vec<String> = history.iter().map(|h| h.command.clone()).collect();\n\n            if commands.is_empty() {\n                bail!(\"No commands found in history\");\n            }\n\n            let script_text = commands.join(\"\\n\");\n\n            // Only open editor if --no-edit is not specified\n            if new_script.no_edit {\n                Some(script_text)\n            } else {\n                // Open the editor with the commands pre-loaded\n                Some(Self::open_editor(Some(&script_text))?)\n            }\n        } else if let Some(script_path) = new_script.script {\n            let script_content = std::fs::read_to_string(script_path)?;\n            Some(script_content)\n        } else if !stdin.is_terminal() {\n            let mut buffer = String::new();\n            stdin.read_to_string(&mut buffer)?;\n            Some(buffer)","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin/src/command/client/scripts.rs#L230-L266","documentation":"`handle_new_script` builds a script from recently fetched history commands. If the collected history yields an empty command list, there is nothing to turn into a script, so it bails. This guards against creating empty scripts.","triggerScenarios":"Running `atuin scripts new` (history-derived flow) when the history query/selection returned no entries — e.g. no commands in the selected session or time range.","commonSituations":"Fresh install with empty history DB; history filtered out by session/directory; history not yet synced; running the command from a context with no recorded commands.","solutions":["Record some commands first (use the shell normally) and retry.","Run `atuin sync` if history lives on another machine.","Check the history query/filters (session, cwd) that select which commands feed the script; widen them."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# ensure there is history before deriving a script:\natuin history list --limit 1 >/dev/null 2>&1 \\\n  || { echo \"history is empty; use atuin normally or run 'atuin sync' first\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match new_script_from_history().await {\n    Err(e) if e.to_string().contains(\"No commands found in history\") => {\n        eprintln!(\"no history in scope: run commands or widen the session/time filter\");\n    }\n    other => other,\n}","preventionTips":["Run `atuin sync` before creating scripts on a new machine.","Check session/cwd filters that scope the history query.","Confirm the history DB is non-empty before script creation."],"tags":["scripts","empty-history","validation"],"backgroundTag":"empty-result-set","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}