# How to Start the code-graph-rag Daemon: CLI and Programmatic Guide

> Learn to start the code-graph-rag daemon using the CLI command cgr daemon up. Easily launch background Docker services like Memgraph and Qdrant on localhost.

- Repository: [Vitali Avagyan/code-graph-rag](https://github.com/vitali87/code-graph-rag)
- Tags: how-to-guide
- Published: 2026-09-05

---

**Run `cgr daemon up` to start the background Docker stack with Memgraph and Qdrant services bound to localhost.**

The code-graph-rag daemon powers the graph and vector-store backend services for the vitali87/code-graph-rag repository. Starting this daemon initializes the Dockerized Memgraph and Qdrant containers required for real-time code analysis and vector queries. Whether you use the CLI or Python API, the process ensures secure, local-only service binding and automated health verification.

## Prerequisites

Before you start the code-graph-rag daemon, ensure Docker is installed and the Docker daemon is running on your system. The `cgr` CLI tool must be installed and available in your PATH.

## Starting the Daemon with the CLI

### The `cgr daemon up` Command

The fastest way to start the code-graph-rag daemon is through the `cgr` CLI. When you execute the daemon subcommand, the top-level CLI defined in [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) routes the request to the dedicated daemon command handler around lines 1054-1055.

```bash

# Start the daemon (creates/starts the Docker stack)

cgr daemon up

```

This single command triggers the full initialization sequence, rendering the Docker Compose configuration if missing and starting the containerized services.

## How the Daemon Initialization Works

Understanding the startup flow helps troubleshoot connection issues and customize deployments.

### Step 1: CLI Routing

In [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py), the CLI entry point forwards any `daemon …` subcommand to the daemon management module. This architecture separates concerns between the main application logic and infrastructure management.

### Step 2: Stack Manager Invocation

The `cgr daemon up` command invokes the `daemon_up` function located in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py) (lines 42-46). This function serves as the primary orchestrator for the Docker stack lifecycle.

```python

# Programmatic start (if embedding in another script)

from codebase_rag.stack.manager import daemon_up, daemon_status

# Bring the stack up

status = daemon_up()
print(f"Daemon started – Memgraph at {status.memgraph_endpoint}")

```

### Step 3: Docker-Compose Orchestration

The `daemon_up` function instantiates a `StackManager` class and calls `StackManager.up()`. This method renders the Docker Compose file at `~/.cgr/docker-compose.yaml` if it does not exist, then launches the Memgraph and Qdrant containers. According to the architecture documentation in [`docs/architecture/security.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/architecture/security.md), the stack binds all ports to `127.0.0.1` to prevent external network exposure.

### Step 4: Health Check Verification

After container startup, `StackManager.wait_healthy()` polls the services until they report ready status. The function returns a `StackStatus` object (defined in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py), lines 8-15) containing the reachable endpoints:

- Memgraph: `127.0.0.1:7687`
- Qdrant: `127.0.0.1:6333`

## Verifying the Daemon Status

Once started, confirm the daemon is running and inspect endpoint availability:

```bash

# Verify the daemon is running and see endpoints

cgr daemon status

# Example output:

#   State: RUNNING

#   Memgraph: 127.0.0.1:7687

#   Qdrant:   127.0.0.1:6333

```

For programmatic verification, use the `daemon_status` function:

```python

# Check health later

current = daemon_status()
print(f"Current state: {current.state}")

```

## Summary

- The `cgr daemon up` command triggers the complete startup sequence for the code-graph-rag daemon.
- CLI commands route through [`codebase_rag/cli.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/cli.py) to the `daemon_up` function in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py).
- The `StackManager` class renders `~/.cgr/docker-compose.yaml` and orchestrates Docker containers for Memgraph and Qdrant.
- Services bind exclusively to `127.0.0.1` for security, exposing ports 7687 (Memgraph) and 6333 (Qdrant).
- Health verification occurs automatically before the command returns, ensuring services are queryable immediately.

## Frequently Asked Questions

### What services does the code-graph-rag daemon start?

The daemon starts two containerized services: Memgraph (graph database on port 7687) and Qdrant (vector store on port 6333). These services power the graph-based code analysis and semantic search capabilities of the tool.

### Where is the Docker Compose configuration stored?

The Docker Compose file is automatically generated at `~/.cgr/docker-compose.yaml` on first run. The `StackManager.up()` method in [`codebase_rag/stack/manager.py`](https://github.com/vitali87/code-graph-rag/blob/main/codebase_rag/stack/manager.py) renders this file if it is missing before starting the containers.

### How do I check if the daemon is running?

Run `cgr daemon status` in your terminal or call `daemon_status()` from the `codebase_rag.stack.manager` module. Both methods return a `StackStatus` object indicating whether the state is RUNNING and displaying the current endpoints for Memgraph and Qdrant.

### Is the daemon accessible from remote machines?

No. As implemented in the vitali87/code-graph-rag repository, the Docker stack binds all service ports to `127.0.0.1` (localhost) only. This security constraint, documented in [`docs/architecture/security.md`](https://github.com/vitali87/code-graph-rag/blob/main/docs/architecture/security.md), prevents unauthorized remote access to the graph and vector databases.