Skip to content

Commit 4fdd421

Browse files
committed
fix: improve Windows compatibility for OpenCode backend
- Fix PATH detection for opencode.exe on Windows - Hide console window when spawning OpenCode process on Windows - Hide show1MModel setting when using OpenCode backend (Claude Code only)
1 parent a3c043c commit 4fdd421

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/core/opencode/OpencodeServerManager.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import { Notice, Platform } from 'obsidian';
12+
import type { ChildProcess } from 'child_process';
1213
import * as path from 'path';
1314

1415
export interface OpencodeServerConfig {
@@ -61,8 +62,10 @@ export class OpencodeServerManager {
6162
*/
6263
private getOpencodeCliPath(): string {
6364
// First check if 'opencode' is in PATH
65+
// Use Platform.isWin to check for Windows - opencode.exe needs extension on Windows
66+
const exeName = Platform.isWin ? 'opencode.exe' : 'opencode';
6467
const pathInEnv = process.env.PATH?.split(path.delimiter)
65-
.map(dir => path.join(dir, 'opencode'))
68+
.map(dir => path.join(dir, exeName))
6669
.find(cliPath => {
6770
try {
6871
const fs = require('fs');
@@ -97,7 +100,7 @@ export class OpencodeServerManager {
97100
if (fs.existsSync(p)) return p;
98101
} catch {}
99102
}
100-
} else if (Platform.isWin32) {
103+
} else if (Platform.isWin) {
101104
return 'opencode.exe';
102105
}
103106

@@ -268,11 +271,12 @@ export class OpencodeServerManager {
268271
// eslint-disable-next-line @typescript-eslint/no-var-requires
269272
const { spawn } = require('child_process');
270273

271-
this.process = spawn(cliPath, args, {
274+
this.process = spawn(cliPath, args, {
272275
cwd: this.vaultPath,
273276
env,
274277
stdio: ['ignore', 'pipe', 'pipe'],
275278
detached: true,
279+
windowsHide: true, // Hide console window on Windows
276280
});
277281

278282
// Handle process events

src/features/settings/OpencodeSettings.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,21 @@ export class OpencodeSettingTab extends PluginSettingTab {
616616
// Show/hide OpenCode config based on backend selection
617617
const updateOpencodeConfigVisibility = (): void => {
618618
opencodeConfigContainer.style.display = this.plugin.settings.agentBackend === 'opencode' ? 'block' : 'none';
619+
// Also update 1M model visibility for Claude Code backend
620+
if (show1MModelContainer) {
621+
show1MModelContainer.style.display = this.plugin.settings.agentBackend === 'claude-code' ? 'block' : 'none';
622+
}
619623
};
620624

621625
// Store references for visibility updates
622626
const autoStartSetting = new Setting(opencodeConfigContainer);
623627
const enableMdnsSetting = new Setting(opencodeConfigContainer);
624628

625-
// 1M context model toggle
626-
new Setting(containerEl)
629+
// Claude Code specific: 1M context model toggle
630+
const show1MModelContainer = containerEl.createDiv({ cls: 'opencode-show-1m-model-container' });
631+
show1MModelContainer.style.display = this.plugin.settings.agentBackend === 'claude-code' ? 'block' : 'none';
632+
633+
new Setting(show1MModelContainer)
627634
.setName(t('settings.show1MModel.name'))
628635
.setDesc(t('settings.show1MModel.desc'))
629636
.addToggle((toggle) =>

0 commit comments

Comments
 (0)