Grok CLI chat
Default: if grok can search or answer it, run grok. Do this whenever possible, not only when asked. Do not fall back to agy.
When the task is a question, search, explanation, or follow-up (not implementing code), run grok CLI only. Do not use agy. For implementing or editing code, use CLI coding with grok or agy instead.
1. Check grok
Ensure PATH includes common install locations (e.g. ~/.local/bin, ~/.grok/bin).
If grok is missing or not signed in (no ~/.grok/auth.json / grok login not done), tell the user. Do not fall back to agy.
2. Choose a working directory
--continue / --resume are scoped to --cwd. Keep using the same directory for a thread.
- Questions about a repo: that project directory
- General threads not tied to a repo: a stable scratch dir such as
/tmp/grok-chat(create it if needed) and keep using it so continue works
3. Continue a previous session
If this is a follow-up on a grok chat already run with the same --cwd, resume — do not start a blank session. A different directory means a new session.
Prefer -c / --continue with the follow-up. Use either -p / --single or --prompt-file, never both.
grok --always-approve --permission-mode bypassPermissions \
--cwd "$DIR" \
-c -p "follow-up"
If you have a session id, -r / --resume <SESSION_ID_OR_TITLE> is the precise form (UUID = id). Omitting the id resumes the most recent session for that cwd.
From that directory:
grok sessions list -n 20
grok sessions search QUERY
grok sessions list prints SESSION ID. After a run you expect to continue later, note that id (do not print secrets). Do not pass --fork-session or --restore-code unless the user asks.
4. Run (new or one-shot)
Leave web search/fetch enabled unless the user wants to stay offline (then pass --disable-web-search).
export PATH="$HOME/.local/bin:$HOME/.grok/bin:$PATH"
grok --always-approve --permission-mode bypassPermissions \
--cwd "$DIR" \
--prompt-file /tmp/grok-chat-prompt.md \
--output-format plain
Short questions:
grok --always-approve --permission-mode bypassPermissions \
--cwd "$DIR" \
-p "…"
5. After grok answers
Summarize the CLI answer for the user in plain language. Do not claim search results or facts you did not get from this grok run. Never paste bot tokens, API keys, webhook secrets, or auth files into the prompt or the summary.