Claude in my terminal
Inspired by kqr’s post about calling LLMs from the terminal, I decided to set up llm
and create my own q
script.
Setting up llm
There’s a couple ways you can install llm
and I decided to use uv
:
uv tool install llm
(mise
users can run mise use -g uv
first to install uv
)
I want to use Claude but by default llm
only supports OpenAI’s GPTs, so I had to install the llm-anthropic
plugin:
llm install llm-anthropic
Then I configured my API key by running the following and pasting in my key when prompted:
llm keys set anthropic
llm
is now configured and ready to use! You can test your configuration with:
llm -m claude-4-opus 'Impress me with wild facts about turnips'
The q
script
With Claude’s help, I tweaked kqr’s script to let me craft a prompt in my text editor if none is provided:
#!/usr/bin/bash
if [ $# -eq 0 ]; then
# No arguments - open editor with temp file
tmpfile=$(mktemp)
${EDITOR:-nvim} "$tmpfile"
# Check if file has content after editing
if [ -s "$tmpfile" ]; then
# Replace arguments with file contents
set -- "$(cat "$tmpfile")"
else
rm -f "$tmpfile"
exit 0
fi
# Clean up temp file
rm -f "$tmpfile"
fi
llm -s "Answer in as few words as possible. Use a brief style with short replies." -m anthropic/claude-sonnet-4-0 "$*"
Finally, I saved the above script to ~/.local/bin/q
and made it executable with chmod +x ~/.local/bin/q
.