Skip to content

Streaming output in --verbose --print #733

@filipesilva

Description

@filipesilva

Followup from #365 (comment)

When using --verbose with --print, output is only available as json:

Error: When using --print, --verbose must be used together with --json
    at sg1.<anonymous> (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1616:246)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async sg1.parseAsync (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:424:4184)
    at async Or5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1619:4348)
    at async dr5 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1615:41755)
filipesilva@m4 ~/r/sandbox [1]> claude --verbose --json --print "say hello!"
[
  {
    "role": "user",
    "content": "say hello!"
  },
  {
    "id": "msg_01Xx3rAZ93AyDpMALs8nCJ9n",
    "type": "message",
    "role": "assistant",
    "model": "claude-3-7-sonnet-20250219",
    "content": [
      {
        "type": "text",
        "text": "Hello!"
      }
    ],
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "usage": {
      "input_tokens": 4,
      "cache_creation_input_tokens": 26313,
      "cache_read_input_tokens": 0,
      "output_tokens": 5
    }
  },
  {
    "role": "system",
    "cost_usd": 0.09876075000000001,
    "duration_ms": 3365,
    "duration_api_ms": 3366,
    "result": "Hello!"
  }
]

It would be much nicer for CI and debugging scenarios if it would stream the output like in the non-print call then exited:

filipesilva@m4 ~/r/sandbox> claude "say hello!"
╭────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview! │
│                                            │
│   /help for help                           │
│                                            │
│   cwd: /Users/filipesilva/repos/sandbox    │
╰────────────────────────────────────────────╯

 Tips for getting started:

 1. Run /init to create a CLAUDE.md file with instructions for Claude
 2. Run /terminal-setup to set up terminal integration
 3. Use Claude to help with file analysis, editing, bash commands and git
 4. Be as specific as you would with another engineer for the best results

> say hello!

⏺ Hello!

╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ > Try "how does <filepath> work?"                                                                                                                                                                                                                                                                                                                                                                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  Press Ctrl-C again to exit



Total cost:            $0.0080
Total duration (API):  1.7s
Total duration (wall): 11.2s
Total code changes:    0 lines added, 0 lines removed

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions