Skip to content

Pipes and scripts

kunji ask answers one question and exits, which makes it easy to use with other commands.

Terminal window
npm test 2>&1 | kunji ask "Why are these tests failing?"
git log --oneline -20 | kunji ask "Write release notes from these commits"
cat config.yaml | kunji ask "Is anything wrong with this config?"

Piped text is added under your question. Very large input is cut to the last 200,000 characters.

When the output goes to a file or another command, kunji prints plain text with no colours or boxes. Force it with --raw:

Terminal window
kunji ask --raw "Write a .gitignore for a Node project" > .gitignore
git commit -m "$(kunji @commit --raw)"

In CI or on servers, use environment variables instead of the keychain:

Terminal window
export OPENAI_API_KEY=sk-...
kunji ask -m openai:gpt-4o-mini "Summarize this" < report.txt

Or store a key from a script without typing it:

Terminal window
echo "$GROQ_API_KEY" | kunji keys add groq --key-stdin --model llama-3.3-70b-versatile

All variables: Environment variables.

Code Meaning
0 Success
1 Something failed (bad key, provider error, missing file); the message says why
2 The command was used wrongly (missing argument, interactive command without a terminal)
130 Cancelled with Ctrl+C

kunji chat and the menu need a real terminal. In scripts, use kunji ask, kunji @name and commands with flags (for example kunji keys remove groq --yes).