GC-101 · Module 1

Essential Commands

4 min read

Gemini CLI uses slash commands for all built-in operations. These are your primary controls for managing sessions, configuring behavior, and navigating the tool. Every productive Gemini CLI session leans on these commands heavily.

/help       Show all available commands and usage
/settings   View and modify configuration
/tools      List all available tools (built-in + MCP)
/stats      Show token usage and model information
/clear      Clear conversation history
/compact    Compress context to free up tokens
/copy       Copy the last response to clipboard
/restore    Restore to a previous checkpoint

The ! prefix is your escape hatch to the shell. Type ! followed by any shell command and Gemini CLI executes it directly without AI involvement. This is faster than asking Gemini to run a command when you know exactly what you want. Think of it as a quick toggle between AI mode and shell mode.

# Run shell commands directly with !
!git status
!npm test
!ls -la src/
!cat package.json | head -20

Headless mode with the -p flag runs Gemini CLI non-interactively. Pass a prompt as a string and Gemini executes it, prints the result, and exits. This is the foundation for scripting and CI/CD integration — you can pipe Gemini CLI into other tools or call it from shell scripts.

# Headless mode — single prompt, no interaction
gemini -p "Explain what this project does based on the README"

# Pipe output to a file
gemini -p "Generate a changelog from the last 10 commits" > CHANGELOG.md

# Use in a script
if gemini -p "Does this code have any obvious security issues? Answer YES or NO" | grep -q "YES"; then
  echo "Security review needed"
fi

Do This

  • Use /clear between unrelated tasks to keep context fresh
  • Check /stats regularly to monitor token consumption
  • Use ! for quick shell commands you already know

Avoid This

  • Let context accumulate across unrelated tasks — quality degrades
  • Ignore token usage until you hit rate limits or quality drops
  • Ask Gemini to run "git status" when !git status is instant