Multi-turn session management.
Wraps repeated Query.execute/2 calls, automatically threading the
session_id returned by the CLI so each turn continues the same
conversation.
Usage
config = ClaudeWrapper.Config.new(working_dir: "/path/to/project")
session = ClaudeWrapper.Session.new(config)
{:ok, session, result} = ClaudeWrapper.Session.send(session, "What files are in this project?")
{:ok, session, result} = ClaudeWrapper.Session.send(session, "Now add tests for lib/foo.ex")
# Access history
ClaudeWrapper.Session.turns(session)
#=> [%Result{...}, %Result{...}]
# Resume a previous session
session = ClaudeWrapper.Session.resume(config, "session-id-abc")
Summary
Functions
Get the last result, if any.
Create a new session with the given config.
Resume an existing session by ID.
Send a message in the session. Returns the updated session and result.
Get the session ID (if established).
Send a message and return a stream of events.
Get the total cost across all turns.
Get the number of completed turns.
Get the conversation history (list of results).
Types
@type t() :: %ClaudeWrapper.Session{ config: ClaudeWrapper.Config.t(), history: [ClaudeWrapper.Result.t()], query_opts: keyword(), session_id: String.t() | nil }
Functions
@spec last_result(t()) :: ClaudeWrapper.Result.t() | nil
Get the last result, if any.
@spec new( ClaudeWrapper.Config.t(), keyword() ) :: t()
Create a new session with the given config.
Options
Any option accepted by ClaudeWrapper.query/2 (query-level options only):
:model- Model name:system_prompt- System prompt:max_turns- Max turns per send:permission_mode- Permission mode:max_budget_usd- Budget limit:effort- Effort level
@spec resume(ClaudeWrapper.Config.t(), String.t(), keyword()) :: t()
Resume an existing session by ID.
Send a message in the session. Returns the updated session and result.
The first turn creates a new session. Subsequent turns use --resume
with the session ID from the first result.
Get the session ID (if established).
@spec stream(t(), String.t(), keyword()) :: {t(), Enumerable.t()}
Send a message and return a stream of events.
Returns {session, stream}. The returned session is the same
session passed in -- this function does not thread session_id
across turns. If you need multi-turn continuity, use send/3
instead, which runs the turn synchronously and updates
session_id from the final result.
Use stream/3 when you want to observe events from a single turn
(for example, to render intermediate output as the CLI produces
it) and do not need to chain into a follow-up turn on the same
session.
Get the total cost across all turns.
@spec turn_count(t()) :: non_neg_integer()
Get the number of completed turns.
@spec turns(t()) :: [ClaudeWrapper.Result.t()]
Get the conversation history (list of results).