@@ -15,6 +15,8 @@ function getEnvVarForProvider(provider: string): string {
1515 return 'CLAUDE_CODE_USE_FOUNDRY'
1616 case 'gemini' :
1717 return 'CLAUDE_CODE_USE_GEMINI'
18+ case 'grok' :
19+ return 'CLAUDE_CODE_USE_GROK'
1820 default :
1921 throw new Error ( `Unknown provider: ${ provider } ` )
2022 }
@@ -48,6 +50,7 @@ const call: LocalCommandCall = async (args, context) => {
4850 delete process . env . CLAUDE_CODE_USE_FOUNDRY
4951 delete process . env . CLAUDE_CODE_USE_OPENAI
5052 delete process . env . CLAUDE_CODE_USE_GEMINI
53+ delete process . env . CLAUDE_CODE_USE_GROK
5154 return {
5255 type : 'text' ,
5356 value : 'API provider cleared (will use environment variables).' ,
@@ -59,6 +62,7 @@ const call: LocalCommandCall = async (args, context) => {
5962 'anthropic' ,
6063 'openai' ,
6164 'gemini' ,
65+ 'grok' ,
6266 'bedrock' ,
6367 'vertex' ,
6468 'foundry' ,
@@ -87,6 +91,19 @@ const call: LocalCommandCall = async (args, context) => {
8791 }
8892 }
8993
94+ // Check env vars when switching to grok (including settings.env)
95+ if ( arg === 'grok' ) {
96+ const mergedEnv = getMergedEnv ( )
97+ const hasKey = ! ! ( mergedEnv . GROK_API_KEY || mergedEnv . XAI_API_KEY )
98+ if ( ! hasKey ) {
99+ updateSettingsForSource ( 'userSettings' , { modelType : 'grok' } )
100+ return {
101+ type : 'text' ,
102+ value : `Switched to Grok provider.\nWarning: Missing env var: GROK_API_KEY (or XAI_API_KEY)\nConfigure it via settings.json env or set manually.` ,
103+ }
104+ }
105+ }
106+
90107 // Check env vars when switching to gemini (including settings.env)
91108 if ( arg === 'gemini' ) {
92109 const mergedEnv = getMergedEnv ( )
@@ -104,13 +121,14 @@ const call: LocalCommandCall = async (args, context) => {
104121 // Handle different provider types
105122 // - 'anthropic', 'openai', 'gemini' are stored in settings.json (persistent)
106123 // - 'bedrock', 'vertex', 'foundry' are env-only (do NOT touch settings.json)
107- if ( arg === 'anthropic' || arg === 'openai' || arg === 'gemini' ) {
124+ if ( arg === 'anthropic' || arg === 'openai' || arg === 'gemini' || arg === 'grok' ) {
108125 // Clear any cloud provider env vars to avoid conflicts
109126 delete process . env . CLAUDE_CODE_USE_BEDROCK
110127 delete process . env . CLAUDE_CODE_USE_VERTEX
111128 delete process . env . CLAUDE_CODE_USE_FOUNDRY
112129 delete process . env . CLAUDE_CODE_USE_OPENAI
113130 delete process . env . CLAUDE_CODE_USE_GEMINI
131+ delete process . env . CLAUDE_CODE_USE_GROK
114132 // Update settings.json
115133 updateSettingsForSource ( 'userSettings' , { modelType : arg } )
116134 // Ensure settings.env gets applied to process.env
@@ -122,6 +140,7 @@ const call: LocalCommandCall = async (args, context) => {
122140 delete process . env . OPENAI_API_KEY
123141 delete process . env . OPENAI_BASE_URL
124142 delete process . env . CLAUDE_CODE_USE_GEMINI
143+ delete process . env . CLAUDE_CODE_USE_GROK
125144 process . env [ getEnvVarForProvider ( arg ) ] = '1'
126145 // Do not modify settings.json - cloud providers controlled solely by env vars
127146 applyConfigEnvironmentVariables ( )
@@ -136,9 +155,9 @@ const provider = {
136155 type : 'local' ,
137156 name : 'provider' ,
138157 description :
139- 'Switch API provider (anthropic/openai/gemini/bedrock/vertex/foundry)' ,
158+ 'Switch API provider (anthropic/openai/gemini/grok/ bedrock/vertex/foundry)' ,
140159 aliases : [ 'api' ] ,
141- argumentHint : '[anthropic|openai|gemini|bedrock|vertex|foundry|unset]' ,
160+ argumentHint : '[anthropic|openai|gemini|grok| bedrock|vertex|foundry|unset]' ,
142161 supportsNonInteractive : true ,
143162 load : ( ) => Promise . resolve ( { call } ) ,
144163} satisfies Command
0 commit comments