Skip to content

Commit 167627a

Browse files
artwalkerclaude
andcommitted
fix(cli): route logs to stderr when --json flag is active
Plugin loading emits console.log messages to stdout, which corrupts JSON output for commands like `openclaw agents list --json`. Call routeLogsToStderr() in the preAction hook before plugin loading when --json mode is detected, matching the existing pattern in completion-cli. Fixes #52032 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent f6c57ed commit 167627a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/cli/program/preaction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Command } from "commander";
22
import { setVerbose } from "../../globals.js";
33
import { isTruthyEnvValue } from "../../infra/env.js";
4+
import { routeLogsToStderr } from "../../logging/console.js";
45
import type { LogLevel } from "../../logging/levels.js";
56
import { defaultRuntime } from "../../runtime.js";
67
import {
@@ -144,6 +145,9 @@ export function registerPreActionHooks(program: Command, programVersion: string)
144145
return;
145146
}
146147
const suppressDoctorStdout = isJsonOutputMode(commandPath, argv);
148+
if (suppressDoctorStdout) {
149+
routeLogsToStderr();
150+
}
147151
const { ensureConfigReady } = await loadConfigGuardModule();
148152
await ensureConfigReady({
149153
runtime: defaultRuntime,

0 commit comments

Comments
 (0)