CodeVetter
← All unpacks
CodeVetter · Repo Unpack evidence

ollama/ollama

Scanned commit 6383a0fa9c dated 2026-09-18 — last upstream commit. Generated by codevetter 1.12.0 on 2026-09-22.

github.com/ollama/ollama ↗ · 1232 files · 11.9 MB

Ollama Start building with open models. Download macOS shell curl -fsSL https://ollama.com/install.sh | sh or download manually Windows shell irm https://ollama.com/install.ps1 | iex or download manually Linux shell curl -fsSL https://ollama.com/install.sh | s

Deep analysis by swe-2 via the devin CLI on 2026-09-22 (runtime not recorded) — every claim below links to its cited source files.

Overview

Ollama is a Go-based local LLM runner that packages models as OCI-style content-addressed blobs plus manifests under ~/.ollama/models, serves them through a Gin HTTP API on 127.0.0.1:11434, and delegates actual inference to per-model subprocesses — upstream llama-server for GGUF models and a bundled `ollama runner` MLX subprocess for safetensors models on Apple silicon. The same binary provides the end-user CLI (cobra), a Bubbletea TUI, and a desktop app (macOS/Windows webview + React/Vite chat UI backed by a sqlite store). Distinctively, it emulates OpenAI and Anthropic REST surfaces on top of its native /api/* routes via middleware translators, supports remote 'cloud' models hosted on ollama.com, and renders/parses chat formats in Go through per-model-family renderer and parser registries.

System map

Single Go module (github.com/ollama/ollama) whose main binary is both the CLI client and the server. `ollama serve` starts a Gin HTTP server that owns a model Scheduler; inference is delegated to subprocesses (llama-server for GGUF, `ollama runner` for MLX/safetensors) spoken to over loopback HTTP. Model artifacts live as sha256 blobs + JSON manifests under OLLAMA_MODELS. Native code (vendored llama.cpp under llama/, MLX under mlx/) is built by CMake; the desktop app adds a webview shell and a React/Vite UI. Everything is configured through OLLAMA_* environment variables centralized in envconfig.

Feature catalog

User-facing surface = CLI subcommands + REST endpoints + OpenAI/Anthropic compat shims + a desktop chat app. Features cover the full model lifecycle (pull/create/push/copy/show/list/ps/delete), inference (generate/chat/embed with streaming NDJSON, thinking, tools, vision/audio, structured output, logprobs), cloud remote inference on ollama.com, experimental web search/fetch, and Codex Desktop integration via a loopback proxy.

All 13 feature catalog claims →

Data flow

Requests enter via Gin handlers -> model resolution (manifest -> Model struct) -> option merge (defaults < generation defaults < model < request) -> Scheduler -> runner subprocess over loopback HTTP -> streamed tokens parsed back into API responses. Model artifacts flow registry -> blob downloads -> manifest write; create flows Modelfile/safetensors dir -> layer blobs -> manifest. Chat text flows messages -> Go renderer or llama-server chat template -> prompt -> token stream -> Parser.Add splits content/thinking/tool calls -> NDJSON stream.

Behavior traces

Three canonical flows: (1) serve startup: main -> cobra serve -> initializeKeypair -> net.Listen -> server.Serve -> blob prune -> GenerateRoutes -> InitScheduler.Run; (2) `ollama run X prompt`: CLI heartbeat/pull -> api.Client.Chat -> ChatHandler -> GetModel -> getRunner -> load -> llama-server subprocess -> streamed parse -> NDJSON; (3) pull: PullHandler -> PullModel -> blob downloads -> manifest write. Safetensors models diverge at sched.load into the mlxrunner subprocess.

Testing signals

Testing is Go-test-first with heavy coverage in server/, model/parsers, model/renderers, middleware, mlxrunner, create, envconfig; testify is the assertion library. integration/ holds end-to-end suites gated on a live server/registry; CI runs go test -count=1 ./... plus a -race job, golangci-lint, patch-apply checks, vitest for the React app, and a benchmark pass.

Risk map

Main risks: the API has no request authentication by default and can be bound to non-loopback hosts via OLLAMA_HOST; the server spawns subprocesses (llama-server, self runner, gpu probes) with model-derived arguments; startup blob pruning deletes on-disk data; registry push/pull signs with a local private key; and several middleware paths decompress/transform untrusted request bodies. Scheduler and runner state is intricate (eviction, OOM retry, panic on model mismatch during load).

Extension points

Deliberate plug-in surfaces: per-model-family Parser and Renderer registries (name-keyed constructors with a switch fallback), embedded named chat templates, the llm.LlamaServer runner interface, cobra command table, launch.Default* UI hooks, middleware translators for new API dialects, envconfig's AsMap registry, and the create/ import pipeline stages.

Contributor handoff

Start with AGENTS.md and docs/development.md. Build Go-only via `go build .`/`go run . serve`; full builds need CMake (native payload under build/lib/ollama). Tests: `go test ./...` (race: `go test -race ./...`), vitest under app/ui/app, integration/ needs a live server. Read cmd/cmd.go, server/routes.go, server/sched.go, llm/llama_server.go first. Traps: dual runner paths (GGUF subprocess vs MLX self-runner), removed features that still error loudly, scheduler panics, and env-var-driven behavior.

Languages

LanguageFilesShare of source
Go77482%
TypeScript10411%
Markdown76docs/config
C465%
JSON32docs/config
Shell101%
YAML9docs/config
C++40%

Start reading here

Probable source entrypoint: cmd/bench — inferred from the directory tree and manifest, not the upstream docs.

Source roots

app/ (237 files)

Source layout — app/

PathFiles
app/auth/1
app/cmd/22
app/logrotate/2
app/tools/11
app/types/3
app/ui/139
app/webview/4
app/ollama.rc1

Repository structure

Top-level pathFiles
app/237
mlxrunner/141
template/104
model/102
cmd/96
mlx/88
docs/77
server/61

Docs found: AGENTS.mdCLAUDE.mdCONTRIBUTING.mdREADME.mddocs/README.mddocs/api.mddocs/development.mddocs/examples.mddocs/tools/extract-examples/README.md

Package

go.mod — github.com/ollama/ollama, 0 declared dependencies.

CI & config entrypoints

Structural health signals

Average score 6.4/10 across 96 analyzed source files; 48 hotspots surfaced.

These are deterministic review leads — size, churn, and structural signals — not proof of a bug in this project.

Recent history