# How the ai-memory Bootstrap Command Initializes a New Project with Existing Git History

> Learn how the ai-memory bootstrap command initializes new projects by ingesting Git history and files to seed your AI knowledge base. Get started with existing code.

- Repository: [Fabio Akita/ai-memory](https://github.com/akitaonrails/ai-memory)
- Tags: how-to-guide
- Published: 2026-08-20

---

**The ai-memory bootstrap command ingests a project's Git commit history, documentation, and source files to generate an initial wiki manifest that seeds the AI-memory knowledge base.**

The `ai-memory bootstrap` command in the akitaonrails/ai-memory repository transforms existing project artifacts into structured AI knowledge. When executed inside a Git repository, it automatically discovers the project root, collects historical commits and contextual files, and constructs a foundational [`bootstrap.md`](https://github.com/akitaonrails/ai-memory/blob/main/bootstrap.md) manifest through coordinated client-side collection and server-side LLM processing.

## Step 1: Repository Discovery and Source Collection

The initialization process begins by establishing the project context and gathering raw materials from the local filesystem.

### Auto-Discovering the Git Root

In [`crates/ai-memory-cli/src/commands/bootstrap.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-cli/src/commands/bootstrap.rs), the CLI first invokes `discover_repo_root` using libgit2 to locate the Git repository root (lines 45‑61). If detection succeeds, that directory becomes the source base; otherwise, the command falls back to the current working directory and automatically disables Git-commit collection.

### Extracting Commits and Documentation

Once rooted, the CLI calls `collect_sources` (lines 81‑88) to assemble a vector of `BootstrapSource` objects. According to [`crates/ai-memory-consolidate/src/bootstrap.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-consolidate/src/bootstrap.rs) (lines 11‑13), this includes:

- **Git commits** (when `include_git` is true), represented as `BootstrapSource` values of kind **GitCommit**
- **README files**, documentation, and Rust module headers

The `collect_sources` logic resides primarily in [`crates/ai-memory-consolidate/src/collect_sources.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-consolidate/src/collect_sources.rs), which walks the repository to extract these artifacts.

## Step 2: Client-Side Token Management and Transmission

Before transmitting data to the server, the CLI optimizes the payload to prevent rejection.

### Pruning to the Input Budget

To avoid HTTP 413 errors, `prune_sources_to_budget` (lines 90‑95) trims the source list to comply with the user-specified `max_input_tokens` limit. This client-side validation mirrors server-side constraints and ensures the request stays within LLM context windows.

### Transmission to the Admin Endpoint

The CLI serializes the workspace, project name, and pruned source list into JSON and POSTs to `POST /admin/bootstrap` (lines 32‑44). This endpoint is defined in [`crates/ai-memory-mcp/src/admin.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-mcp/src/admin.rs) and handled by the server-side consolidator.

## Step 3: Server-Side Knowledge Generation

Upon receiving the bundle, the server executes `ai_memory_consolidate::bootstrap::process_sources` to generate the knowledge base.

### Duplicate Manifest Detection

The server first checks for an existing `wiki/<workspace>/<project>/bootstrap.md` at lines 298‑303 in [`crates/ai-memory-consolidate/src/bootstrap.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-consolidate/src/bootstrap.rs). If the file exists and parses cleanly, the operation aborts unless the user provided the `--force` flag.

### LLM Chunk Processing

The `plan_bootstrap_chunks` function (lines 351‑357) splits the collected sources into LLM-sized segments. The configured LLM (OpenAI or Anthropic) then generates concise summaries for each chunk, transforming raw Git history and documentation into structured content.

### Creating the bootstrap.md Manifest

Finally, the system writes a [`bootstrap.md`](https://github.com/akitaonrails/ai-memory/blob/main/bootstrap.md) manifest via [`crates/ai-memory-wiki/src/wiki.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-wiki/src/wiki.rs), inserting YAML front-matter containing a `bootstrapped_at` timestamp and tags `["bootstrap","manifest"]` (lines 430‑436). This manifest links the generated summary pages, establishing the project's initial knowledge graph. The server returns a `BootstrapOutcome` listing pages written and token usage, which the CLI renders as a human-readable report (lines 45‑50).

## Implementation Reference: Key Source Files

- **[`crates/ai-memory-cli/src/commands/bootstrap.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-cli/src/commands/bootstrap.rs)** – CLI entry point; discovers repo, collects sources, sends POST.
- **[`crates/ai-memory-consolidate/src/bootstrap.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-consolidate/src/bootstrap.rs)** – Server-side bootstrap logic; creates [`bootstrap.md`](https://github.com/akitaonrails/ai-memory/blob/main/bootstrap.md), calls LLM.
- **[`crates/ai-memory-consolidate/src/collect_sources.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-consolidate/src/collect_sources.rs)** – Walks the repo, extracts Git commits and other sources.
- **[`crates/ai-memory-mcp/src/admin.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-mcp/src/admin.rs)** – HTTP handler for `POST /admin/bootstrap` that invokes the consolidator.
- **[`crates/ai-memory-wiki/src/wiki.rs`](https://github.com/akitaonrails/ai-memory/blob/main/crates/ai-memory-wiki/src/wiki.rs)** – Handles writing the generated wiki pages, including [`bootstrap.md`](https://github.com/akitaonrails/ai-memory/blob/main/bootstrap.md).

## Code Examples

```rust
// Example: Running bootstrap from a Git repository
let args = BootstrapArgs {
    repo_path: None,          // auto‑detect .git
    exclude_git: false,
    force: false,
    dry_run: false,
    ..Default::default()
};
ai_memory_cli::commands::bootstrap::run(&config, args).await?;

```

```bash

# Equivalent CLI invocation

AI_MEMORY_SERVER_URL=http://localhost:49374 \
AI_MEMORY_AUTH_TOKEN=... \
ai-memory bootstrap --chunk-input-tokens 2000 --max-input-tokens 150000

```

## Summary

- The **ai-memory bootstrap command** initializes projects by transforming Git history into structured wiki pages.
- **Repository discovery** relies on libgit2 via `discover_repo_root`, falling back to the current directory if no `.git` exists.
- **Source collection** gathers Git commits, READMEs, and Rust module headers as typed `BootstrapSource` objects.
- **Token pruning** happens client-side to enforce `max_input_tokens` before transmission.
- **Server-side processing** generates LLM summaries and writes a [`bootstrap.md`](https://github.com/akitaonrails/ai-memory/blob/main/bootstrap.md) manifest with metadata tags.
- The process is idempotent by default; use `--force` to overwrite existing manifests.

## Frequently Asked Questions

### What happens if the project already has a bootstrap manifest?

The server checks for an existing `wiki/<workspace>/<project>/bootstrap.md` before processing. If the file exists and parses cleanly, the bootstrap operation aborts unless you supply the `--force` flag to overwrite the previous bootstrap state.

### How does the command handle non-Git directories?

If `discover_repo_root` fails to find a Git repository, the CLI falls back to using the current working directory as the source base. In this mode, the tool disables Git-commit collection automatically, though it still processes other documentation files present in the directory.

### What sources are included beyond Git history?

In addition to Git commits (when `include_git` is enabled), `collect_sources` ingests README files, general documentation, and Rust module headers. Each source type is tagged accordingly in the `BootstrapSource` enum to ensure proper handling during the LLM summarization phase.

### How does the token budget affect the bootstrap process?

The `prune_sources_to_budget` function enforces the `max_input_tokens` limit client-side before transmission. This prevents HTTP 413 errors and ensures the payload fits within the LLM's context window, prioritizing recent or high-priority sources when trimming is required.