Skip to content

[Bug]: --json CLI flags output plugin logs to stdout, breaking JSON parsing #52032

@xl0shk

Description

@xl0shk

Bug type

Behavior bug (incorrect output/state without crash)

Summary

CLI commands with --json flag (e.g. openclaw agents list --json) mix plugin loading logs into stdout alongside the JSON output, making it impossible to pipe the result to jq or parse programmatically.

Steps to reproduce

$ openclaw agents list --json
[plugins] feishu_doc: Registered feishu_doc, feishu_app_scopes                                                                                                      
[plugins] feishu_chat: Registered feishu_chat tool                                                                                                                  
[plugins] feishu_wiki: Registered feishu_wiki tool                                                                                                                  
[plugins] feishu_drive: Registered feishu_drive tool                                                                                                                
[plugins] feishu_bitable: Registered bitable tools                                                                                                                  
[                                                                                                                                                                   
  {                                                                                                                                                                 
    "id": "work",                                                                                                                                                   
    ...                                                                                                                                                             
  }                                                                                                                                                                 
]                                                                                                                                                                   

Piping to jq fails:

$ openclaw agents list --json | jq '.[0].id'
parse error (Invalid numeric literal at line 1, column 2)                                                                                                           

2>/dev/null does not help because the [plugins] lines go to stdout, not stderr.

Expected behavior

--json output should be valid JSON on stdout. All log/diagnostic messages should go to stderr.

Actual behavior

Plugin subsystem info-level logs ([plugins] Registered ...) are written to stdout via console.log(), appearing before the JSON array and corrupting the output.

OpenClaw version

2026.3.13 (61d171a)

Operating system

macOS 14.5 (Darwin 23.5.0)

Install method

npm global

Model

openai/claude-opus-4.5

Provider / routing chain

N/A — this bug is in CLI output, not model routing

Additional provider/model setup details

Feishu plugin is loaded from /opt/homebrew/lib/node_modules/openclaw/extensions/feishu.
The plugin loading logs are emitted via createSubsystemLogger("plugins").info(), which routes to console.log() (stdout).

The codebase already has routeLogsToStderr() (sets loggingState.forceConsoleToStderr = true) but it is not called in --json code paths.

Suggested fix: in the CLI preAction hook, if any parsed option is --json, call routeLogsToStderr() so stdout stays clean for JSON output.

Logs, screenshots, and evidence

Impact and severity

Affected: all users piping --json output programmatically
Severity: medium (functional breakage of --json flag purpose)
Frequency: 100% reproducible when plugins are loaded
Workaround: openclaw agents list --json | grep -v '^\[plugins\]'

Additional information

Affected commands include at minimum agents list --json and agents bindings --json, likely all commands offering --json. The fix should be applied globally in the preAction hook rather than per-command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug:behaviorIncorrect behavior without a crash

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions