Skip to content

feat: Add --json flag for LLM-friendly CLI help output#335

Open
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/gentle-lion
Open

feat: Add --json flag for LLM-friendly CLI help output#335
aronchick wants to merge 1 commit intodlorenc:mainfrom
aronchick:work/gentle-lion

Conversation

@aronchick
Copy link
Copy Markdown
Contributor

Summary

  • Adds --json flag to CLI help for machine-readable output
  • multiclaude --json outputs full command tree as JSON
  • multiclaude --help --json same as above
  • multiclaude <cmd> --json outputs that command's schema

This enables LLMs and automation tools to programmatically discover available commands, their descriptions, usage patterns, and subcommands.

Implementation

  • Added CommandSchema struct for clean JSON serialization
  • Added toSchema() method on Command that recursively converts the command tree
  • Internal commands (prefixed with _) are filtered from output
  • Updated help text to mention the new --json flag

Example Output

$ multiclaude agent --json
{
  "name": "agent",
  "description": "Agent communication commands",
  "subcommands": {
    "attach": {
      "name": "attach",
      "description": "Attach to an agent's tmux window",
      "usage": "multiclaude agent attach <agent-name> [--read-only]"
    },
    ...
  }
}

Test plan

  • Build succeeds: go build ./cmd/multiclaude
  • All tests pass: go test ./...
  • New tests added for JSON output functionality
  • Manual verification of --json flag at root and subcommand levels
  • Regular help output still works as expected

🤖 Generated with Claude Code

Add support for machine-readable JSON output of the command tree:
- `multiclaude --json` outputs full command tree as JSON
- `multiclaude --help --json` same as above
- `multiclaude <cmd> --json` outputs that command's schema

This enables LLMs and automation tools to programmatically discover
available commands, their descriptions, usage patterns, and subcommands.

Includes CommandSchema struct for clean JSON serialization that filters
internal commands (prefixed with _) from output.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aronchick
Copy link
Copy Markdown
Contributor Author

Merge Queue: READY TO MERGE

  • CI: All 6 checks passing
  • Merge status: MERGEABLE/CLEAN
  • Reviews: None blocking

This PR is ready for maintainer merge.

@aronchick aronchick marked this pull request as ready for review January 31, 2026 21:27
whitmo added a commit to whitmo/multiclaude that referenced this pull request Feb 28, 2026
whitmo added a commit to whitmo/multiclaude that referenced this pull request Feb 28, 2026
…nc#336, dlorenc#340, dlorenc#342

Add 659 lines of tests covering:
- All 18 structured error constructors from PR dlorenc#340 (individual + bulk format test)
- JSON CLI output edge cases from PR dlorenc#335 (empty/nested/all-internal subcommands)
- Structured CLIError validation for workspace names from PR dlorenc#340 integration
- Message routing edge cases from PR dlorenc#342 (no acked, mixed ack status)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
whitmo added a commit to whitmo/multiclaude that referenced this pull request Mar 1, 2026
Gemini-assisted review of dlorenc#335 which adds --json
flag for machine-readable CLI output. Found clean implementation with
one suggestion to improve test assertions on JSON content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
whitmo added a commit to whitmo/multiclaude that referenced this pull request Mar 1, 2026
Resolved conflicts with dlorenc#337 categorized help: kept categorized output
and added JSON hint line. showCommandHelp now supports both outputJSON
parameter and root command redirect to categorized help.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
whitmo added a commit to whitmo/multiclaude that referenced this pull request Mar 1, 2026
…nc#336, dlorenc#340, dlorenc#342

Add 659 lines of tests covering:
- All 18 structured error constructors from PR dlorenc#340 (individual + bulk format test)
- JSON CLI output edge cases from PR dlorenc#335 (empty/nested/all-internal subcommands)
- Structured CLIError validation for workspace names from PR dlorenc#340 integration
- Message routing edge cases from PR dlorenc#342 (no acked, mixed ack status)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant