Skip to content

Instantly share code, notes, and snippets.

@alexanderson1993
Created January 30, 2026 14:53
Show Gist options
  • Select an option

  • Save alexanderson1993/65db235eb6fa19f3684dabab3c8209cb to your computer and use it in GitHub Desktop.

Select an option

Save alexanderson1993/65db235eb6fa19f3684dabab3c8209cb to your computer and use it in GitHub Desktop.
A simple programmable AI CLI
import { type ModelMessage, generateText } from 'ai';
import { intro, log, text, isCancel, outro, spinner } from '@clack/prompts';
import { anthropic } from '@ai-sdk/anthropic';
intro(`AI Assistant`);
const systemContent = `You are a helpful AI assistant`
const conversation: ModelMessage[] = [
{
role: 'system',
content: systemContent
}
];
while (true) {
const question = await text({ message: '' });
if (isCancel(question)) {
break;
}
conversation.push({ role: 'user', content: question });
await getResponse();
}
outro('See you later!');
async function getResponse() {
const s = spinner();
s.start('Generating response...');
console.time('Generate');
const { text } = await generateText({
model: anthropic('claude-haiku-4-5-20251001'),
// model: openai('gpt-5-mini'),
messages: conversation,
});
console.timeEnd('Generate');
s.stop('');
log.info(text);
conversation.push({ role: 'assistant', content: text });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment