# How Open Interpreter Loop Mode and Loop Breakers Work: Complete Technical Guide

> Understand Open Interpreter's loop mode and loop breakers. Learn how it enables automatic multi-step conversations and how to control them.

- Repository: [Open Interpreter/open-interpreter](https://github.com/openinterpreter/open-interpreter)
- Tags: internals
- Published: 2026-03-05

---

**Open Interpreter's loop mode automatically continues multi-step conversations by re-injecting a system prompt after each assistant response until the model emits a specific phrase defined in `loop_breakers`.**

Open Interpreter supports an autonomous execution pattern that eliminates manual *"continue"* prompts during complex, multi-step tasks. This feature, implemented in the `openinterpreter/open-interpreter` repository, uses configurable break phrases to determine when a task sequence has completed naturally. Understanding how **loop mode** and **loop_breakers** function enables developers to build persistent automation workflows without requiring human intervention between each step.

## Core Configuration Components

The loop mechanism relies on three primary attributes initialized in [`interpreter/core/core.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/core/core.py) (lines 52-58):

- **`interpreter.loop`** — A boolean flag that enables the autonomous looping behavior.
- **`interpreter.loop_message`** — The system prompt string automatically appended as a user message to force continuation.
- **`interpreter.loop_breakers`** — A list of exact substring matches that, when detected in the assistant's response, halt the loop.

You can initialize these programmatically:

```python
from interpreter import interpreter

interpreter.loop = True
interpreter.loop_message = "Proceed. You can run code on my machine."
interpreter.loop_breakers = [
    "The task is done.",
    "The task is impossible.",
    "Let me know what you'd like to do next.",
    "Please provide more information."
]

```

## The Execution Flow in respond.py

The core logic resides in [`interpreter/core/respond.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/core/respond.py) within a `while True` loop (lines 21-55). After each assistant generation completes, the system evaluates whether to continue or break based on the following guard clause:

```python
if (
    interpreter.loop
    and interpreter.messages
    and interpreter.messages[-1].get("role") == "assistant"
    and not any(
        task_status in interpreter.messages[-1].get("content", "")
        for task_status in loop_breakers
    )
):
    # Cleanup and continue logic

    insert_loop_message = True
    continue

```

This check requires three conditions to trigger another loop iteration:

1. **Loop mode is active** (`interpreter.loop` is `True`).
2. **The last message is from the assistant**, ensuring the model has completed its turn.
3. **No break phrases are present** in the assistant's content (case-sensitive substring matching against `loop_breakers`).

### Message Cleanup and Injection

Before inserting a fresh loop prompt, the system performs housekeeping in [`respond.py`](https://github.com/openinterpreter/open-interpreter/blob/main/respond.py) (lines 30-49):

- Removes all previous instances of `loop_message` from the conversation history to prevent context bloat.
- Merges adjacent assistant messages to maintain proper conversation structure.

When `insert_loop_message` is set to `True`, the `loop_message` string is appended as a **user** message (lines 65-73), and the loop continues to the next LLM call. If the assistant's response contains any breaker phrase, the guard fails, the `break` statement executes, and `respond()` exits normally.

## CLI and Profile Configuration

For terminal users, enable loop mode without modifying code by using the `--loop` flag, processed in [`interpreter/terminal_interface/start_terminal_interface.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/terminal_interface/start_terminal_interface.py) (lines 154-157):

```bash
interpreter --loop

```

Production implementations often define these settings in profiles. The reference implementation appears in [`interpreter/terminal_interface/profiles/defaults/the01.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/terminal_interface/profiles/defaults/the01.py) (lines 35-44), which demonstrates a voice-assistant configuration with custom break phrases tailored for autonomous task completion.

## Practical Implementation Example

The following script demonstrates a complete workflow where the model autonomously executes multiple steps until explicitly signaling completion:

```python
from interpreter import interpreter

# Configure loop parameters

interpreter.loop = True
interpreter.loop_message = (
    "Proceed. You can run code on my machine. "
    "If you're finished, say exactly 'The task is done.'"
)
interpreter.loop_breakers = ["The task is done.", "The task is impossible."]

# Initiate multi-step autonomous execution

interpreter.chat(
    "Create a folder, write a Python script that lists the files, "
    "run it, and tell me the output."
)

```

During execution, Open Interpreter prints each assistant turn and automatically injects the loop prompt after every non-breaking reply. The conversation persists until the model outputs *"The task is done."* or another configured breaker phrase.

## Summary

- **Loop mode** enables autonomous multi-turn conversations by automatically re-prompting the LLM after each assistant response.
- **Loop breakers** are exact string patterns that terminate the automation when detected in assistant output.
- The mechanism is controlled via `interpreter.loop`, `interpreter.loop_message`, and `interpreter.loop_breakers` in [`core.py`](https://github.com/openinterpreter/open-interpreter/blob/main/core.py).
- Execution logic lives in [`respond.py`](https://github.com/openinterpreter/open-interpreter/blob/main/respond.py), which handles message cleanup, breaker detection, and prompt injection.
- Activation is available via Python API, CLI (`--loop` flag), or configuration profiles like [`the01.py`](https://github.com/openinterpreter/open-interpreter/blob/main/the01.py).

## Frequently Asked Questions

### What triggers the loop to stop in Open Interpreter?

The loop terminates when the assistant's response contains any string defined in the `interpreter.loop_breakers` list. According to the source code in [`respond.py`](https://github.com/openinterpreter/open-interpreter/blob/main/respond.py), the system performs a substring check using `any(task_status in content for task_status in loop_breakers)`, and if a match is found, the `while True` loop breaks naturally without injecting another `loop_message`.

### How do I enable loop mode from the command line?

Pass the `--loop` flag when starting Open Interpreter. This sets `interpreter.loop = True` during initialization in [`start_terminal_interface.py`](https://github.com/openinterpreter/open-interpreter/blob/main/start_terminal_interface.py) (lines 154-157). You can combine this with profile configurations to customize the break phrases without writing Python scripts.

### Can I customize the loop message and break phrases?

Yes. You can modify `interpreter.loop_message` to change the continuation prompt sent to the model, and redefine `interpreter.loop_breakers` as a list of strings specific to your use case. The default profile [`the01.py`](https://github.com/openinterpreter/open-interpreter/blob/main/the01.py) demonstrates this by using voice-assistant-appropriate breakers like *"Let me know what you'd like to do next."*

### Where is the loop logic implemented in the source code?

The primary implementation resides in two locations: [`interpreter/core/core.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/core/core.py) stores the configuration defaults and constructor parameters (lines 52-58), while [`interpreter/core/respond.py`](https://github.com/openinterpreter/open-interpreter/blob/main/interpreter/core/respond.py) contains the execution logic (lines 21-55) that evaluates break conditions, cleans up message history, and manages the `while True` conversation loop.