449 words, 3 min read

When working with tools like Dexter for Elixir code intelligence in VS Code, it's useful to have the Elixir standard library source checked out locally. Dexter uses it to provide go-to-definition and hover docs for stdlib modules.

The naive approach — cloning it once by hand — breaks down the moment you upgrade Elixir. You forget to re-clone, the path is wrong, and suddenly your editor is jumping to source that doesn't match what's actually running.

Here's a small shell script that automates it.

The script

#!/usr/bin/env bash
set -euo pipefail
version=$(elixir --version | grep -oE 'Elixir [0-9]+\.[0-9]+\.[0-9]+' | head -1 | awk '{print $2}')
if [[ -z "$version" ]]; then
echo "Error: could not determine Elixir version" >&2
exit 1
fi
branch="v${version}"
dest="$(cd "$(dirname "$0")" && pwd)/.elixir_stdlib"
echo "Elixir version: ${version}"
if [[ -d "$dest" ]]; then
if git -C "$dest" tag --points-at HEAD 2>/dev/null | grep -qx "$branch"; then
echo "${dest} already at ${branch}, skipping."
exit 0
fi
echo "Found ${dest} at a different version, removing for ${branch} ..."
rm -rf "$dest"
fi
echo "Cloning branch ${branch} into ${dest} ..."
git -c advice.detachedHead=false clone https://github.com/elixir-lang/elixir.git "$dest" --depth=1 --branch "$branch"

What it does

Detects the running Elixir version. It calls elixir --version and extracts the version number, so there's no hardcoded version to keep in sync manually.

Clones into .elixir_stdlib next to the script. Using dirname "$0" makes the destination relative to the script itself, so it works regardless of your current working directory.

Skips the clone if already up to date. Before doing anything destructive, it checks whether the target tag (v1.19.5, for example) is among the tags pointing at HEAD in the existing clone. This matters because the Elixir repo uses floating tags like v1.19-latest that point at the same commit — a naive git describe would return that tag instead, causing a false version mismatch every time.

Wipes and re-clones on version change. If the installed Elixir version doesn't match what's checked out, the old folder is removed and the correct version is cloned fresh.

Suppresses the detached HEAD warning. Cloning a tag always results in a detached HEAD, which git warns about by default. Passing -c advice.detachedHead=false silences that noise without hiding anything useful.

Usage

Drop the script in your project root, make it executable, add .elixir_stdlib to .gitignore, and point your editor at ${workspaceFolder}/.elixir_stdlib/lib.

chmod +x clone-elixir-src.sh
./clone-elixir-src.sh

Run it again whenever you upgrade Elixir — it'll figure out the rest.