AI Agent Usage Guide
Quick Setup (Non-Interactive)
# Enable non-interactive mode and consistent output
export INFRA_NON_INTERACTIVE=1
export INFRA_ASSUME_YES=1
export NO_COLOR=1
# Example (init with minimum required flags):
infra init my-tenant -n \
--template frontend-backend \
--environments dev,prd \
--location japaneast \
--frontend-repo GenerativeX/my-tenant-nextjs \
--backend-repo GenerativeX/my-tenant-fastapi \
--frontend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--frontend-acr-name gxsharedacr \
--frontend-image-name my-tenant-frontend \
--backend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--backend-acr-name gxsharedacr \
--backend-image-name my-tenant-backend \
--dev-site-url https://my-tenant-dev.gx-dev.app \
--prd-site-url https://my-tenant.gx-dev.app \
--enable-mysql true \
--enable-redis false \
--enable-storage true
# Example (apply):
infra apply my-tenant dev --yes
This guide explains how to use the infra CLI in non-interactive mode, making it suitable for AI agents like Devin, Codex, and Claude Code.
Overview
The infra CLI now supports both interactive mode (for human users) and non-interactive mode (for AI agents). In non-interactive mode, the CLI will never prompt for user input and will instead fail with clear error messages indicating what flags are required.
Global Flags
These flags can be used with any command: --non-interactive / -n(Never prompt for user input)、--yes / -y(Automatically answer "yes" to all confirmation prompts)、--no-color(Disable colored output)、--quiet / -q(Show only errors)、--verbose / -v(Show detailed output)
Environment Variables
The CLI automatically detects non-interactive mode from environment variables: INFRA_NON_INTERACTIVE=1(Enable non-interactive mode)、INFRA_ASSUME_YES=1(Assume yes to confirmations)、CI=true(Automatically enables non-interactive mode)、NO_COLOR=1(Disable colored output)
Non-Interactive Behavior
Prompts
In non-interactive mode:
-
Selection prompts (
selectOne,selectMany):- If a default value is provided, it will be used
- If there's exactly one option, it will be auto-selected
- If there are multiple options and no default, the command will fail with a list of candidates
-
Input prompts (
input):- If a default value is provided, it will be used
- Otherwise, the command will fail indicating the required flag
-
Confirmation prompts (
confirm):- If
--yesflag is set, returnstrue - Otherwise, returns the default value (usually
false)
- If
-
Password prompts (
password):- Always fail in non-interactive mode (passwords cannot have defaults for security)
Error Messages
When a command fails due to missing input in non-interactive mode, it will provide:
- Clear error message explaining what's missing
- List of available candidates (when applicable)
- Suggested flags to provide the required information
Example error:
{
"code": "ERR_NON_INTERACTIVE_INPUT_REQUIRED",
"message": "Cannot prompt for selection in non-interactive mode: リビジョンを選択してください:",
"candidates": [
"revision-abc123 (revision-abc123)",
"revision-def456 (revision-def456)"
],
"context": {
"message": "リビジョンを選択してください:",
"choiceCount": 2
}
}
Command Examples
Init Command (Non-Interactive)
The init command supports extensive flags for non-interactive usage:
# Full non-interactive init
infra init my-tenant \
--non-interactive \
--template frontend-backend \
--environments dev,prd \
--location japaneast \
--frontend-repo GenerativeX/my-tenant-nextjs \
--frontend-root frontend \
--backend-repo GenerativeX/my-tenant-fastapi \
--backend-root backend \
--frontend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--frontend-acr-name gxsharedacr \
--frontend-image-name my-tenant-frontend \
--backend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--backend-acr-name gxsharedacr \
--backend-image-name my-tenant-backend \
--dev-site-url https://my-tenant-dev.gx-dev.app \
--prd-site-url https://my-tenant.gx-dev.app \
--enable-mysql true \
--enable-redis true \
--enable-storage false \
--dev-db-name my_tenant_dev \
--prd-db-name my_tenant_prd \
--migrate false
Container Apps Commands (Non-Interactive)
Container Apps commands support flags to avoid prompts:
# Shell access with explicit parameters
infra shell my-tenant dev \
--non-interactive \
--app my-tenant-frontend \
--revision revision-abc123 \
--replica replica-xyz789 \
--container my-tenant-frontend
# Logs with explicit parameters
infra logs my-tenant dev \
--non-interactive \
--app my-tenant-backend \
--revision latest \
--container my-tenant-backend \
--follow
# Restart with explicit app
infra restart my-tenant dev \
--non-interactive \
--app my-tenant-frontend
Other Commands (Non-Interactive)
# Generate Terraform (no prompts)
infra generate my-tenant dev --non-interactive
# Plan (no confirmation prompts)
infra plan my-tenant dev
# Apply with auto-approve (--auto-approve or --yes)
infra apply my-tenant dev --auto-approve
# または
infra apply my-tenant dev --yes
# Encrypt/Decrypt (no prompts)
infra encrypt my-tenant --non-interactive
infra decrypt my-tenant --non-interactive
# Validate (no prompts)
infra validate my-tenant --non-interactive
AI Agent Best Practices
1. Always Use Explicit Flags
When using the CLI in AI agent workflows, always provide explicit flags rather than relying on prompts:
# Good
infra init my-tenant --template frontend-backend --environments dev --location japaneast
# Bad (will prompt in interactive mode)
infra init my-tenant
2. Set Environment Variables
For CI/CD pipelines or automated workflows, set environment variables:
export INFRA_NON_INTERACTIVE=1
export INFRA_ASSUME_YES=1
export NO_COLOR=1
3. Handle Errors Gracefully
Parse error messages to understand what flags are missing:
try {
await exec("infra shell my-tenant dev --non-interactive");
} catch (error) {
// Error will contain candidates list if multiple options exist
// Parse and retry with explicit --app, --revision, etc.
}
4. Use --auto-approve or --yes for Apply Commands
When you want to proceed without confirmation prompts for apply, you can use either --auto-approve or the global --yes flag:
infra apply my-tenant dev --auto-approve
# または
infra apply my-tenant dev --yes
5. Disable Colors for Parsing
When parsing CLI output, disable colors:
infra ps my-tenant dev --no-color
Migration from Interactive to Non-Interactive
If you have existing scripts using interactive mode, here's how to migrate:
Before (Interactive)
# This will prompt for template, environments, etc.
infra init my-tenant
After (Non-Interactive)
# Provide all required information via flags
infra init my-tenant \
--non-interactive \
--template frontend-backend \
--environments dev,prd \
--location japaneast \
# ... other flags
Troubleshooting
Command Fails with "Cannot prompt in non-interactive mode"
Solution: Add the required flag indicated in the error message.
Example:
Error: Cannot prompt for selection in non-interactive mode: リビジョンを選択してください:
Candidates: revision-abc123, revision-def456
Fix:
infra shell my-tenant dev --revision revision-abc123
Command Hangs Waiting for Input
Solution: Ensure non-interactive mode is enabled:
# Option 1: Use flag
infra command --non-interactive
# Option 2: Set environment variable
export INFRA_NON_INTERACTIVE=1
infra command
Confirmation Prompts Still Appearing
Solution: Use the --auto-approve flag or the global --yes flag for apply commands:
infra apply my-tenant dev --auto-approve
# または
infra apply my-tenant dev --yes
Examples for Common AI Agent Scenarios
Scenario 1: Devin Setting Up New Tenant
# Step 1: Initialize tenant
infra init my-tenant \
--non-interactive \
--template frontend-backend \
--environments dev \
--location japaneast \
--frontend-repo GenerativeX/my-tenant-nextjs \
--backend-repo GenerativeX/my-tenant-fastapi \
--frontend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--frontend-acr-name gxsharedacr \
--backend-acr-subscription e3143cb2-4707-4614-bbba-3ddeb66669c2 \
--backend-acr-name gxsharedacr \
--dev-site-url https://my-tenant-dev.gx-dev.app \
--enable-mysql true \
--migrate false
# Step 2: Generate and apply
infra generate my-tenant dev --non-interactive
infra plan my-tenant dev
infra apply my-tenant dev --auto-approve
Scenario 2: Codex Debugging Container
# Get container status
infra ps my-tenant dev --no-color
# Access shell (with explicit parameters to avoid prompts)
infra shell my-tenant dev \
--non-interactive \
--app my-tenant-backend \
--container my-tenant-backend
# View logs
infra logs my-tenant dev \
--non-interactive \
--app my-tenant-backend \
--follow
Scenario 3: Claude Code Updating Configuration
# Decrypt environment files
infra decrypt my-tenant --non-interactive
# Edit .env files programmatically
# ... (edit files)
# Re-encrypt
infra encrypt my-tenant --non-interactive
# Regenerate and apply
infra generate my-tenant dev --non-interactive
infra apply my-tenant dev --auto-approve
Summary
The infra CLI now fully supports non-interactive mode, making it suitable for AI agents and automated workflows. Key points:
- Use
--non-interactiveflag or setINFRA_NON_INTERACTIVE=1 - Provide all required information via flags
- Use
--yes(global flag) or--auto-approve(apply command) to skip confirmation prompts - Parse error messages to understand missing flags
- Set
NO_COLOR=1for easier output parsing
For questions or issues, refer to the main documentation or contact the platform team.