OCaml client library for Claude Code
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-claude: enable MDX on lib/hooks.mli

Run mdx on lib/hooks.mli so the two {[ ... ]} odoc blocks now
type-check.

The first block referenced free `input` of unknown record type and
unqualified `Hooks.X` / `Tool_input.X`; annotated `(input :
Claude.Hooks.Pre_tool_use.input)` so field access resolves and
qualified all module paths to `Claude.Hooks.X` / `Claude.Tool_input.X`.

The second block (configure-hooks builder pattern) was a chained
expression with free `bash_handler` / `post_handler`; wrapped in
`let configure ~bash_handler ~post_handler = ...` so the example
takes the handlers as parameters.

Replaced the `String.contains` substring check with a length+sub
prefix check that reads as plausible production code.

+18 -20
+1 -1
lib/dune
··· 4 4 (libraries eio eio_main fmt logs nox-json)) 5 5 6 6 (mdx 7 - (files mcp_server.mli client.mli claude.mli) 7 + (files mcp_server.mli client.mli claude.mli hooks.mli) 8 8 (libraries claude nox-json logs fmt eio eio.core eio.unix eio_main))
+17 -19
lib/hooks.mli
··· 11 11 {1 Example Usage} 12 12 13 13 {[ 14 - open Eio.Std 14 + (* Block dangerous bash commands. *) 15 + let block_rm_rf (input : Claude.Hooks.Pre_tool_use.input) = 16 + if input.tool_name = "Bash" then 17 + match Claude.Tool_input.string input.tool_input "command" with 18 + | Some cmd 19 + when String.length cmd >= 5 20 + && String.sub cmd 0 5 = "rm -rf" -> 21 + Claude.Hooks.Pre_tool_use.deny ~reason:"Dangerous command" () 22 + | _ -> Claude.Hooks.Pre_tool_use.continue () 23 + else Claude.Hooks.Pre_tool_use.continue () 15 24 16 - (* Block dangerous bash commands *) 17 - let block_rm_rf input = 18 - if input.Hooks.Pre_tool_use.tool_name = "Bash" then 19 - match Tool_input.string input.tool_input "command" with 20 - | Some cmd when String.contains cmd "rm -rf" -> 21 - Hooks.Pre_tool_use.deny ~reason:"Dangerous command" () 22 - | _ -> Hooks.Pre_tool_use.continue () 23 - else Hooks.Pre_tool_use.continue () 24 - 25 - let hooks = 26 - Hooks.empty 27 - |> Hooks.on_pre_tool_use ~pattern:"Bash" block_rm_rf 28 - 29 - let options = Claude.Options.create ~hooks () in 30 - let client = Claude.Client.v ~options ~sw ~process_mgr () in 25 + let hooks = 26 + Claude.Hooks.empty 27 + |> Claude.Hooks.on_pre_tool_use ~pattern:"Bash" block_rm_rf 31 28 ]} *) 32 29 33 30 val src : Logs.Src.t ··· 203 200 204 201 Hooks are configured using a builder pattern: 205 202 {[ 206 - Hooks.empty 207 - |> Hooks.on_pre_tool_use ~pattern:"Bash" bash_handler 208 - |> Hooks.on_post_tool_use post_handler 203 + let configure ~bash_handler ~post_handler = 204 + Claude.Hooks.empty 205 + |> Claude.Hooks.on_pre_tool_use ~pattern:"Bash" bash_handler 206 + |> Claude.Hooks.on_post_tool_use post_handler 209 207 ]} *) 210 208 211 209 val pp : Format.formatter -> t -> unit