package dune-ai-context

  1. Overview
  2. Docs
Extract dune external dependencies and generate interface context for AI tools

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.2.tar.gz
md5=5d7e3ba2610083ec18c99874eb75984d
sha512=48a48712c428ac89ae44a8d6794803b357797662a830f96d3549c9819172f46608df6bfd7cfb16b95a3cd56f95f0d223acf6958caf422e5b159fdbf46438110a

Description

dune-ai-context parses external library dependencies using dune describe external-lib-deps, finds their .cmi files, and writes interface signatures for AI-assisted coding tools.

Tags

ocaml dune cmi interfaces ai

Published: 17 Mar 2026

README

dune‑ai‑context

dune‑ai‑context is a small OCaml command‑line tool that:

  • Parses the external library dependencies of an OCaml project by invoking dune describe external‑lib‑deps.
  • Filters out ppx_‑prefixed packages (they are usually build‑time helpers).
  • Looks for the compiled interface files (.cmi) of the remaining vendor libraries in the current OPAM switch ($OPAM_SWITCH_PREFIX/lib).
  • Collects the public API of all third‑party libraries and writes each interface to vendor_interfaces/<library>.mli. The generated vendor_interfaces directory can be added to a project's source tree and used as a context for AI‑assisted coding tools such as Claude Code, OpenCode, Aider, and similar assistants that can read local files to provide more accurate suggestions.

The tool is useful when you need to inspect or export the public API of the third‑party libraries used in a project, and when you want to give AI coding assistants full visibility of those APIs without requiring them to resolve external dependencies themselves.

Installation

The project depends on the following OPAM packages:

  • dune (≥ 3.1)
  • ocaml (≥ 4.14)
  • sexplib

You can install the tool directly from the repository:

git clone https://github.com/zenfey/dune-ai-context
cd dune-ai-context
opam pin add dune-ai-context .
opam install dune-ai-context

Building from source

If you prefer to build manually with dune:

dune build

The executable will be built as _build/default/bin/dune_ai_context.exe (and installed as dune-ai-context when you run dune install).

Usage

Assuming your OCaml project that uses Dune is located at <proj-root>:

  • Run the tool from the project root:
cd <proj-root>
dune-ai-context
  • Or invoke it with the project directory as an argument:
dune-ai-context <proj-root>

The command will create a vendor_interfaces directory inside the current working directory (or inside <proj-root> if you passed it as an argument) and populate it with <library>.mli files containing the exported signatures.

Environment variable

dune‑ai‑context relies on the OPAM_SWITCH_PREFIX environment variable to locate the compiled libraries. Ensure it is set (it is automatically set when you are inside an OPAM switch). If the variable is not present the tool will skip the .cmi lookup.

Testing

There are currently no inline tests. Run the tests with:

dune runtest

License

MIT – see the LICENSE file for details.

Contributing

Feel free to open issues or submit pull requests on the GitHub repository:

https://github.com/zenfey/dune-ai-context

Dependencies (3)

  1. sexplib
  2. dune >= "3.1"
  3. ocaml >= "4.14"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None