Installation

Get AI4BayesCode running.

Two ways to use it. Drive it from a coding agent (install it as a skill, then describe your model in plain language), or install the R / Python package and call it from code. Install steps for each:

Recommended: generate your sampler in a coding agent, where generation is the most complete and runs through your Claude or Codex subscription. Then use the R or Python package to load and run the sampler it writes. The package can generate too, but it supports fewer models than the coding agent, and its generate() calls the model API directly, so it needs a real API key (for Anthropic, an sk-ant-api... key) billed per call. A subscription token from claude setup-token will not work there, since Anthropic no longer allows those on the direct API. So the package suits the occasional sampler, and the coding agent suits frequent generation on a subscription. Installing both gives the smoothest workflow.

AI4BayesCode runs through a coding agent, for example Claude Code, Cursor, or Codex. A chat-only LLM like ChatGPT can’t be used, because the agent needs to work with files on your computer and run code to validate the sampler it builds.

The repository root is the skill package. Install it once, reload, then launch it and describe your model.

Claude Code
# clone, then copy in (re-running overwrites any existing install)
git clone https://github.com/zjg540066169/AI4BayesCode.git
cd AI4BayesCode
mkdir -p ~/.claude/skills
rsync -a --delete --exclude '.git/' ./ ~/.claude/skills/AI4BayesCode/

Reload Claude Code, then type /AI4BayesCode.

Codex
# clone, then copy in (re-running overwrites any existing install)
git clone https://github.com/zjg540066169/AI4BayesCode.git
cd AI4BayesCode
mkdir -p ~/.codex/skills
rsync -a --delete --exclude '.git/' ./ ~/.codex/skills/AI4BayesCode/

Restart Codex, then type /Ai4bayescode (Codex lowercases the skill name, so only the first letter is capitalized).

Other coding agent
# clone the repo (no skills dir needed)
git clone https://github.com/zjg540066169/AI4BayesCode.git

# then tell your coding agent:
Read AI4BayesCode/start.md first,
then: <your model description>

No slash command needed. Cursor, Windsurf, Cline, aider, or any coding agent (one with local-file & code access) launches by reading start.md, which routes you to generate-vs-design and loads the rest on demand.

Also recommended: install the R or Python package too (the R / Python package tab). Then the sampler the agent writes finds the AI4BayesCode library on your computer on its own, and you won’t have to point it at any folder by hand.

After install, launch it. Use the slash command in Claude Code / Codex, or tell any other coding agent to "Read AI4BayesCode/start.md first". It first asks what you want to do: generate a sampler (compose existing blocks for your model) or design a new block (build a new sampling primitive). Choose generate a sampler, then describe your model in plain typeable text (spell Greek out: beta, sigma):

# Claude Code: /AI4BayesCode    ·    Codex: /Ai4bayescode
# Cursor / other coding agent: "Read AI4BayesCode/start.md first"
# then choose "generate a sampler", and describe the model:
y ~ N(Xbeta, sigma^2) with Jeffreys prior p(sigma^2) propto 1/sigma^2

The block-design flow is the other path, for building a new sampling primitive when no existing block fits. Pure-C++ users need only a C++17 compiler. The bundled include/ headers are the install.