Agent
Provider-neutral coding agent. Each provider module exports a layer that
provides Agent:
import * as ClaudeAgent from "@jpowersdev/effect-agent/claude"program.pipe(Effect.provide(ClaudeAgent.layer()))A session is a scoped resource: closing its Scope stops the agent process.
Since v0.1.0
Constructors
Section titled “Constructors”refuseTool
Section titled “refuseTool”Refuse a tool call from Hooks.beforeTool, with the reason the model gets
as the tool’s result. An empty reason is replaced, as Codex needs one.
Signature
declare const refuseTool: (reason: string) => ToolRefusalSince v0.7.0
Guards
Section titled “Guards”isToolRefusal
Section titled “isToolRefusal”Whether a beforeTool result refuses the call.
Signature
declare const isToolRefusal: (u: unknown) => u is ToolRefusalSince v0.7.0
Models
Section titled “Models”AccountStatus
Section titled “AccountStatus”Sign-in and usage-limit status, from Agent.status.
Signature
declare const AccountStatus: Schema.Struct<{ readonly provider: Schema.String readonly usable: Schema.Boolean readonly reason: Schema.NullOr< Schema.Literals<readonly ["unauthenticated", "usage_limited", "spend_limited"]> > readonly windows: Schema.$Array< Schema.Struct<{ readonly window: Schema.Literals<readonly ["five_hour", "weekly", "other"]> readonly label: Schema.String readonly usedPercent: Schema.NullOr<Schema.Number> readonly resetsAt: Schema.NullOr<Schema.DateTimeUtcFromMillis> readonly model: Schema.OptionFromNullOr<Schema.String> }> > readonly plan: Schema.NullOr<Schema.String> readonly checkedAt: Schema.DateTimeUtcFromMillis}>Since v0.1.0
AccountStatus (type alias)
Section titled “AccountStatus (type alias)”Signature
type AccountStatus = typeof AccountStatus.TypeSince v0.1.0
BeforeToolResult (type alias)
Section titled “BeforeToolResult (type alias)”What Hooks.beforeTool returns: text to add to the model’s context (or
none), or a ToolRefusal.
Signature
type BeforeToolResult = Option.Option<string> | ToolRefusalSince v0.7.0
Capabilities
Section titled “Capabilities”What a provider supports, from Agent.capabilities.
Signature
declare const Capabilities: Schema.Struct<{ readonly provider: Schema.String readonly version: Schema.NullOr<Schema.String> readonly steer: Schema.Boolean readonly queue: Schema.Boolean readonly resume: Schema.Boolean readonly cost: Schema.Literals<readonly ["reported", "estimated", "none"]> readonly spendCap: Schema.Literals<readonly ["native", "estimated", "none"]> readonly resetTimes: Schema.Boolean readonly hooks: Schema.Boolean readonly refuseTool: Schema.optionalKey<Schema.Boolean> readonly reattach: Schema.Boolean readonly disable: Schema.Struct<{ readonly askUser: Schema.Boolean readonly subagents: Schema.Boolean readonly tools: Schema.Literals<readonly ["any", "some"]> }>}>Since v0.1.0
Capabilities (type alias)
Section titled “Capabilities (type alias)”Signature
type Capabilities = typeof Capabilities.TypeSince v0.1.0
Effort
Section titled “Effort”Reasoning effort for a turn.
Signature
declare const Effort: Schema.Literals< readonly ["minimal", "low", "medium", "high", "xhigh", "max"]>Since v0.1.0
Effort (type alias)
Section titled “Effort (type alias)”Signature
type Effort = typeof Effort.TypeSince v0.1.0
Hooks (interface)
Section titled “Hooks (interface)”Each hook may return text that is added to the model’s context. Hooks run inside the agent’s tool loop, so keep them fast; a failing hook adds nothing.
beforeTool may instead refuse the call (refuseTool): the tool doesn’t
run, and the model gets the reason as its result. A refusal holds with
permissions bypassed, as for mcp. It fails open: a hook that fails, times
out, or (on a detached session) has no client to answer it refuses nothing.
Where capabilities.refuseTool isn’t true, as on a host from an older
release, a refusal is only added to the model’s context, and the tool runs.
Signature
export interface Hooks { readonly beforeTool?: (call: ToolHookInput) => Effect.Effect<BeforeToolResult> readonly afterTool?: ( call: ToolHookInput & { readonly output: string; readonly isError: boolean }, ) => Effect.Effect<Option.Option<string>> /** * The agent is about to end its turn. Returning text keeps the turn going with that * text as context. */ readonly beforeStop?: () => Effect.Effect<Option.Option<string>>}Since v0.1.0
McpServer
Section titled “McpServer”An MCP server for RunSettings.mcpServers: Streamable HTTP, or a command
speaking MCP on stdio.
Signature
declare const McpServer: Schema.Union< readonly [ Schema.Struct<{ readonly type: Schema.Literal<"http"> readonly url: Schema.String readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>> }>, Schema.Struct<{ readonly type: Schema.Literal<"stdio"> readonly command: Schema.String readonly args: Schema.optionalKey<Schema.$Array<Schema.String>> readonly env: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>> }>, ]>Since v0.8.0
McpServer (type alias)
Section titled “McpServer (type alias)”Signature
type McpServer = typeof McpServer.TypeSince v0.8.0
RunOptions (interface)
Section titled “RunOptions (interface)”Options for Agent.open: RunSettings, plus hooks.
Signature
export interface RunOptions extends RunSettings { /** * Callbacks that can add context to the turn. Only where `capabilities.hooks` is * true. */ readonly hooks?: Hooks}Since v0.1.0
RunSettings
Section titled “RunSettings”Everything in RunOptions but hooks, as a Schema: plain data that can
be stored or sent to another process (DetachedAgent sends it to its host).
Durations encode as millis; an env value of undefined as null.
Signature
declare const RunSettings: Schema.Struct<{ readonly cwd: Schema.String readonly env: Schema.optionalKey< Schema.decodeTo< Schema.$Record<Schema.String, Schema.UndefinedOr<Schema.String>>, Schema.$Record<Schema.String, Schema.NullOr<Schema.String>>, never, never > > readonly model: Schema.optionalKey<Schema.String> readonly effort: Schema.optionalKey< Schema.Literals<readonly ["minimal", "low", "medium", "high", "xhigh", "max"]> > readonly appendSystemPrompt: Schema.optionalKey<Schema.String> readonly disable: Schema.optionalKey< Schema.Struct<{ readonly askUser: Schema.optionalKey<Schema.Boolean> readonly subagents: Schema.optionalKey<Schema.Boolean> readonly tools: Schema.optionalKey<Schema.$Array<Schema.String>> }> > readonly mcp: Schema.optionalKey< Schema.Struct<{ readonly allow: Schema.$Array<Schema.String> readonly deny: Schema.optionalKey<Schema.$Array<Schema.String>> }> > readonly mcpServers: Schema.optionalKey< Schema.$Record< Schema.String, Schema.Union< readonly [ Schema.Struct<{ readonly type: Schema.Literal<"http"> readonly url: Schema.String readonly headers: Schema.optionalKey< Schema.$Record<Schema.String, Schema.String> > }>, Schema.Struct<{ readonly type: Schema.Literal<"stdio"> readonly command: Schema.String readonly args: Schema.optionalKey<Schema.$Array<Schema.String>> readonly env: Schema.optionalKey< Schema.$Record<Schema.String, Schema.String> > }>, ] > > > readonly spendCapUsd: Schema.optionalKey<Schema.Number> readonly resume: Schema.optionalKey< Schema.brand<Schema.String, "effect-agent/SessionId"> > readonly watchdog: Schema.optionalKey< Schema.Struct<{ readonly idle: Schema.decodeTo< Schema.declare<Input, Input>, Schema.Union<readonly [Schema.String, Schema.Number]>, never, never > readonly toolIdle: Schema.optionalKey< Schema.decodeTo< Schema.declare<Input, Input>, Schema.Union<readonly [Schema.String, Schema.Number]>, never, never > > readonly grace: Schema.optionalKey< Schema.decodeTo< Schema.declare<Input, Input>, Schema.Union<readonly [Schema.String, Schema.Number]>, never, never > > }> >}>Since v0.2.0
RunSettings (type alias)
Section titled “RunSettings (type alias)”Signature
type RunSettings = typeof RunSettings.TypeSince v0.2.0
StatusOptions (interface)
Section titled “StatusOptions (interface)”Options for Agent.status.
Signature
export interface StatusOptions { /** * Applied over the host environment like `RunOptions.env`, e.g. to check * another account: `{ CLAUDE_CONFIG_DIR: "..." }` or `{ CODEX_HOME: "..." }`. */ readonly env?: Readonly<Record<string, string | undefined>>}Since v0.1.0
ToolHookInput (interface)
Section titled “ToolHookInput (interface)”The tool call passed to Hooks.beforeTool and Hooks.afterTool.
Signature
export interface ToolHookInput { readonly callId: string readonly name: string readonly input: unknown}Since v0.1.0
ToolRefusal (interface)
Section titled “ToolRefusal (interface)”What Hooks.beforeTool returns to stop a call: the tool doesn’t run, and the
model gets reason as its result. Make one with refuseTool.
Signature
export interface ToolRefusal { readonly _tag: "ToolRefusal" readonly reason: string}Since v0.7.0
Predicates
Section titled “Predicates”appliesTo
Section titled “appliesTo”Whether a limit window applies to model: windows without a model apply
to all; a per-model window applies when the model id contains its family
name (e.g. claude-fable-5-1 and fable).
Example
import { appliesTo } from "@jpowersdev/effect-agent"import { Option } from "effect"import assert from "node:assert"
const weeklyFable = { window: "weekly", label: "seven_day_fable", usedPercent: 100, resetsAt: null, model: Option.some("fable"),} as const
assert.strictEqual(appliesTo(weeklyFable, "claude-fable-5-1"), true)assert.strictEqual(appliesTo(weeklyFable, "claude-sonnet-5-5"), false)Signature
declare const appliesTo: (window: LimitWindowStatus, model: string) => booleanSince v0.1.0
usableFor
Section titled “usableFor”status.usable, and no exhausted per-model window caps model. A full
per-model window doesn’t make the whole account unusable (other models
still run), but it does stop a run on that model.
Signature
declare const usableFor: (status: AccountStatus, model: string) => booleanSince v0.1.0
Services
Section titled “Services”Agent (class)
Section titled “Agent (class)”The provider-neutral agent service; each provider module’s layer provides it.
Example
import { Agent } from "@jpowersdev/effect-agent"import { ClaudeAgent, ClaudeSdk } from "@jpowersdev/effect-agent/claude"import { Effect, Layer, Stream } from "effect"
const program = Effect.gen(function* () { const agent = yield* Agent const session = yield* agent.open({ cwd: process.cwd(), spendCapUsd: 5 }) // Subscribe before sending, so no event is missed const events = yield* session.subscribe yield* events.pipe(Stream.runForEach(Effect.logInfo), Effect.forkScoped) return yield* session.turn("Fix the failing test")}).pipe( // Closing the scope ends the session and stops the agent process Effect.scoped, Effect.provide(ClaudeAgent.layer().pipe(Layer.provide(ClaudeSdk.layer()))),)Signature
declare class AgentSince v0.1.0
settingsOf
Section titled “settingsOf”RunOptions without its hooks (functions can’t leave the process).
Signature
declare const settingsOf: ({ hooks: _, ...settings }: RunOptions) => RunSettingsSince v0.2.0