Skip to content

Commit 8159185

Browse files
Max_ProMax_Pro
authored andcommitted
feat(tools): inject current model info into slashcommand and skill output
- Add setSessionModel/getSessionModel to session state - Store model info from chat.message hook - Display **Current Model**: provider/modelID in command/skill output
1 parent 5c7eb02 commit 8159185

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/features/claude-code-session-state/state.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,31 @@ export function getMainSessionID(): string | undefined {
1414
export function _resetForTesting(): void {
1515
_mainSessionID = undefined
1616
subagentSessions.clear()
17+
sessionAgentMap.clear()
18+
sessionModelMap.clear()
1719
}
1820

1921
const sessionAgentMap = new Map<string, string>()
22+
const sessionModelMap = new Map<string, { providerID: string; modelID: string }>()
2023

2124
export function setSessionAgent(sessionID: string, agent: string): void {
2225
if (!sessionAgentMap.has(sessionID)) {
2326
sessionAgentMap.set(sessionID, agent)
2427
}
2528
}
2629

30+
export function setSessionModel(sessionID: string, model: { providerID: string; modelID: string }): void {
31+
sessionModelMap.set(sessionID, model)
32+
}
33+
34+
export function getSessionModel(sessionID: string): { providerID: string; modelID: string } | undefined {
35+
return sessionModelMap.get(sessionID)
36+
}
37+
38+
export function clearSessionModel(sessionID: string): void {
39+
sessionModelMap.delete(sessionID)
40+
}
41+
2742
export function updateSessionAgent(sessionID: string, agent: string): void {
2843
sessionAgentMap.set(sessionID, agent)
2944
}

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import {
5454
setMainSession,
5555
getMainSessionID,
5656
setSessionAgent,
57+
setSessionModel,
58+
getSessionModel,
5759
updateSessionAgent,
5860
clearSessionAgent,
5961
} from "./features/claude-code-session-state";
@@ -380,7 +382,13 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
380382
setSessionAgent(input.sessionID, input.agent);
381383
}
382384

383-
const message = (output as { message: { variant?: string } }).message
385+
const message = (output as { message: { variant?: string; model?: { providerID?: string; modelID?: string } } }).message
386+
if (message.model?.providerID && message.model?.modelID) {
387+
setSessionModel(input.sessionID, {
388+
providerID: message.model.providerID,
389+
modelID: message.model.modelID,
390+
});
391+
}
384392
if (firstMessageVariantGate.shouldOverride(input.sessionID)) {
385393
const variant = resolveAgentVariant(pluginConfig, input.agent)
386394
if (variant !== undefined) {

src/tools/skill/tools.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { SkillArgs, SkillInfo, SkillLoadOptions } from "./types"
55
import type { LoadedSkill } from "../../features/opencode-skill-loader"
66
import { getAllSkills, extractSkillTemplate } from "../../features/opencode-skill-loader/skill-content"
77
import { injectGitMasterConfig } from "../../features/opencode-skill-loader/skill-content"
8+
import { getSessionModel } from "../../features/claude-code-session-state"
89
import type { SkillMcpManager, SkillMcpClientInfo, SkillMcpServerContext } from "../../features/skill-mcp-manager"
910
import type { Tool, Resource, Prompt } from "@modelcontextprotocol/sdk/types.js"
1011

@@ -163,7 +164,7 @@ export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition
163164
args: {
164165
name: tool.schema.string().describe("The skill identifier from available_skills (e.g., 'code-review')"),
165166
},
166-
async execute(args: SkillArgs, ctx?: { agent?: string }) {
167+
async execute(args: SkillArgs, ctx?: { agent?: string; sessionID?: string }) {
167168
const skills = await getSkills()
168169
const skill = skills.find(s => s.name === args.name)
169170

@@ -183,11 +184,13 @@ export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition
183184
}
184185

185186
const dir = skill.path ? dirname(skill.path) : skill.resolvedPath || process.cwd()
187+
const currentModel = ctx?.sessionID ? getSessionModel(ctx.sessionID) : undefined
186188

187189
const output = [
188190
`## Skill: ${skill.name}`,
189191
"",
190192
`**Base directory**: ${dir}`,
193+
...(currentModel ? [`**Current Model**: ${currentModel.providerID}/${currentModel.modelID}`] : []),
191194
"",
192195
body,
193196
]

src/tools/slashcommand/tools.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isMarkdownFile } from "../../shared/file-utils"
77
import { getClaudeConfigDir } from "../../shared"
88
import { discoverAllSkills, type LoadedSkill } from "../../features/opencode-skill-loader"
99
import { loadBuiltinCommands } from "../../features/builtin-commands"
10+
import { getSessionModel } from "../../features/claude-code-session-state"
1011
import type { CommandScope, CommandMetadata, CommandInfo, SlashcommandToolOptions } from "./types"
1112

1213
function discoverCommandsFromDir(commandsDir: string, scope: CommandScope): CommandInfo[] {
@@ -100,7 +101,12 @@ function skillToCommandInfo(skill: LoadedSkill): CommandInfo {
100101
}
101102
}
102103

103-
async function formatLoadedCommand(cmd: CommandInfo): Promise<string> {
104+
interface CurrentModelInfo {
105+
providerID: string
106+
modelID: string
107+
}
108+
109+
async function formatLoadedCommand(cmd: CommandInfo, currentModel?: CurrentModelInfo): Promise<string> {
104110
const sections: string[] = []
105111

106112
sections.push(`# /${cmd.name} Command\n`)
@@ -126,6 +132,11 @@ async function formatLoadedCommand(cmd: CommandInfo): Promise<string> {
126132
}
127133

128134
sections.push(`**Scope**: ${cmd.scope}\n`)
135+
136+
if (currentModel) {
137+
sections.push(`**Current Model**: ${currentModel.providerID}/${currentModel.modelID}\n`)
138+
}
139+
129140
sections.push("---\n")
130141
sections.push("## Command Instructions\n")
131142

@@ -230,7 +241,7 @@ export function createSlashcommandTool(options: SlashcommandToolOptions = {}): T
230241
),
231242
},
232243

233-
async execute(args) {
244+
async execute(args, ctx) {
234245
const allItems = await getAllItems()
235246

236247
if (!args.command) {
@@ -244,7 +255,8 @@ export function createSlashcommandTool(options: SlashcommandToolOptions = {}): T
244255
)
245256

246257
if (exactMatch) {
247-
return await formatLoadedCommand(exactMatch)
258+
const currentModel = ctx?.sessionID ? getSessionModel(ctx.sessionID) : undefined
259+
return await formatLoadedCommand(exactMatch, currentModel)
248260
}
249261

250262
const partialMatches = allItems.filter((cmd) =>

0 commit comments

Comments
 (0)