GC-301g · Module 1

Non-Interactive Execution

3 min read

Non-interactive execution is the foundation of every headless automation pattern. The -p flag tells Gemini CLI to accept a prompt as a command-line argument, process it without waiting for human input, and exit when the response is complete. No REPL, no conversation loop, no interactive confirmation. This transforms Gemini CLI from a chat interface into a Unix-style command that slots into any automation pipeline — shell scripts, cron jobs, CI/CD workflows, orchestration frameworks.

The critical distinction between interactive and non-interactive mode is state management. Interactive sessions maintain conversation history, load previous context, and allow multi-turn refinement. Non-interactive invocations are stateless — each call starts fresh with only the prompt and any files Gemini auto-discovers (like GEMINI.md). This statelessness is an advantage for automation: identical inputs produce identical behavior regardless of what ran before. Reproducibility is the first requirement of production-grade automation.

# Basic non-interactive execution
gemini -p "Summarize the architecture of this project"

# Suppress all non-response output for clean piping
gemini -p "List all TODO comments in src/" 2>/dev/null

# Combine with --output-format for structured output
gemini -p "Identify unused exports in src/utils/" --output-format json

# Pass multiline prompts with heredoc
gemini -p "$(cat <<'PROMPT'
Analyze the following code for memory leaks.
Focus on event listeners and unclosed resources.
Output a JSON array of findings.
PROMPT
)"