# How to Run AutoHedge Using the Command-Line Interface (CLI)

> Learn to run AutoHedge using the command-line interface (CLI). Access its interactive REPL via the autohedge command or python -m autohedge for seamless execution.

- Repository: [Swarms/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge)
- Tags: how-to-guide
- Published: 2026-09-08

---

**AutoHedge provides an interactive REPL through a lightweight CLI wrapper located in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py), which you can launch via the installed `autohedge` command, `python -m autohedge`, or standard help flags.**

AutoHedge is an open-source multi-agent hedge fund system that automates quantitative analysis, risk management, and trade execution. The command-line interface serves as the primary entry point for interacting with the swarm of AI agents that power the platform. This guide walks you through installation, launch methods, and the internal workflow of the CLI based on the actual source code implementation.

## Installation and Environment Setup

Before launching the CLI, you must install the package and configure the required API credentials.

Install AutoHedge via pip:

```bash
pip install -U autohedge

```

The CLI depends on several environment variables defined in [`autohedge/env_loader.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/env_loader.py), which searches upward through your directory tree for a `.env` file. Create this file in your project root with the following keys:

- `OPENAI_API_KEY` – Required for the LLM director agent
- `JUPITER_API_KEY` – Required for Solana trading operations  
- Wallet credentials for blockchain interactions

If `OPENAI_API_KEY` is missing when you start the CLI, [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) prints a yellow warning (lines 17-21) but continues execution.

## Launching the Interactive REPL

You can start the AutoHedge CLI using three different methods, all of which ultimately invoke the `main()` function in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py).

### Installed Script Method

The most common approach uses the console script defined in [`setup.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/setup.py) or [`pyproject.toml`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/pyproject.toml):

```bash
autohedge

```

This command executes the entry point mapping that calls `autohedge/cli.main`.

### Module Execution Method

For virtual environments or development setups, run the package as a module:

```bash
python -m autohedge

```

This executes [`autohedge/__main__.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/__main__.py), which imports and calls the same `main` function as the installed script.

### Help and Version Flags

The `_build_parser()` function in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) supports standard utility flags:

```bash

# Display help information

autohedge --help
autohedge help

# Show current version

autohedge --version

```

The version is retrieved dynamically via `importlib.metadata.version`.

## CLI Workflow and Architecture

When you launch the CLI, it performs several initialization steps before presenting the interactive prompt.

### Environment Loading and Validation

First, [`autohedge/env_loader.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/env_loader.py) walks up the directory tree to locate and load your `.env` file without overriding existing environment variables. This ensures API keys are available regardless of your current working directory. The system then checks for `OPENAI_API_KEY` and warns you if it is missing.

### Banner and Recent Tasks Display

Using the **Rich** library, the CLI renders a two-column welcome panel containing ASCII art and helpful tips. It also reads from `~/.autohedge/recent_tasks.txt` to display your most recent hedge fund tasks, providing quick context for continuing previous work.

### The REPL Loop

Once initialized, the CLI enters a read-eval-print loop that:

1. Displays the `>` prompt
2. Parses your input against reserved commands (`quit`, `exit`, `q`, `help`, `?`)
3. Forwards valid task prompts to the core `AutoHedge` class defined in [`autohedge/main.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/main.py)
4. Logs the conversation using the **Swarms** library's `Conversation` object
5. Invokes the Director Agent from [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py) to coordinate the multi-agent pipeline (quant, risk, and execution agents)
6. Prints results in a styled Rich panel and appends successful prompts to [`recent_tasks.txt`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/recent_tasks.txt) via `_append_recent()`

## Using the REPL Effectively

After launching, you can interact with the hedge fund swarm using natural language prompts:

```text
> Analyze NVDA for 50k allocation

```

The system creates a fresh `AutoHedge` instance, processes your request through the director agent, and returns a formatted analysis panel.

Control the session using these commands:

- `help` or `?` – Redisplay the welcome tips and shortcuts
- `quit`, `exit`, or `q` – Terminate the REPL with a "Goodbye." message

Typical workflow example:

```bash

# Start the session

autohedge

# Execute a task

> Analyze AAPL for 100k allocation

# View help again

> help

# Exit cleanly

> quit

```

## Summary

- **Entry Point**: The CLI lives in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) and exposes three launch methods: the `autohedge` command, `python -m autohedge`, and help/version flags.
- **Environment**: [`autohedge/env_loader.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/env_loader.py) handles `.env` file discovery and API key validation, warning if `OPENAI_API_KEY` is absent.
- **Architecture**: The CLI is a thin wrapper that delegates to the `AutoHedge` class ([`autohedge/main.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/main.py)) and Director Agent ([`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py)) for actual processing.
- **Persistence**: Successful prompts are tracked in `~/.autohedge/recent_tasks.txt` and displayed in the welcome banner on startup.
- **Controls**: Use standard quit commands or the help shortcut to navigate the REPL.

## Frequently Asked Questions

### What happens if I don't have an OpenAI API key configured?

If `OPENAI_API_KEY` is missing when you launch `autohedge`, the CLI prints a yellow warning message (defined in lines 17-21 of [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py)) but continues to start the REPL. However, task execution will fail when the Director Agent attempts to call the LLM. Configure your key in a `.env` file or export it directly before launching.

### Can I run specific hedge fund tasks without entering the interactive REPL?

According to the current implementation in [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py), the CLI is designed specifically as an interactive REPL wrapper. There is no batch mode or single-command execution flag implemented in `_build_parser()`. You must enter the REPL and type your task at the `>` prompt to invoke the `AutoHedge` class.

### Where does AutoHedge store my recent task history?

The CLI maintains a history file at `~/.autohedge/recent_tasks.txt`. When you successfully submit a prompt, the `_append_recent()` function appends it to this file. On startup, `_get_recent_tasks()` reads this file to populate the welcome banner displayed via Rich panels, allowing you to see your previous hedge fund analyses immediately.

### How does the CLI handle different agent coordination?

While [`autohedge/cli.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/cli.py) manages the user interface, the heavy coordination happens in [`autohedge/main.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/main.py) and [`autohedge/workers.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/workers.py). The CLI instantiates the core `AutoHedge` class, which creates a `Conversation` object from the Swarms library and delegates to the Director Agent. This Director Agent then orchestrates the quant, risk, and execution agents to fulfill your hedge fund task.