Skip to content

Commit 7caf123

Browse files
committed
fix(cli): route logs to stderr in 'openclaw agent --json' to prevent plugin loading pollution
1 parent dc86b6d commit 7caf123

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/commands/agent-via-gateway.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
2+
import { routeLogsToStderr } from "../logging.js";
23
import { listAgentIds } from "../agents/agent-scope.js";
34
import { formatCliCommand } from "../cli/command-format.js";
45
import type { CliDeps } from "../cli/deps.js";
@@ -179,6 +180,11 @@ export async function agentViaGatewayCommand(opts: AgentCliOpts, runtime: Runtim
179180
}
180181

181182
export async function agentCliCommand(opts: AgentCliOpts, runtime: RuntimeEnv, deps?: CliDeps) {
183+
// When --json is set, route all logs to stderr so only the JSON result appears on stdout.
184+
if (opts.json) {
185+
routeLogsToStderr();
186+
}
187+
182188
const localOpts = {
183189
...opts,
184190
agentId: opts.agent,

0 commit comments

Comments
 (0)