{"record":{"id":"f3ab0d1751c5a8c2","repo":"gitbutlerapp/gitbutler","slug":"local-ai-configuration-requires-running-inside-a-git","errorCode":null,"errorMessage":"Local AI configuration requires running inside a git repository","messagePattern":"Local AI configuration requires running inside a git repository","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/config.rs","lineNumber":117,"sourceCode":"        Some(Subcommands::Feature { flag, status }) => feature_config(out, flag, status),\n        Some(Subcommands::Ai { local, global, cmd }) => {\n            ai_config_with_repo(ctx, out, cmd, local, global)\n        }\n        None => show_overview(ctx, out).await,\n    }\n}\n\n/// Handle AI config subcommand without repository context.\n///\n/// This supports global configuration from outside of a git repository.\npub(crate) fn ai_config(\n    out: &mut OutputChannel,\n    cmd: Option<AiSubcommand>,\n    local: bool,\n    global: bool,\n) -> Result<()> {\n    if local {\n        anyhow::bail!(\"Local AI configuration requires running inside a git repository\")\n    }\n    ai_config_inner(None, out, cmd, local, global)\n}\n\n/// Show overview of important settings\nasync fn show_overview(ctx: &mut Context, out: &mut OutputChannel) -> Result<()> {\n    let t = theme::get();\n    #[derive(Serialize)]\n    struct ConfigOverview {\n        name: Option<String>,\n        email: Option<String>,\n        editor: Option<String>,\n        target_branch: Option<String>,\n        forge_accounts: Vec<ForgeAccountInfo>,\n    }\n\n    #[derive(Serialize)]\n    struct ForgeAccountInfo {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/config.rs#L99-L135","documentation":"The `but config` command supports local (repo-scoped) and global AI configuration. When `ai_config` is invoked without a repository context (the caller passes None as the project/repository handle), local-scope configuration is impossible because there is no repo-local config file to write to, so the CLI aborts with this bail. Use global scope instead, or run from inside a git repository.","triggerScenarios":"Running `but config ai --local ...` (or an AiSubcommand with local=true) from outside any git work tree, so no project/repository can be resolved and ai_config is called with a None repo path.","commonSituations":"Developers running the CLI in a home directory, CI workspace, or temp folder that is not a git repo while trying to set a repo-local AI API key; scripts that cd away from the repo before invoking but config.","solutions":["Run the command from inside a git repository (cd into your project work tree) and retry with --local","Drop the --local flag so configuration is written globally instead","Initialize a git repository in the current directory (git init) if a repo-local setting is truly needed"],"exampleFix":"// before\nbut config ai --local --api-key sk-...\n// after\ncd /path/to/repo && but config ai --local --api-key sk-...\n# or, scope-independent:\nbut config ai --api-key sk-...","handlingStrategy":"validation","validationCode":"function isInsideGitRepo(dir) {\n  try {\n    require('node:child_process').execSync('git rev-parse --is-inside-work-tree', { cwd: dir, stdio: 'pipe' });\n    return true;\n  } catch { return false; }\n}\nif (!isInsideGitRepo(process.cwd()) && args.includes('--local')) throw new Error('Run from inside a git repo or drop --local');","typeGuard":"const isLocalScope = (opts) => opts.local === true;","tryCatchPattern":"try {\n  await exec('but config ai --local ...');\n} catch (e) {\n  if (e.message.includes('requires running inside a git repository')) {\n    // fallback to global config\n    await exec('but config ai ...');\n  } else throw e;\n}","preventionTips":["Always cd into the repository before repo-scoped CLI commands","Detect non-repo directories in scripts and skip/scope-down --local flags","Use git rev-parse in CI before invoking repo-scoped commands"],"tags":["cli","git","configuration"],"backgroundTag":"missing-required-config","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}