> ## Documentation Index
> Fetch the complete documentation index at: https://chatcli.edilsonfreitas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# One-Shot, Pipes, and Automation

> Use ChatCLI in scripts, CI/CD pipelines, and automations with one-shot mode and stdin pipes.

ChatCLI's one-shot mode allows you to run prompts in a single line, ideal for scripts, CI/CD pipelines, and automations.

## Basic One-Shot Mode

Use the `-p` flag to send a prompt and exit immediately:

```bash theme={"system"}
chatcli -p "Briefly explain this repository."
```

All context features work within the prompt:

```bash theme={"system"}
chatcli -p "@git @env Create a concise release note."
chatcli -p "@file ./src --mode summary Provide an architecture overview."
```

***

## Pipes and stdin

ChatCLI accepts input via pipe, combining the output of other commands with your prompt:

```bash theme={"system"}
# Analyze Git diff
git diff | chatcli -p "Summarize the changes and list possible impacts."

# Diagnose errors
cat error.log | chatcli -p "Explain the root cause and suggest a solution."

# Analyze command output
kubectl get pods -n production | chatcli -p "Which pods are having issues?"

# Review code
cat src/auth.go | chatcli -p "Review this code and point out vulnerabilities."
```

***

## Available Flags

| Flag                | Description                                       | Example               |
| ------------------- | ------------------------------------------------- | --------------------- |
| `-p`, `--prompt`    | Text to send to the LLM                           | `-p "Explain this"`   |
| `--provider`        | Override the AI provider                          | `--provider CLAUDEAI` |
| `--model`           | Override the model                                | `--model gpt-4o`      |
| `--max-tokens`      | Token limit for the response                      | `--max-tokens 1000`   |
| `--timeout`         | Call timeout (Go duration)                        | `--timeout 30s`       |
| `--no-anim`         | Disable animations (useful in scripts)            | `--no-anim`           |
| `--agent-auto-exec` | Automatically execute the first suggested command | `--agent-auto-exec`   |
| `--realm`           | Realm/tenant for StackSpot                        | `--realm my-tenant`   |
| `--agent-id`        | Agent ID for StackSpot                            | `--agent-id xxx`      |

***

## One-Shot Agent Mode

Combine `/agent` in the prompt to delegate tasks:

```bash theme={"system"}
# Dry-run: only suggests the command and exits
chatcli -p "/agent list all .go files in this directory"

# Automatic execution: runs the first safe command
chatcli -p "/agent create a file called test_file.txt" --agent-auto-exec
```

<Warning>
  With `--agent-auto-exec`, dangerous commands are automatically blocked. Only commands considered safe will be executed.
</Warning>

***

## Automation Examples

### Generate release notes automatically

```bash theme={"system"}
#!/bin/bash
chatcli -p "@git Create detailed release notes for the latest tag." \
  --provider CLAUDEAI \
  --no-anim > RELEASE_NOTES.md
```

### Review PR in CI

```bash theme={"system"}
#!/bin/bash
git diff main...HEAD | chatcli -p "Review this diff. List security issues, potential bugs, and suggestions." \
  --no-anim \
  --max-tokens 2000
```

### Analyze logs in a cron job

```bash theme={"system"}
#!/bin/bash
tail -100 /var/log/nginx/error.log | chatcli -p "Summarize the errors and suggest corrective actions." \
  --no-anim >> /var/log/ai-analysis.log
```

### One-shot with a specific provider

```bash theme={"system"}
chatcli -p "@file ./src --mode summary Describe the architecture" \
  --provider STACKSPOT \
  --agent-id "your-agent-id"
```

***

## Tips

<Tip>
  Create an alias in your shell for quick access: `alias c='chatcli'` and `alias ai='chatcli -p'`. Then use: `ai "Explain what this command does: iptables -t nat -L"`
</Tip>

* Use `--no-anim` in **all** scripts to avoid escape characters in the output
* Combine with `>` to redirect output to files
* Use `--timeout` to prevent scripts from hanging while waiting for a response
* Double quotes are important: `chatcli -p "text with @file and @git"` (protects against shell interpretation)
