@@ -296,7 +296,7 @@ public CodexCliResult execWithDisable(String prompt, String... features) {
296296 * @return the raw CLI invocation result; never {@code null}.
297297 */
298298 public CodexCliResult startSession () {
299- return cli .startInteractive ();
299+ return cli .startInteractive (defaultGlobalOptions (), null );
300300 }
301301
302302 /**
@@ -306,7 +306,7 @@ public CodexCliResult startSession() {
306306 * @return the raw CLI invocation result; never {@code null}.
307307 */
308308 public CodexCliResult startSession (String prompt ) {
309- return cli .startInteractive (prompt );
309+ return cli .startInteractive (defaultGlobalOptions (), prompt );
310310 }
311311
312312 /**
@@ -1122,7 +1122,7 @@ public CodexCliResult execute(String... args) {
11221122 * @return a fresh options instance; never {@code null}.
11231123 */
11241124 private CodexCli .ExecOptions defaultOptions (String prompt ) {
1125- CodexCli .ExecOptions opts = new CodexCli .ExecOptions (prompt ).json (true );
1125+ CodexCli .ExecOptions opts = new CodexCli .ExecOptions (prompt ).json (config . isJsonOutput () );
11261126 if (config .getDefaultModel () != null ) opts .model (config .getDefaultModel ());
11271127 if (config .getDefaultSandbox () != null ) opts .sandbox (config .getDefaultSandbox ());
11281128 if (config .getDefaultApprovalPolicy () != null ) opts .approvalPolicy (config .getDefaultApprovalPolicy ());
@@ -1146,6 +1146,33 @@ private CodexCli.ExecOptions defaultOptions(String prompt) {
11461146 return opts ;
11471147 }
11481148
1149+ /**
1150+ * Builds global CLI options for interactive sessions from client defaults.
1151+ *
1152+ * @return a fresh options instance; never {@code null}.
1153+ */
1154+ private CodexCli .GlobalOptions defaultGlobalOptions () {
1155+ CodexCli .GlobalOptions opts = new CodexCli .GlobalOptions ();
1156+ if (config .getDefaultModel () != null ) opts .model (config .getDefaultModel ());
1157+ if (config .getDefaultSandbox () != null ) opts .sandbox (config .getDefaultSandbox ());
1158+ if (config .getDefaultApprovalPolicy () != null ) opts .approvalPolicy (config .getDefaultApprovalPolicy ());
1159+ if (config .getDefaultProfile () != null ) opts .profile (config .getDefaultProfile ());
1160+ if (config .getWorkingDir () != null ) opts .workingDir (config .getWorkingDir ());
1161+ if (config .getAddDir () != null ) opts .addDir (config .getAddDir ());
1162+ if (config .isOssProvider ()) opts .oss (true );
1163+ if (config .getLocalProvider () != null ) opts .localProvider (config .getLocalProvider ());
1164+ if (config .isSearch ()) opts .search (true );
1165+ if (config .getImage () != null ) opts .image (config .getImage ());
1166+ if (config .getConfigOverrides () != null ) opts .configOverrides (config .getConfigOverrides ());
1167+ if (config .isDangerouslyBypassApprovalsAndSandbox ()) opts .dangerouslyBypassApprovalsAndSandbox (true );
1168+ if (config .isDangerouslyBypassHookTrust ()) opts .dangerouslyBypassHookTrust (true );
1169+ if (config .isStrictConfig ()) opts .strictConfig (true );
1170+ if (config .getEnable () != null ) opts .enable (config .getEnable ());
1171+ if (config .getDisable () != null ) opts .disable (config .getDisable ());
1172+ if (config .isNoAltScreen ()) opts .noAltScreen (true );
1173+ return opts ;
1174+ }
1175+
11491176 /**
11501177 * Decodes a JSON-Lines blob into a list of {@link CodexEvent}s.
11511178 *
0 commit comments