/ocaml-dev:ocamlfrom ocaml-dev
Provides OCaml development guidance covering module interface design (.mli files), error handling with result types, dune build system, and common libraries (eio, fmt, logs, cmdliner, yojson, cohttp-eio).
Ships in ocaml-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
.mli file first. A clean interface matters more than clever implementation.dune exclusivelydune fmt before committing (uses ocamlformat)eiofmtlogscmdlinerjsontcohttp-eioWrite ocamldoc in the voice of a POSIX manual page. Full sentences, no
extraneous detail, no colons or em dashes joining clauses, and nothing about
the implementation. Load the doc-style skill before writing or changing any
comment. It is the full standard and this section is only its summary.
Every .mli file starts with a synopsis, then a blank line, then the
description.
(** User accounts and profiles.
Users are workspace members. A user is identified by an {!type:id} that is
stable for the lifetime of the account. *)
Open with the function applied to its arguments, followed by is:
val is_bot : t -> bool
(** [is_bot u] is [true] if [u] is a bot user. *)
val find : id -> t -> user option
(** [find id t] is the user of [t] with identifier [id], or [None] if [t] has
no such user. *)
Reserve an active verb for functions that exist for their effect:
val flush : out_channel -> unit
(** [flush oc] writes the buffered bytes of [oc] to its underlying file. *)
For types, describe what the values represent, never their representation:
type id = string
(** The type for user identifiers. An identifier is unique within a workspace
and stable across renames. *)
Implementations carry no comments where the code says it already. Write one
only for a spec citation, a non-local invariant, a deliberate workaround, or a
justification for an unsafe operation. Documentation lives in the .mli, so
an .ml with an .mli has no (** ... *) comments at all.
For modules with a central type t, provide these functions where applicable:
| Function | Purpose |
|---|---|
val v : ... -> t | Pure smart constructor (no I/O) |
val create : ... -> (t, Error.t) result | Constructor with side-effects |
val pp : t Fmt.t | Pretty-printer for logging/debugging |
val equal : t -> t -> bool | Structural equality |
val compare : t -> t -> int | Comparison for sorting |
val of_json : Yojson.Safe.t -> (t, string) result | Parse from JSON |
val to_json : t -> Yojson.Safe.t | Serialize to JSON |
val validate : t -> (t, string) result | Validate data integrity |
Keep types abstract (type t) when possible. Expose smart constructors and accessors instead of record fields to maintain invariants.
Use result type for recoverable errors. Reserve exceptions for programming errors (e.g., Invalid_argument).
Define a comprehensive error type in lib/error.ml:
(* In lib/error.mli *)
type t = [
| `Api of string * Yojson.Safe.t
| `Json_parse of string
| `Network of string
| `Msg of string
]
val pp : t Fmt.t
let err_api code fields = Error (`Api (code, fields))
let err_parse msg = Error (`Json_parse msg)
let find_user_id json =
match Yojson.Safe.Util.find_opt "id" json with
| Some (`String id) -> Ok id
| Some _ -> err_parse "Expected string for user ID"
| None -> err_parse "Missing user ID"
try ... with _ -> .... Match specific exceptions.Fmt.failwith:let tls_config =
match Tls.Config.client ~authenticator () with
| Ok config -> config
| Error (`Msg msg) -> Fmt.failwith "Failed to create TLS config: %s" msg
match/if signals need for refactoring.bin/, lib/ui/).Use the logs library with per-module log sources:
let log_src = Logs.Src.create "project_name.module_name"
module Log = (val Logs.src_log log_src : Logs.LOG)
| Level | Use Case |
|---|---|
Log.app | Messages always shown to user (startup) |
Log.err | Handled but critical errors |
Log.warn | Potential issues, operation continues |
Log.info | Informational state messages |
Log.debug | Verbose debugging details |
Log.info (fun m ->
m "Received event: %s" event_type
~tags:(Logs.Tag.add "channel_id" channel_id Logs.Tag.empty))
| Element | Convention | Example |
|---|---|---|
| Files | lowercase_underscores | user_profile.ml |
| Modules | lowercase_underscores | user_profile |
| Primary type | t | type t |
| Identifiers | id | type id = string |
| Values | short_descriptive | find_user, create_channel |
Use labels only when they clarify meaning. Avoid ~f and ~x.
For bin/ applications using cmdliner:
bin/common.mlrun function that initializes the main loop and environment (e.g., Eio loop)Follow Conventional Commits:
Format: type(scope): subject
| Type | Purpose |
|---|---|
feat | New feature |
fix | Bug fix |
docs | Documentation |
style | Formatting |
refactor | Code restructuring |
test | Tests |
chore | Maintenance |
Examples:
feat(api): add support for file uploadsfix(ui): correct channel list rendering bugtest(user): add tests for user profile updatesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub avsm/ocaml-claude-marketplace --plugin ocaml-dev22 skills in this plugin
/cmdlinerDesigning and implementing robust command-line interfaces using OCaml's cmdliner library. Use when Claude needs to: (1) Design a new CLI or subcommand layout, (2) Implement cmdliner terms and combinators, (3) Enforce clear, predictable, orthogonal options, (4) Produce high-quality --help output and error messages, (5) Integrate cmdliner CLIs into dune-based OCaml projects./code-styleOCaml coding style and refactoring patterns. Use when the user asks to tidy, clean up, refactor, or improve OCaml code, reviewing code quality, enforcing naming conventions, or reducing complexity./doc-styleOCaml comment and ocamldoc writing style, in the voice of a POSIX manual page. Use whenever writing, rewording, reviewing or deleting any OCaml comment or documentation. Triggers on ocamldoc, odoc, doc comments, (** ... *), .mli documentation, .mld pages, documenting a function, type or module, and on any request to add, tidy, rewrite or strip OCaml comments.Other plugins' skills for the same job