Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/switch-model-agent-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": minor
---

Support VS Code switch links that select a Kilo model, agent, or both.
40 changes: 29 additions & 11 deletions packages/kilo-docs/pages/code-with-ai/agents/model-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,40 @@ The model selection is remembered per mode across sessions.

For details on configuring subagent models, see [Custom Subagents](/docs/customize/custom-subagents).

## Selecting a Model via a Link (VS Code)
## Selecting a Model or Agent via a Link (VS Code)

The VS Code extension supports a `vscode://` protocol handler that lets you open VS Code and automatically select a specific model — no manual picker interaction required. This is useful for sharing model recommendations, launching a specific model tier from a web page, or switching quickly to a newly announced model.
The VS Code extension supports a `vscode://` protocol handler that lets you open VS Code and automatically select a model, an agent, or both — no manual picker interaction required. This is useful for sharing model recommendations, launching a specific model tier from a web page, or switching quickly to a preferred agent.

### URL Format

Include at least one of the `model` or `agent` parameters:

```
vscode://kilocode.kilo-code/kilocode/model?model=<modelID>
vscode://kilocode.kilo-code/kilocode/switch?model=<modelID>
vscode://kilocode.kilo-code/kilocode/switch?agent=<agentName>
vscode://kilocode.kilo-code/kilocode/switch?model=<modelID>&agent=<agentName>
```

Replace `<modelID>` with the Kilo Gateway model ID you want to select (e.g. `kilo-auto/free`). Only models available in the Kilo Gateway catalog are accepted; the link is silently ignored if the model ID is not found.
Replace `<modelID>` with a Kilo Gateway model ID such as `kilo-auto/free`. Replace `<agentName>` with a visible primary agent ID such as `code` or `plan`, rather than its display name.

### Example: Auto Free

To open Kilo Code and switch to the [Auto Free](/docs/code-with-ai/agents/auto-model) tier (`kilo-auto/free`), use:

```
vscode://kilocode.kilo-code/kilocode/model?model=kilo-auto%2Ffree
vscode://kilocode.kilo-code/kilocode/switch?model=kilo-auto%2Ffree
```

To switch only to Plan and use its normal model selection, specify the agent without a model:

```
vscode://kilocode.kilo-code/kilocode/switch?agent=plan
```

To select both at the same time, include both parameters:

```
vscode://kilocode.kilo-code/kilocode/switch?model=kilo-auto%2Ffree&agent=plan
```

{% callout type="tip" %}
Expand All @@ -168,18 +184,20 @@ URL-encode the `/` in model IDs as `%2F` when embedding this URL in HTML links o

### How It Works

- **VS Code open**: the Kilo sidebar is focused and the model is selected in the active session immediately.
- **VS Code closed**: VS Code launches, then applies the model selection once the extension is ready.
- The model is validated against the current Kilo Gateway model catalog before being applied. If the model ID is not found in the catalog, the deep link is silently ignored.
- Model selection via deep link follows the same precedence as using the model picker: it applies as a session override for the active session (or sets the next-session model when no session is active), and updates your model recents list. It does **not** change your configured default model in settings.
- **VS Code open**: the Kilo sidebar is focused and the linked selection is applied to the active session immediately.
- **VS Code closed**: VS Code launches, then applies the selection once the extension is ready.
- When `model` is provided, it must identify a model in the current Kilo Gateway catalog. Invalid or unavailable models cause the deep link to be ignored.
- When `agent` is provided, it must identify a visible primary agent. Invalid or unavailable agents cause the deep link to be ignored.
- An agent-only link uses the model that would normally be selected for that agent. When both parameters are present, the agent is selected first so the linked model applies to it.
- The selection follows the same precedence as using the pickers: it updates the active session, or the next session when no session is active. It does **not** change your configured defaults in settings.

### Sharing and Embedding

You can embed these links in a web page:

```html
<a href="vscode://kilocode.kilo-code/kilocode/model?model=kilo-auto%2Ffree">
Open Kilo Code with Auto Free
<a href="vscode://kilocode.kilo-code/kilocode/switch?model=kilo-auto%2Ffree&amp;agent=plan">
Open Kilo Code with Auto Free in Plan
</a>
```

Expand Down
15 changes: 8 additions & 7 deletions packages/kilo-vscode/src/KiloProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
private configWarningsShown = false
/** Cached notificationsLoaded payload */
private cachedNotificationsMessage: unknown = null
private pendingKiloModelID: string | null = null
private pendingKiloModel: { modelID?: string; agent?: string } | null = null
private pendingReviewComments: { comments: unknown[]; autoSend: boolean }[] = []
private readyResolvers: (() => void)[] = []
private promptRecoveryQueued = false
Expand Down Expand Up @@ -716,8 +716,9 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
this.postMessage({ type: "openCloudSession", sessionId })
}

