@langwatch/scenario
    Preparing search index...

    Class ClaudeCodeAgentAdapter

    Adapter that runs the Claude Code CLI as a Scenario agent.

    const adapter = new ClaudeCodeAgentAdapter({
    workingDirectory: "/tmp/project",
    model: "claude-sonnet-4-5",
    skipPermissions: true,
    });
    await scenario.run({
    agents: [adapter, scenario.userSimulatorAgent(), scenario.judgeAgent({ criteria: [...] })],
    script: [scenario.user("..."), scenario.agent(), scenario.judge()],
    });

    Hierarchy (View Summary)

    Index
    name: string = "ClaudeCodeAgent"
    role: AgentRole = AgentRole.AGENT
    • Process the conversation and return Claude Code's assistant text.

      A thread's first turn sends the FULL history and lets the CLI mint a session; later turns --resume it and send only the delta.

      This method owns ALL session-map policy — every read, write, and eviction of this.sessions happens here; runTurn is a pure one-spawn helper that mutates no instance state. A resume turn evicts its id ONLY when the failure is a genuinely stale session (isStaleSessionError); every other failure (auth, rate limit, unknown model, signal, timeout, or the client-side empty-delta guard that never even spawned) leaves the cached session untouched — the server session may well still be valid.

      On a stale session the behaviour is replayOnLostSession's to decide: by default the turn rejects; when opted in, the rebuild happens INSIDE this same turn. It cannot be deferred to "the next turn": ScenarioExecution rethrows whatever an adapter's call() throws, which aborts the run — so a rejected turn has no successor to rebuild on.

      Parameters

      • input: AgentInput

        Scenario agent input (conversation history etc.).

      Returns Promise<AgentReturnTypes>

      The concatenated assistant-visible text as a string.