Skip to main content

CLI Reference

Complete reference for Forge command-line interface, including commands and flags.

CLI Commands

CommandDescriptionExample
forgeStart interactive REPLforge
forge -p "query"Execute prompt directly, then exitforge -p "explain this function"
cat file | forgeProcess piped content as prompt, then exitcat logs.txt | forge
forge -c file.txtExecute commands from file, then continue in interactive modeforge -c commands.txt
forge --conversation-id <id>Resume conversation by IDforge --conversation-id abc123
forge -C /path/to/dirChange working directory before startingforge -C ~/projects/myapp
forge --sandbox <name>Create isolated git worktreeforge --sandbox experiment-1
forge list <resource>List resources (agents, models, providers, mcp, etc.)forge list agents
forge config <subcommand>Manage configurationforge config get model
forge conversation <subcommand>Manage conversationsforge conversation list
forge mcp <subcommand>Manage MCP serversforge mcp list
forge infoShow current configuration and statusforge info
forge envDisplay environment informationforge env
forge bannerDisplay version and helpful informationforge banner
forge --versionPrint versionforge --version

CLI Flags

Customize Forge's behavior with these command-line flags:

FlagDescriptionExample
-p, --promptDirect prompt to process without entering interactive mode (mutually exclusive with piping)forge -p "analyze this code"
-c, --commandPath to file containing initial commands to execute, then continue in interactive modeforge -c setup.txt
--conversationPath to JSON file containing conversation to executeforge --conversation chat.json
--conversation-idResume or continue existing conversation by IDforge --conversation-id abc123
-C, --directoryWorking directory to set before starting forgeforge -C ~/projects
--sandboxCreate isolated git worktree for experimentationforge --sandbox feature-test
--verboseEnable verbose output modeforge --verbose
-r, --restrictedUse restricted shell (rbash) for enhanced securityforge -r
--agentAgent ID to use for this sessionforge --agent sage
-w, --workflowPath to file containing workflow to executeforge -w workflow.yaml
-e, --eventDispatch event to workflowforge -e '{"name": "fix_issue", "value": "449"}'
-h, --helpPrint help informationforge --help
-V, --versionPrint versionforge --version

List Commands

View available resources in your Forge installation:

CommandDescriptionExample
forge list agentsList all available agentsforge list agents
forge list providersList all available providersforge list providers
forge list modelsList all available modelsforge list models
forge list configList current configuration valuesforge list config
forge list tools <agent>List all tools for a specific agentforge list tools sage
forge list mcpList all MCP serversforge list mcp
forge list conversationList all conversations (max controlled by FORGE_MAX_CONVERSATIONS env var, defaults to 100)forge list conversation

List Options

FlagDescription
--porcelainOutput in machine-readable format

Configuration Commands

Manage Forge configuration settings:

CommandDescriptionExample
forge config set <field> <value>Set configuration valueforge config set model gpt-4
forge config get <field>Get specific configuration valueforge config get provider
forge config listList all configuration valuesforge config list

Configuration Fields

FieldDescription
modelAI model to use
providerAI provider to use

Configuration Options

FlagDescription
--porcelainOutput in machine-readable format (tab-separated key-value pairs)

Conversation Commands

Manage and interact with conversations:

CommandDescriptionExample
forge conversation listList all conversations (max controlled by FORGE_MAX_CONVERSATIONS env var, defaults to 100)forge conversation list
forge conversation newCreate a new conversation and output its IDforge conversation new
forge conversation dump <id> [format]Dump conversation as JSON or HTMLforge conversation dump abc123 html
forge conversation compact <id>Compact the conversation contextforge conversation compact abc123
forge conversation retry <id>Retry last command without modifying contextforge conversation retry abc123
forge conversation resume <id>Resume a conversation (starts interactive mode)forge conversation resume abc123
forge conversation show <id>Show last assistant messageforge conversation show abc123
forge conversation info <id>Show conversation info (ID, title, tasks, completion status, file changes, token usage, cost)forge conversation info abc123

