Skip to content

Commit 9994f6c

Browse files
grichaclaude
andcommitted
Improve OpenCode streaming with line-buffered output
Use stdbuf -oL to set line-buffered stdout for OpenCode commands, ensuring JSON events are flushed immediately after each newline. This helps reduce output buffering and improves streaming responsiveness. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7c17f67 commit 9994f6c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/chat/host-opencode-handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ export class HostOpencodeSession {
186186
await this.loadHistory();
187187
}
188188

189-
const args = ['run', '--format', 'json'];
189+
const args = ['-oL', 'opencode', 'run', '--format', 'json'];
190190

191191
if (this.sessionId) {
192192
args.push('--session', this.sessionId);
193193
}
194194

195195
args.push(userMessage);
196196

197-
console.log('[host-opencode] Running: opencode', args.join(' '));
197+
console.log('[host-opencode] Running: stdbuf', args.join(' '));
198198

199199
this.onMessage({
200200
type: 'system',
@@ -203,7 +203,7 @@ export class HostOpencodeSession {
203203
});
204204

205205
try {
206-
const proc = Bun.spawn(['opencode', ...args], {
206+
const proc = Bun.spawn(['stdbuf', ...args], {
207207
cwd: this.workDir,
208208
stdin: 'ignore',
209209
stdout: 'pipe',

src/chat/opencode-handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ export class OpencodeSession {
118118

119119
const args = [
120120
'exec',
121+
'-i',
121122
'-u',
122123
'workspace',
123124
'-w',
124125
this.workDir,
125126
this.containerName,
127+
'stdbuf',
128+
'-oL',
126129
'opencode',
127130
'run',
128131
'--format',

0 commit comments

Comments
 (0)