Skip to content

feat(cli): add models command for listing available models#4997

Merged
marius-kilocode merged 3 commits intomainfrom
cli-models-json-support
Jan 13, 2026
Merged

feat(cli): add models command for listing available models#4997
marius-kilocode merged 3 commits intomainfrom
cli-models-json-support

Conversation

@marius-kilocode
Copy link
Collaborator

@marius-kilocode marius-kilocode commented Jan 13, 2026

Summary

Add a CLI command kilocode models --json that exposes available models as JSON, enabling agent manager to offer per-session model selection without hardcoding model lists.

Changes

New Files

  • cli/src/commands/models-api.ts - Models listing logic with:

    • ModelsApiOutput interface for JSON output structure
    • fetchRouterModels() function for lightweight extension initialization
    • modelsApiCommand() main command handler
    • Support for both router-based providers (kilocode, openrouter, etc.) and static providers (anthropic, gemini, etc.)
    • 30-second timeout for router models request
  • cli/src/commands/__tests__/models-api.test.ts - Comprehensive test suite

Modified Files

  • cli/src/index.ts - Register models subcommand
  • cli/src/config/mapper.ts - Export mapProviderToApiConfig() for use by models command

Usage

# List models for current provider
kilocode models --json

# List models for specific provider
kilocode models --provider anthropic-1 --json

Output Format

{
  "provider": "kilocode",
  "currentModel": "anthropic/claude-opus-4.5",
  "models": [
    {
      "id": "anthropic/claude-opus-4.5",
      "displayName": "Anthropic: Claude Opus 4.5",
      "contextWindow": 200000,
      "supportsImages": true,
      "inputPrice": 5,
      "outputPrice": 25
    }
  ]
}

Implementation Details

For router-based providers (kilocode, openrouter, etc.), the command:

  1. Creates and initializes an ExtensionService
  2. Injects provider configuration
  3. Sends requestRouterModels message
  4. Waits for routerModels response (30-second timeout)
  5. Transforms and outputs JSON
  6. Disposes the service

For static providers (anthropic, gemini, etc.), the command uses the built-in model definitions without needing to initialize the extension.

Testing

  • Manual testing confirmed the command successfully outputs 200+ models from the kilocode provider
  • Unit tests cover transformation logic, output format validation, and error handling

@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2026

🦋 Changeset detected

Latest commit: 5b35a04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marius-kilocode marius-kilocode requested a review from a team January 13, 2026 18:13
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 13, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR adds a new kilocode models --json command to the CLI that exposes available models as JSON for programmatic use. The implementation is well-structured with:

  • Clean separation of concerns between the command handler and model transformation logic
  • Proper error handling with typed error codes
  • Support for both static providers (anthropic, gemini, etc.) and router-based providers (kilocode, openrouter, ollama, etc.)
  • Comprehensive test coverage for the transformation logic and interface contracts
Files Reviewed (4 files)
  • .changeset/cli-models-api-command.md - Changeset for the new feature
  • cli/src/commands/__tests__/models-api.test.ts - Test suite for the models API command
  • cli/src/commands/models-api.ts - Main implementation of the models API command
  • cli/src/config/mapper.ts - Export of mapProviderToApiConfig function
  • cli/src/index.ts - Registration of the new models command

Notes

  • The test file uses inline implementations of transformModelsToOutput to avoid jotai mock issues, which is a reasonable approach for testing the transformation logic
  • The existing comment about timeout inconsistency (test expects 10 seconds vs implementation's 30 seconds) was already noted in a previous review

- Add 'kilocode models --json' command to expose available models as JSON
- Implement lightweight extension initialization for router-based providers
- Add 30-second timeout for router models request
- Export mapProviderToApiConfig from mapper.ts for use by models command
- Support both router-based providers (kilocode, openrouter) and static providers
@marius-kilocode marius-kilocode force-pushed the cli-models-json-support branch from 69915a5 to 5148127 Compare January 13, 2026 18:18
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.

2 participants