Skip to content

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.

Gnome mascot

What you'll learn

  • gemini starts 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
  • --yolo auto-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 -p instead of gemini -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

ModeCommandGood forWhen to pick it
Interactive REPLgeminiExploring codebases, iterative editing, multi-step tasksYou want a conversation -- ask, review, approve, ask again
One-shotgemini -p "prompt"Scripts, CI/CD, single-answer questionsYou know exactly what you want and don't need a conversation
One-shot with auto-approvalgemini --yolo -p "prompt"Automated pipelines, batch processingYou 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
gemini

You'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 files

Gemini 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.sh

The 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." --yolo

Gemini 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 list

If 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

MistakeHow you notice itThe fix
Typing gemini and getting a blank screenTerminal looks frozenThe 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 similarGemini 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 commandA file you needed is goneNever 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 confirmationYou expected --yolo behavior but forgot the flagAdd --yolo. Without it, Gemini CLI still prompts for every tool call even in one-shot mode
Pipes don't work as expectedecho "prompt" | gemini hangs or ignores inputUse gemini -p "$(cat)" instead of piping directly. Or use gemini -p "prompt" < file.txt for file input
REPL loses context after many turnsResponses get less relevant, Gemini CLI seems to forget earlier parts of the conversationThe 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.txt

If /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