Unlike {@link ClaudeProfile#createDefault()}, this method goes through
+ * {@link #getProfiles()}, which loads stored settings (API key, proxy,
+ * extraCliArgs, etc.) from {@code NbPreferences}. Callers that need the
+ * Default profile should use this method so the user's configuration is
+ * honoured rather than silently discarded.
+ *
+ * @return the Default profile with settings loaded from preferences
+ */
+ public static ClaudeProfile getDefaultProfile() {
+ return getProfiles().stream().filter(ClaudeProfile::isDefault).findFirst()
+ .orElseGet(ClaudeProfile::createDefault);
+ }
+
/**
* Looks up a profile by name.
*
@@ -108,14 +124,10 @@ public static List If no profile name is stored, or the stored name is blank, the
- * Default profile is returned. If the stored name cannot be found in
- * {@link ClaudeProfileStore}, the Default profile is returned and a
- * warning is logged.
- *
- * @param projectDir the project root directory; may be {@code null}
- * @return the assigned profile, or the Default profile if not set / not found
- */
- public static ClaudeProfile resolveProfile(File projectDir) {
- String name = getProfileName(projectDir);
- if (name.isBlank()) {
- return ClaudeProfile.createDefault();
- }
- ClaudeProfile found = ClaudeProfileStore.findByName(name);
- if (found.isDefault() && !name.isBlank()) {
- LOG.warning("Profile '" + name + "' assigned to project "
- + (projectDir != null ? projectDir.getAbsolutePath() : "null")
- + " not found — using Default.");
- }
- return found;
- }
-
// -------------------------------------------------------------------------
// Write
// -------------------------------------------------------------------------
diff --git a/src/main/java/io/github/nbclaudecodegui/ui/ClaudeSessionTab.java b/src/main/java/io/github/nbclaudecodegui/ui/ClaudeSessionTab.java
index 93886df9..74104536 100644
--- a/src/main/java/io/github/nbclaudecodegui/ui/ClaudeSessionTab.java
+++ b/src/main/java/io/github/nbclaudecodegui/ui/ClaudeSessionTab.java
@@ -576,11 +576,17 @@ public boolean isSessionActive() {
/**
* Starts a session for {@code dir} with {@code profileName} without showing any dialogs.
*
+ * The profile's {@code extraCliArgs} are resolved here so that the global
+ * "Extra CLI args" setting in Tools → Options is honoured when a session is
+ * launched from the project context menu ("Open with Claude Code").
+ * Previously passing {@code null} meant the setting was silently ignored.
+ *
* @param dir working directory
* @param profileName profile name, or {@code null} for Default
*/
public void autoStart(File dir, String profileName) {
- autoStart(dir, profileName, null);
+ ClaudeProfile profile = ClaudeProfileStore.findByName(profileName);
+ autoStart(dir, profileName, profile.getExtraCliArgs());
}
public void autoStart(File dir, String profileName, String extraCliArgs) {
diff --git a/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProfileStoreTest.java b/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProfileStoreTest.java
index 063060b5..ed834daf 100644
--- a/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProfileStoreTest.java
+++ b/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProfileStoreTest.java
@@ -83,6 +83,49 @@ void findByName_nullName_returnsDefault() {
assertTrue(found.isDefault());
}
+ @Test
+ void findByName_unknownName_returnsDefault() {
+ ClaudeProfile found = ClaudeProfileStore.findByName("nonexistent-profile-xyz");
+ assertTrue(found.isDefault(),
+ "findByName with unknown name must fall back to the Default profile");
+ }
+
+ // -------------------------------------------------------------------------
+ // getDefaultProfile (issue #23)
+ // -------------------------------------------------------------------------
+
+ /**
+ * Regression test for issue #23: {@code getDefaultProfile()} must return
+ * the preference-backed Default profile, matching what {@code getProfiles()}
+ * returns — not a bare {@code createDefault()} with empty fields.
+ *
+ * {@code createDefault()} sets {@code extraCliArgs = ""} unconditionally,
+ * so using it in {@code findByName(null)} would silently discard any Extra
+ * CLI args the user configured in Tools → Options.
+ */
+ @Test
+ void getDefaultProfile_isDefault() {
+ ClaudeProfile p = ClaudeProfileStore.getDefaultProfile();
+ assertTrue(p.isDefault(), "getDefaultProfile() must return the Default profile");
+ assertEquals("Default", p.getName());
+ }
+
+ @Test
+ void getDefaultProfile_matchesGetProfiles() {
+ ClaudeProfile fromList = ClaudeProfileStore.getProfiles().get(0);
+ ClaudeProfile fromMethod = ClaudeProfileStore.getDefaultProfile();
+ assertEquals(fromList.getExtraCliArgs(), fromMethod.getExtraCliArgs(),
+ "getDefaultProfile() must return the same extraCliArgs as getProfiles().get(0)");
+ }
+
+ @Test
+ void findByName_null_delegatesToGetDefaultProfile() {
+ ClaudeProfile fromFind = ClaudeProfileStore.findByName(null);
+ ClaudeProfile fromMethod = ClaudeProfileStore.getDefaultProfile();
+ assertEquals(fromMethod.getExtraCliArgs(), fromFind.getExtraCliArgs(),
+ "findByName(null) must delegate to getDefaultProfile()");
+ }
+
// -------------------------------------------------------------------------
// saveProfile / Default cannot be saved
// -------------------------------------------------------------------------
diff --git a/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProjectPropertiesTest.java b/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProjectPropertiesTest.java
index fe0debaf..75ee9897 100644
--- a/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProjectPropertiesTest.java
+++ b/src/test/java/io/github/nbclaudecodegui/settings/ClaudeProjectPropertiesTest.java
@@ -72,16 +72,6 @@ void setProfileName_nullName_clearsEntry() {
} catch (Exception ignored) {}
}
- // -------------------------------------------------------------------------
- // resolveProfile — null dir falls back to Default
- // -------------------------------------------------------------------------
-
- @Test
- void resolveProfile_nullDir_returnsDefault() {
- ClaudeProfile profile = ClaudeProjectProperties.resolveProfile(null);
- assertTrue(profile.isDefault());
- }
-
// -------------------------------------------------------------------------
// renameAssignments
// -------------------------------------------------------------------------
diff --git a/src/test/java/io/github/nbclaudecodegui/ui/ClaudeSessionTabAutoStartTest.java b/src/test/java/io/github/nbclaudecodegui/ui/ClaudeSessionTabAutoStartTest.java
new file mode 100644
index 00000000..7d2dee0b
--- /dev/null
+++ b/src/test/java/io/github/nbclaudecodegui/ui/ClaudeSessionTabAutoStartTest.java
@@ -0,0 +1,49 @@
+package io.github.nbclaudecodegui.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.concurrent.atomic.AtomicReference;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Regression tests for issue #23: {@link ClaudeSessionTab#autoStart(File, String)}
+ * must forward the profile's {@code extraCliArgs} to the underlying session start,
+ * not pass {@code null}.
+ *
+ * Before the fix, {@code autoStart(File, String)} called
+ * {@code autoStart(dir, profileName, null)}, silently discarding any Extra CLI
+ * args configured for the profile in Tools → Options → Profiles.
+ */
+class ClaudeSessionTabAutoStartTest {
+
+ /**
+ * Verifies that {@code autoStart(File, String)} passes a non-null
+ * {@code extraCliArgs} string to the three-argument overload.
+ *
+ * A non-null value guarantees that the profile's CLI args setting
+ * (even if empty) is forwarded rather than dropped.
+ */
+ @Test
+ void autoStart_twoArg_passesNonNullExtraCliArgs() throws IOException {
+ AtomicReference