Conversation Options

FlagDescription
--porcelainOutput in machine-readable format

Dump Format

When using forge conversation dump, you can specify the output format:

  • JSON (default): Omit format argument or specify json
  • HTML: Specify html for formatted HTML output
# Dump as JSON
forge conversation dump abc123

# Dump as HTML
forge conversation dump abc123 html

MCP Commands

Manage Model Context Protocol (MCP) servers:

CommandDescriptionExample
forge mcp importImport MCP servers configuration from JSONforge mcp import
forge mcp listList all MCP serversforge mcp list
forge mcp remove <name>Remove a server by nameforge mcp remove playwright
forge mcp show <name>Show detailed configuration for a serverforge mcp show playwright
forge mcp reloadReload MCP servers and rebuild cachesforge mcp reload

MCP Options

FlagDescription
--porcelainOutput in machine-readable format

Advanced Usage

Working Directory

Change the working directory before starting Forge:

forge -C /path/to/project -p "analyze the codebase"

Sandbox Mode

Create an isolated git worktree for experimentation without affecting your main branch:

forge --sandbox experiment-1

This creates a new git worktree where you can safely test changes.

Workflow Execution

Execute predefined workflows with custom events:

# Execute workflow
forge -w workflow.yaml

# Execute workflow with event
forge -w workflow.yaml -e '{"name": "fix_issue", "value": "449"}'

Security Mode

Run Forge with restricted shell for enhanced security:

forge -r

This uses rbash (restricted bash) to limit potentially harmful operations.

Verbose Output

Enable detailed logging for debugging:

forge --verbose -p "complex task"

Agent Selection

Use a specific agent for your session:

forge --agent sage -p "research this topic"

Piping Content

Forge supports piping content from stdin as an alternative to using the -p flag. Note: Piping and -p flag are mutually exclusive - when you use -p, the piped content is ignored.

# Pipe file content (piped content becomes the prompt)
cat README.md | forge

# Pipe command output
git log --oneline | forge

# Pipe from multiple sources
cat file1.txt file2.txt | forge

# Combine with other flags
cat config.json | forge --agent sage
tip

Use piping when you want to process file contents or command output. The piped content will be treated as your prompt to Forge. If you need to provide additional context or instructions, use the -p flag instead.

Session Management

Resume Conversation

Continue a previous conversation using its ID:

# Using conversation-id flag
forge --conversation-id abc123

# Using conversation resume command
forge conversation resume abc123

View Conversation History

List all your conversations:

forge conversation list

View specific conversation details:

# Show detailed information about a conversation
forge conversation info <conversation-id>

# Show the last assistant message
forge conversation show <conversation-id>

Export Conversation

Export conversations for sharing or archival:

# Export as JSON
forge conversation dump abc123 > conversation.json

# Export as HTML
forge conversation dump abc123 html > conversation.html

Porcelain Mode

Many commands support --porcelain flag for machine-readable output, useful for scripting:

# Get config in parseable format
forge config list --porcelain

# List agents for scripts
forge list agents --porcelain

# List conversations for automation
forge conversation list --porcelain
tip

The --porcelain flag provides tab-separated or structured output that's easier to parse in scripts and automation tools.

Environment Information

View system and environment details:

# Show current configuration and active model
forge info

# Display environment variables and paths
forge env

# Show version and helpful information
forge banner

Examples

Quick Analysis

forge -p "explain the main function in src/main.rs"

Interactive Session with Setup

forge -c initial-commands.txt

Resume Previous Work

forge --conversation-id abc123 -p "continue where we left off"

Sandbox Experimentation

forge --sandbox new-feature -p "implement the user authentication"

Workflow Automation

forge -w ci-workflow.yaml -e '{"name": "deploy", "value": "production"}'

Verbose Debugging

forge --verbose -C ~/my-project -p "debug the failing test"

See Also