OCaml client library for Claude Code
0
fork

Configure Feed

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

ocaml-claude: defer README MDX side effects via let run ()

The three usage examples opened with [let () = Eio_main.run ...] which
mdx happily executed at test time, spawning the Claude Code CLI and
hanging dune test for 90s. Wrapping each in [let run () = ...] keeps
the examples type-checked against the real API without invoking the
Eio mainloop, restoring sub-second runtime.

While here, switch [Printf.printf] / [print_string] to [Fmt.pr] to
match the monorepo convention.

+11 -10
+11 -10
README.md
··· 47 47 ```ocaml 48 48 open Claude 49 49 50 - let () = 50 + let run () = 51 51 Eio_main.run @@ fun env -> 52 52 Eio.Switch.run @@ fun sw -> 53 53 let process_mgr = Eio.Stdenv.process_mgr env in ··· 57 57 let responses = Client.receive_all client in 58 58 List.iter 59 59 (function 60 - | Response.Text t -> Printf.printf "Claude: %s\n" (Response.Text.content t) 60 + | Response.Text t -> Fmt.pr "Claude: %s@." (Response.Text.content t) 61 61 | _ -> ()) 62 62 responses 63 63 ``` ··· 67 67 ```ocaml 68 68 open Claude 69 69 70 - let () = 70 + let run () = 71 71 Eio_main.run @@ fun env -> 72 72 Eio.Switch.run @@ fun sw -> 73 73 let process_mgr = Eio.Stdenv.process_mgr env in ··· 76 76 Client.query client "Explain OCaml modules"; 77 77 Client.receive client 78 78 |> Seq.iter (function 79 - | Response.Text t -> print_string (Response.Text.content t) 79 + | Response.Text t -> Fmt.pr "%s" (Response.Text.content t) 80 80 | _ -> ()) 81 81 ``` 82 82 ··· 87 87 ```ocaml 88 88 open Claude 89 89 90 - let handler = object 91 - inherit Handler.default 92 - method! on_text t = print_string (Response.Text.content t) 93 - method! on_tool_use t = Fmt.pr "Tool: %s\n" (Response.Tool_use.name t) 94 - end 90 + let handler = 91 + object 92 + inherit Handler.default 93 + method! on_text t = Fmt.pr "%s" (Response.Text.content t) 94 + method! on_tool_use t = Fmt.pr "Tool: %s@." (Response.Tool_use.name t) 95 + end 95 96 96 - let () = 97 + let run () = 97 98 Eio_main.run @@ fun env -> 98 99 Eio.Switch.run @@ fun sw -> 99 100 let process_mgr = Eio.Stdenv.process_mgr env in