Appearance
The REPL & Your First Task
Gemini CLI has two modes: interactive REPL (type gemini and chat) and one-shot (gemini -p "prompt" -- get a response, exit). Most of your time will be in the REPL, but one-shot mode is the secret weapon for scripts and CI. This lesson covers both, plus the --yolo flag that turns off confirmation prompts, and ends with a real task: fixing a buggy shell script.

What you'll learn
geministarts the interactive REPL;gemini -p "prompt"runs a one-shot command and exits- The REPL gives you a chat interface in your terminal -- type prompts, see responses, approve or deny tool calls
--yoloauto-approves all tool calls. Use it in scripts and CI. Never use it on a prompt you haven't verified first- Gemini CLI can read, edit, and create files, run shell commands, and install packages -- in the REPL or from a one-shot
- Migration note: The REPL experience is identical on Antigravity CLI. One-shot mode may use
antigravity -pinstead ofgemini -p
The problem
You've installed Gemini CLI and authenticated. Now what? Running gemini drops you into a blank REPL with no obvious next step. And if you try to use it in a script, the confirmation prompts block everything. The gap between "it installed" and "it did something useful" is where most people stall. We'll bridge it with a single real task.
Options & when to use each
| Mode | Command | Good for | When to pick it |
|---|---|---|---|
| Interactive REPL | gemini | Exploring codebases, iterative editing, multi-step tasks | You want a conversation -- ask, review, approve, ask again |
| One-shot | gemini -p "prompt" | Scripts, CI/CD, single-answer questions | You know exactly what you want and don't need a conversation |
| One-shot with auto-approval | gemini --yolo -p "prompt" | Automated pipelines, batch processing | You trust the prompt and want zero interaction |
The REPL is where you'll spend most of your time. One-shot mode is for automation. Start in the REPL to build intuition, then move to one-shot when you're ready to script it.
Build it
Step 1: Start the REPL
Launch the CLI without arguments to enter the interactive chat interface.
bash
geminiYou'll see a prompt like > or You: depending on your version. Type a prompt and press Enter:
text
> List the files in the current directory, including hidden filesGemini CLI processes your prompt, may read files or run ls -la, and responds with the listing. If it wants to run a command, it'll ask:
text
Run: ls -la
Approve? (y/n)Type y to approve, n to deny. This approval step is the safety mechanism -- Gemini CLI never executes a command or edits a file without your say-so.
Step 2: Try a one-shot
Exit the REPL with Ctrl+C or /exit, then run:
bash
gemini -p "What files are in the current directory? Use ls."The one-shot runs, prints the response, and exits. No REPL, no confirmation prompts (unless Gemini CLI needs to run a command -- then it still asks). The -p flag stands for "prompt."
Step 3: Auto-approve with --yolo
Now run the same thing with --yolo:
bash
gemini --yolo -p "What files are in the current directory? Use ls."This time Gemini CLI runs ls without asking. --yolo means "approve every tool call automatically." It's dangerous if you don't trust the prompt, but essential for automation.
The interactive equivalent: inside the REPL, type /yolo to toggle auto-approval on for the rest of the session.
Step 4: Your first real task -- fix a buggy script
Create a broken script:
Write a flawed bash script that contains platform-specific bugs and edge case failures. This provides a target for the agent to repair.
bash
cat > /tmp/todo.sh << 'EOF'
#!/bin/bash
# A simple todo list manager – broken on purpose
TODOFILE="$HOME/.todos.txt"
add() {
echo "$1" >> "$TODOFILE"
echo "Added: $1"
}
list() {
if [ -f "$TODOFILE" ]; then
cat -n "$TODOFILE"
fi
}
done() {
sed -i "${1}d" "$TODOFILE" 2>/dev/null || echo "Error removing task $1"
}
case "$1" in
add) add "$2" ;;
list) list ;;
done) done "$2" ;;
*) echo "Usage: $0 add|list|done [task]"
esac
EOF
chmod +x /tmp/todo.shThe problem: done 1 uses sed -i which works differently on macOS (BSD sed) and Linux (GNU sed). On macOS it fails with a cryptic error. It also doesn't handle an empty todo file gracefully.
Now ask Gemini CLI to fix it:
bash
gemini -p "Fix /tmp/todo.sh. The 'done' function breaks on macOS because sed -i works differently. Make it cross-platform (BSD and GNU sed compatible). Also handle the case where the todo file is empty. Keep the script structure the same." --yoloGemini CLI will read the file, identify the sed issue, propose a fix (usually switching to a temporary file approach or using sed -i '' with a conditional), and write the corrected version.
After it finishes, test the fix:
bash
/tmp/todo.sh add "Review Gemini CLI PR"
/tmp/todo.sh add "Update dependencies"
/tmp/todo.sh list
/tmp/todo.sh done 1
/tmp/todo.sh listIf task 1 is gone and task 2 is now at position 1, the fix worked. That's the core workflow you'll repeat for every task in this course: give Gemini CLI a file, tell it what's wrong, let it fix it, verify.
Step 5: One-shot with piped input
One-shot mode also accepts stdin. This is useful for piping error logs or command output directly to Gemini CLI:
bash
# Pipe a compiler error to Gemini CLI for explanation
gcc -o /tmp/test /tmp/test.c 2>&1 | gemini -p "Explain this compiler error and show me how to fix it"Gemini CLI reads the piped text as additional context and responds accordingly.
What goes wrong
| Mistake | How you notice it | The fix |
|---|---|---|
Typing gemini and getting a blank screen | Terminal looks frozen | The REPL is waiting for input. Type your prompt and press Enter. It's not broken, just quiet |
| Gemini CLI refuses to edit a file | "I cannot modify files outside the workspace" or similar | Gemini CLI restricts file access to the current directory and below. cd into the project root, or use full paths within the workspace |
--yolo runs a destructive command | A file you needed is gone | Never use --yolo with a prompt you haven't tested in interactive mode first. Test with approvals on, then automate with --yolo |
| One-shot mode still asks for confirmation | You expected --yolo behavior but forgot the flag | Add --yolo. Without it, Gemini CLI still prompts for every tool call even in one-shot mode |
| Pipes don't work as expected | echo "prompt" | gemini hangs or ignores input | Use gemini -p "$(cat)" instead of piping directly. Or use gemini -p "prompt" < file.txt for file input |
| REPL loses context after many turns | Responses get less relevant, Gemini CLI seems to forget earlier parts of the conversation | The context window fills up. Use /compact to summarize the conversation so far. We'll cover this in the slash commands lesson |
Confirm it worked
Run this sequence. If every step succeeds, you've mastered both modes:
bash
# 1. One-shot: ask a question
gemini --yolo -p "What day of the week is it? Use only the date command."
# 2. One-shot: create a file
gemini --yolo -p "Create /tmp/gemini-test.txt with the text 'Gemini CLI is working'"
# 3. Verify the file exists
cat /tmp/gemini-test.txt
# 4. One-shot: modify the file
gemini --yolo -p "Append the current date to /tmp/gemini-test.txt"
# 5. Check the result
cat /tmp/gemini-test.txtIf /tmp/gemini-test.txt contains both lines with the correct date appended, Gemini CLI is reading, writing, and executing commands correctly in both modes.
Next: Slash Commands