LemonCliRunners. ClaudeRunner
(lemon_cli_runners v0.1.0)
View Source
Claude CLI subprocess runner.
This module wraps the claude CLI tool (Claude Code), spawning it as a subprocess
and streaming its JSONL events. It enables using Claude as a subagent
with full session persistence and resumption support.
Usage
# Start a new Claude session
{:ok, pid} = ClaudeRunner.start_link(
prompt: "Create a new Elixir module that...",
cwd: "/path/to/project"
)
# Get the event stream
stream = ClaudeRunner.stream(pid)
# Process events
for event <- LemonAgent.EventStream.events(stream) do
case event do
{:cli_event, %StartedEvent{resume: token}} ->
IO.puts("Session started: #{token.value}")
{:cli_event, %ActionEvent{action: action, phase: :completed}} ->
IO.puts("Completed: #{action.title}")
{:cli_event, %CompletedEvent{ok: true, answer: answer}} ->
IO.puts("Done: #{answer}")
_ ->
:ok
end
endResuming Sessions
# Resume a previous session
token = %ResumeToken{engine: "claude", value: "session_abc123"}
{:ok, pid} = ClaudeRunner.start_link(
prompt: "Continue with the implementation",
resume: token,
cwd: "/path/to/project"
)Configuration
The runner uses the following command and sends the prompt on stdin:
claude -p --output-format stream-json --input-format text --verbose [--resume SESSION_ID]
Summary
Functions
Cancel a running runner
Run synchronously and return the final result
Start the runner
Get the event stream from a running runner