docs: add headless mode guide (#8564)

This commit is contained in:
Jerop Kipruto
2025-09-17 04:01:15 +09:00
committed by GitHub
parent d0b505a577
commit a015ea203f
3 changed files with 329 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ Within Gemini CLI, `packages/cli` is the frontend for users to send and receive
- **[Commands](./commands.md):** A reference for Gemini CLI commands (e.g., `/help`, `/tools`, `/theme`).
- **[Configuration](./configuration.md):** A guide to tailoring Gemini CLI behavior using configuration files.
- **[Enterprise](./enterprise.md):** A guide to enterprise configuration.
- **[Headless Mode](./headless.md):** A comprehensive guide to using Gemini CLI programmatically for scripting and automation.
- **[Token Caching](./token-caching.md):** Optimize API costs through token caching.
- **[Themes](./themes.md)**: A guide to customizing the CLI's appearance with different themes.
- **[Tutorials](tutorials.md)**: A tutorial showing how to use Gemini CLI to automate a development task.
@@ -22,24 +23,10 @@ The following example pipes a command to Gemini CLI from your terminal:
echo "What is fine tuning?" | gemini
```
Gemini CLI executes the command and prints the output to your terminal. Note that you can achieve the same behavior by using the `--prompt` or `-p` flag. For example:
You can also use the `--prompt` or `-p` flag:
```bash
gemini -p "What is fine tuning?"
```
For non-interactive usage with structured output, use the `--output-format json` flag for scripting and automation.
Get structured JSON output for scripting:
```bash
gemini -p "What is fine tuning?" --output-format json
# Output:
# {
# "response": "Fine tuning is...",
# "stats": {
# "models": { "gemini-2.5-flash": { "tokens": {"total": 45} } }
# },
# "error": null
# }
```
For comprehensive documentation on headless usage, scripting, automation, and advanced examples, see the **[Headless Mode](./headless.md)** guide.