# `ClaudeAgentSDK.Mock`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L1)

Mock implementation for the Claude Code CLI for testing purposes.

This module provides a GenServer-based mock system that allows testing and development
without making actual API calls to the Claude service. It can be configured with
predefined responses for different prompt patterns.

## Features

- **Pattern-based responses**: Configure responses for specific prompt patterns
- **Default fallback**: Provides realistic default responses for unmatched prompts
- **Integration testing**: Seamlessly integrates with the main SDK for testing
- **Cost-free development**: Enables development without incurring API costs

## Usage

Start the mock server and configure responses:

    {:ok, _pid} = ClaudeAgentSDK.Mock.start_link()
    
    # Set up a specific response
    ClaudeAgentSDK.Mock.set_response("hello", [
      %{"type" => "system", "subtype" => "init", "session_id" => "mock-123"},
      %{"type" => "assistant", "message" => %{"content" => "Hello from mock!"}},
      %{"type" => "result", "subtype" => "success", "total_cost_usd" => 0.001}
    ])

Enable mocking in your application configuration:

    Application.put_env(:claude_agent_sdk, :use_mock, true)

## Response Format

Mock responses should follow the same format as the actual Claude CLI output:
- Each response is a list of message maps
- Each message has a "type" field (system, assistant, user, result)
- Messages may include optional "subtype" fields for categorization
- Result messages should include cost and timing information for realistic testing

## Testing Integration

The mock system is designed to work seamlessly with testing frameworks:

    test "queries return expected responses" do
      ClaudeAgentSDK.Mock.set_response("test prompt", expected_messages)
      
      result = ClaudeAgentSDK.query("test prompt", options)
      
      assert length(Enum.to_list(result)) == length(expected_messages)
    end

# `child_spec`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L54)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear_responses`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L84)

```elixir
@spec clear_responses() :: :ok
```

Clears all mock responses.

# `get_response`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L92)

```elixir
@spec get_response(String.t()) :: [map()]
```

Gets the response for a prompt.

# `set_default_response`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L100)

```elixir
@spec set_default_response([map()]) :: :ok
```

Sets the default response for any unmatched prompt.

# `set_response`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L76)

```elixir
@spec set_response(String.t(), [map()]) :: :ok
```

Sets a mock response for a given prompt pattern.

## Examples

    ClaudeAgentSDK.Mock.set_response("Hello", [
      %{type: "system", subtype: "init", session_id: "mock-123"},
      %{type: "assistant", message: %{"content" => "Hello from mock!"}},
      %{type: "result", subtype: "success", total_cost_usd: 0.001}
    ])

# `start_link`
[🔗](https://github.com/nshkrdotcom/claude_agent_sdk/blob/v0.9.2/lib/claude_agent_sdk/mock.ex#L60)

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the mock server.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