public selectKiloModel(modelID: string): void {
this.pendingKiloModelID = modelID
public selectKiloModel(modelID?: string, agent?: string): void {
if (!modelID && !agent) return
this.pendingKiloModel = { ...(modelID && { modelID }), ...(agent && { agent }) }
this.flushPendingKiloModel()
}

Expand Down Expand Up @@ -3292,11 +3293,11 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
}

private flushPendingKiloModel(): void {
if (!this.webview || !this.isWebviewReady || !this.client || !this.pendingKiloModelID) return
if (!this.webview || !this.isWebviewReady || !this.client || !this.pendingKiloModel) return

const modelID = this.pendingKiloModelID
this.pendingKiloModelID = null
this.postMessage({ type: "selectKiloModel", modelID })
const pending = this.pendingKiloModel
this.pendingKiloModel = null
this.postMessage({ type: "selectKiloModel", ...pending })
}

public async appendReviewComments(comments: unknown[], autoSend = false): Promise<void> {
Expand Down
12 changes: 7 additions & 5 deletions packages/kilo-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,14 @@ export function activate(context: vscode.ExtensionContext) {
return
}

if (uri.path !== "/kilocode/model") return
const modelID = new URLSearchParams(uri.query).get("model")
if (!modelID) return
console.log("[Kilo New] URI handler: selecting linked Kilo model:", modelID)
if (uri.path !== "/kilocode/switch" && uri.path !== "/kilocode/model") return
const params = new URLSearchParams(uri.query)
const modelID = params.get("model") || undefined
const agent = params.get("agent") || undefined
if (!modelID && !agent) return
console.log("[Kilo New] URI handler: applying linked Kilo selection:", { modelID, agent })
await vscode.commands.executeCommand(`${KiloProvider.viewType}.focus`)
provider.selectKiloModel(modelID)
provider.selectKiloModel(modelID, agent)
},
}),
)
Expand Down
26 changes: 18 additions & 8 deletions packages/kilo-vscode/webview-ui/src/context/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ export const SessionProvider: ParentComponent = (props) => {
const [agents, setAgents] = createSignal<AgentInfo[]>([])
const [allAgents, setAllAgents] = createSignal<AgentInfo[]>([])
const [defaultAgent, setDefaultAgent] = createSignal("code")
const [pendingKiloModel, setPendingKiloModel] = createSignal<{ modelID: string; after: number } | null>(null)
const [pendingKiloModel, setPendingKiloModel] = createSignal<{
modelID?: string
agent?: string
after: number
} | null>(null)
const [catalog, setCatalog] = createSignal(0)

// Skills loaded from the CLI backend
Expand Down Expand Up @@ -598,29 +602,35 @@ export const SessionProvider: ParentComponent = (props) => {
}
}

function selectKiloModel(modelID: string) {
setPendingKiloModel({ modelID, after: catalog() })
vscode.postMessage({ type: "requestProviders" })
function selectKiloModel(modelID?: string, agent?: string) {
if (!modelID && !agent) return
setPendingKiloModel({ ...(modelID && { modelID }), ...(agent && { agent }), after: catalog() })
if (modelID) vscode.postMessage({ type: "requestProviders" })
}

const unsubKiloModel = vscode.onMessage((message: ExtensionMessage) => {
if (message.type === "providersLoaded") {
setCatalog((value) => value + 1)
return
}
if (message.type === "selectKiloModel") selectKiloModel(message.modelID)
if (message.type === "selectKiloModel") selectKiloModel(message.modelID, message.agent)
})
onCleanup(unsubKiloModel)

createEffect(() => {
const pending = pendingKiloModel()
if (!pending || agents().length === 0 || catalog() <= pending.after) return
if (!pending || agents().length === 0 || (pending.modelID && catalog() <= pending.after)) return
setPendingKiloModel(null)
if (!provider.providers()[KILO_PROVIDER_ID]?.models[pending.modelID]) {
if (pending.modelID && !provider.providers()[KILO_PROVIDER_ID]?.models[pending.modelID]) {
console.warn("[Kilo New] Ignoring unavailable Kilo catalog model:", pending.modelID)
return
}
selectModel(KILO_PROVIDER_ID, pending.modelID)
if (pending.agent && !agentNames().has(pending.agent)) {
console.warn("[Kilo New] Ignoring unavailable Kilo agent:", pending.agent)
return
}
if (pending.agent) selectAgent(pending.agent)
if (pending.modelID) selectModel(KILO_PROVIDER_ID, pending.modelID)
})

function promptAgent(sessionID?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export interface OpenCloudSessionMessage {

export interface SelectKiloModelMessage {
type: "selectKiloModel"
modelID: string
modelID?: string
agent?: string
}

export interface ActionMessage {
Expand Down
Loading