claude-code-controller 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ interface InboxMessage {
8
8
  read: boolean;
9
9
  summary?: string;
10
10
  }
11
- type StructuredMessage = TaskAssignmentMessage | ShutdownRequestMessage | ShutdownApprovedMessage | IdleNotificationMessage | PlanApprovalRequestMessage | PlanApprovalResponseMessage | PermissionRequestMessage | PermissionResponseMessage | PlainTextMessage;
11
+ type StructuredMessage = TaskAssignmentMessage | TaskCompletedMessage | ShutdownRequestMessage | ShutdownApprovedMessage | IdleNotificationMessage | PlanApprovalRequestMessage | PlanApprovalResponseMessage | PermissionRequestMessage | PermissionResponseMessage | SandboxPermissionRequestMessage | SandboxPermissionResponseMessage | PlainTextMessage;
12
12
  interface TaskAssignmentMessage {
13
13
  type: "task_assignment";
14
14
  taskId: string;
@@ -37,6 +37,10 @@ interface IdleNotificationMessage {
37
37
  from: string;
38
38
  timestamp: string;
39
39
  idleReason: string;
40
+ summary?: string;
41
+ completedTaskId?: string;
42
+ completedStatus?: string;
43
+ failureReason?: string;
40
44
  }
41
45
  interface PlanApprovalRequestMessage {
42
46
  type: "plan_approval_request";
@@ -71,6 +75,29 @@ interface PermissionResponseMessage {
71
75
  approved: boolean;
72
76
  timestamp: string;
73
77
  }
78
+ interface TaskCompletedMessage {
79
+ type: "task_completed";
80
+ from: string;
81
+ taskId: string;
82
+ taskSubject: string;
83
+ timestamp: string;
84
+ }
85
+ interface SandboxPermissionRequestMessage {
86
+ type: "sandbox_permission_request";
87
+ requestId: string;
88
+ workerId: string;
89
+ workerName: string;
90
+ workerColor?: string;
91
+ hostPattern: string;
92
+ timestamp: string;
93
+ }
94
+ interface SandboxPermissionResponseMessage {
95
+ type: "sandbox_permission_response";
96
+ requestId: string;
97
+ host: string;
98
+ allow: boolean;
99
+ timestamp: string;
100
+ }
74
101
  interface PlainTextMessage {
75
102
  type: "plain_text";
76
103
  text: string;
@@ -88,10 +115,14 @@ interface TeamMember {
88
115
  name: string;
89
116
  agentType: string;
90
117
  model?: string;
118
+ prompt?: string;
119
+ color?: string;
120
+ planModeRequired?: boolean;
91
121
  joinedAt: number;
92
122
  tmuxPaneId?: string;
93
123
  cwd: string;
94
124
  subscriptions?: string[];
125
+ backendType?: string;
95
126
  }
96
127
  interface TaskFile {
97
128
  id: string;
@@ -105,7 +136,7 @@ interface TaskFile {
105
136
  metadata?: Record<string, unknown>;
106
137
  }
107
138
  type TaskStatus = "pending" | "in_progress" | "completed";
108
- type AgentType = "general-purpose" | "Bash" | "Explore" | "Plan" | string;
139
+ type AgentType = "general-purpose" | "Bash" | "Explore" | "Plan" | "claude-code-guide" | "statusline-setup" | string;
109
140
  type PermissionMode = "default" | "acceptEdits" | "bypassPermissions" | "plan" | "dontAsk" | "delegate";
110
141
  interface SpawnAgentOptions {
111
142
  name: string;
@@ -134,7 +165,7 @@ interface ReceiveOptions {
134
165
  }
135
166
  interface ControllerEvents {
136
167
  message: [agentName: string, message: InboxMessage];
137
- idle: [agentName: string];
168
+ idle: [agentName: string, details: IdleNotificationMessage];
138
169
  "shutdown:approved": [agentName: string, message: ShutdownApprovedMessage];
139
170
  "plan:approval_request": [agentName: string, message: PlanApprovalRequestMessage];
140
171
  "permission:request": [agentName: string, message: PermissionRequestMessage];
@@ -396,4 +427,240 @@ declare class ClaudeCodeController extends EventEmitter<ControllerEvents> implem
396
427
  private ensureInitialized;
397
428
  }
398
429
 
399
- export { AgentHandle as A, ClaudeCodeController as C, type InboxMessage as I, type Logger as L, type PermissionMode as P, type ReceiveOptions as R, type StructuredMessage as S, type TaskAssignmentMessage as T, type LogLevel as a, type AgentType as b, type ControllerEvents as c, type ControllerOptions as d, type IdleNotificationMessage as e, type PermissionRequestMessage as f, type PermissionResponseMessage as g, type PlainTextMessage as h, type PlanApprovalRequestMessage as i, type PlanApprovalResponseMessage as j, type ShutdownApprovedMessage as k, type ShutdownRequestMessage as l, type SpawnAgentOptions as m, type TaskFile as n, TaskManager as o, type TaskStatus as p, type TeamConfig as q, TeamManager as r, type TeamMember as s };
430
+ type PermissionPreset = "full" | "edit" | "plan" | "ask";
431
+ interface ClaudeOptions {
432
+ /** Model to use: "sonnet" | "opus" | "haiku" | full model ID */
433
+ model?: "sonnet" | "opus" | "haiku" | (string & {});
434
+ /** Anthropic API key. Maps to ANTHROPIC_AUTH_TOKEN env var. */
435
+ apiKey?: string;
436
+ /** API base URL. Maps to ANTHROPIC_BASE_URL env var. */
437
+ baseUrl?: string;
438
+ /** Request timeout in ms. Maps to API_TIMEOUT_MS env var. */
439
+ timeout?: number;
440
+ /** Working directory for the agent. Defaults to process.cwd(). */
441
+ cwd?: string;
442
+ /**
443
+ * Permission level:
444
+ * - "full" (default) — all tools, no approval needed
445
+ * - "edit" — auto-approve read/write/bash
446
+ * - "plan" — read-only exploration
447
+ * - "ask" — fires permission events for each tool use
448
+ */
449
+ permissions?: PermissionPreset;
450
+ /**
451
+ * Auto-approve permission and plan requests.
452
+ * - `true` — approve everything automatically
453
+ * - `string[]` — only auto-approve these tool names, reject the rest
454
+ *
455
+ * Only meaningful with `permissions: "ask"`. Ignored when "full" or "edit".
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * // Approve everything
460
+ * await claude.agent({ permissions: "ask", autoApprove: true });
461
+ *
462
+ * // Only approve safe tools
463
+ * await claude.agent({ permissions: "ask", autoApprove: ["Read", "Glob", "Grep"] });
464
+ * ```
465
+ */
466
+ autoApprove?: boolean | string[];
467
+ /**
468
+ * Inline callback for permission requests.
469
+ * Called when the agent wants to use a tool.
470
+ * Provides `req.approve()` / `req.reject()` methods.
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * await claude.agent({
475
+ * permissions: "ask",
476
+ * onPermission: (req) => {
477
+ * req.toolName === "Bash" ? req.reject() : req.approve();
478
+ * },
479
+ * });
480
+ * ```
481
+ */
482
+ onPermission?: (request: PermissionRequestInfo) => void;
483
+ /**
484
+ * Inline callback for plan approval requests.
485
+ * Called when the agent submits a plan for review.
486
+ *
487
+ * @example
488
+ * ```ts
489
+ * await claude.agent({
490
+ * onPlan: (req) => {
491
+ * console.log(req.planContent);
492
+ * req.approve();
493
+ * },
494
+ * });
495
+ * ```
496
+ */
497
+ onPlan?: (request: PlanRequestInfo) => void;
498
+ /** Additional environment variables (escape hatch). */
499
+ env?: Record<string, string>;
500
+ /** Log level. Defaults to "warn" for the simplified API. */
501
+ logLevel?: LogLevel;
502
+ /** Custom logger instance. */
503
+ logger?: Logger;
504
+ /** Agent name. Auto-generated if omitted. */
505
+ name?: string;
506
+ /** Agent type. Defaults to "general-purpose". */
507
+ type?: AgentType;
508
+ /** Path to the claude binary. */
509
+ claudeBinary?: string;
510
+ /** Max time in ms to wait for agent to become ready. Default: 60_000. */
511
+ readyTimeout?: number;
512
+ }
513
+ interface AskOptions {
514
+ /** Response timeout in ms. Default: 120_000. */
515
+ timeout?: number;
516
+ /** Poll interval in ms. Default: 500. */
517
+ pollInterval?: number;
518
+ }
519
+ interface SessionOptions extends ClaudeOptions {
520
+ /** Team name. Auto-generated if omitted. */
521
+ teamName?: string;
522
+ }
523
+ interface SessionAgentOptions {
524
+ /** Model override for this agent. */
525
+ model?: string;
526
+ /** Working directory override. */
527
+ cwd?: string;
528
+ /** Agent type override. */
529
+ type?: AgentType;
530
+ /** Permission preset override. */
531
+ permissions?: PermissionPreset;
532
+ /** Auto-approve permission/plan requests. See ClaudeOptions.autoApprove. */
533
+ autoApprove?: boolean | string[];
534
+ /** Inline permission callback. See ClaudeOptions.onPermission. */
535
+ onPermission?: (request: PermissionRequestInfo) => void;
536
+ /** Inline plan callback. See ClaudeOptions.onPlan. */
537
+ onPlan?: (request: PlanRequestInfo) => void;
538
+ /** Per-agent env overrides. */
539
+ env?: Record<string, string>;
540
+ /** Max time in ms to wait for agent to become ready. Default: 60_000. */
541
+ readyTimeout?: number;
542
+ }
543
+ interface PermissionRequestInfo {
544
+ requestId: string;
545
+ toolName: string;
546
+ description: string;
547
+ input?: unknown;
548
+ approve(): Promise<void>;
549
+ reject(): Promise<void>;
550
+ }
551
+ interface PlanRequestInfo {
552
+ requestId: string;
553
+ planContent?: string;
554
+ approve(feedback?: string): Promise<void>;
555
+ reject(feedback: string): Promise<void>;
556
+ }
557
+ interface AgentEvents {
558
+ message: [text: string];
559
+ idle: [];
560
+ permission: [request: PermissionRequestInfo];
561
+ plan: [request: PlanRequestInfo];
562
+ exit: [code: number | null];
563
+ error: [error: Error];
564
+ }
565
+ declare class Agent extends EventEmitter<AgentEvents> {
566
+ private controller;
567
+ private handle;
568
+ private ownsController;
569
+ private disposed;
570
+ private boundListeners;
571
+ private constructor();
572
+ /** Create a standalone agent (owns its own controller). */
573
+ static create(opts?: ClaudeOptions): Promise<Agent>;
574
+ /** Create an agent within an existing session (session owns the controller). */
575
+ static createInSession(controller: ClaudeCodeController, name: string, opts?: SessionAgentOptions): Promise<Agent>;
576
+ /** The agent's name. */
577
+ get name(): string;
578
+ /** The agent process PID. */
579
+ get pid(): number | undefined;
580
+ /** Whether the agent process is still running. */
581
+ get isRunning(): boolean;
582
+ /**
583
+ * Send a message and wait for the response.
584
+ *
585
+ * Uses event-based waiting (via the controller's InboxPoller) instead of
586
+ * polling `readUnread()` directly, which avoids a race condition where the
587
+ * poller marks inbox messages as read before `receive()` can see them.
588
+ */
589
+ ask(question: string, opts?: AskOptions): Promise<string>;
590
+ /** Send a message without waiting for a response. */
591
+ send(message: string): Promise<void>;
592
+ /** Wait for the next response from this agent. */
593
+ receive(opts?: AskOptions): Promise<string>;
594
+ /**
595
+ * Close this agent. If standalone, shuts down the entire controller.
596
+ * If session-owned, kills only this agent's process.
597
+ */
598
+ close(): Promise<void>;
599
+ /** Mark as disposed (used by Session when it closes). */
600
+ markDisposed(): void;
601
+ [Symbol.asyncDispose](): Promise<void>;
602
+ private wireEvents;
603
+ private unwireEvents;
604
+ private wireBehavior;
605
+ private ensureNotDisposed;
606
+ }
607
+ declare class Session {
608
+ readonly controller: ClaudeCodeController;
609
+ private defaults;
610
+ private agents;
611
+ private disposed;
612
+ private constructor();
613
+ static create(opts?: SessionOptions): Promise<Session>;
614
+ /** Spawn a named agent in this session. Inherits session defaults. */
615
+ agent(name: string, opts?: SessionAgentOptions): Promise<Agent>;
616
+ /** Get an existing agent by name. */
617
+ get(name: string): Agent | undefined;
618
+ /** Close all agents and shut down the session. */
619
+ close(): Promise<void>;
620
+ [Symbol.asyncDispose](): Promise<void>;
621
+ private ensureNotDisposed;
622
+ }
623
+ /**
624
+ * One-liner: send a prompt, get a response.
625
+ * Creates an ephemeral agent, sends the message, returns the answer, cleans up.
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const answer = await claude("What does this project do?", { model: "sonnet" });
630
+ * ```
631
+ */
632
+ declare function claudeCall(prompt: string, opts?: ClaudeOptions): Promise<string>;
633
+ /**
634
+ * The simplified Claude Code API.
635
+ *
636
+ * - `claude(prompt, opts?)` — one-liner: ask a question, get an answer
637
+ * - `claude.agent(opts?)` — create a persistent agent for multi-turn conversations
638
+ * - `claude.session(opts?)` — create a multi-agent session
639
+ */
640
+ declare const claude: typeof claudeCall & {
641
+ /**
642
+ * Create a persistent agent for multi-turn conversations.
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * const agent = await claude.agent({ model: "sonnet" });
647
+ * const answer = await agent.ask("What is 2+2?");
648
+ * await agent.close();
649
+ * ```
650
+ */
651
+ agent: (opts?: ClaudeOptions) => Promise<Agent>;
652
+ /**
653
+ * Create a multi-agent session.
654
+ *
655
+ * @example
656
+ * ```ts
657
+ * const session = await claude.session({ model: "sonnet" });
658
+ * const reviewer = await session.agent("reviewer", { model: "opus" });
659
+ * const coder = await session.agent("coder");
660
+ * await session.close();
661
+ * ```
662
+ */
663
+ session: (opts?: SessionOptions) => Promise<Session>;
664
+ };
665
+
666
+ export { Agent as A, type TaskFile as B, ClaudeCodeController as C, TaskManager as D, type TaskStatus as E, type TeamConfig as F, TeamManager as G, type TeamMember as H, type InboxMessage as I, claude as J, type Logger as L, type PermissionMode as P, type ReceiveOptions as R, type StructuredMessage as S, type TaskAssignmentMessage as T, type LogLevel as a, type AgentEvents as b, AgentHandle as c, type AgentType as d, type AskOptions as e, type ClaudeOptions as f, type ControllerEvents as g, type ControllerOptions as h, type IdleNotificationMessage as i, type PermissionPreset as j, type PermissionRequestInfo as k, type PermissionRequestMessage as l, type PermissionResponseMessage as m, type PlainTextMessage as n, type PlanApprovalRequestMessage as o, type PlanApprovalResponseMessage as p, type PlanRequestInfo as q, type SandboxPermissionRequestMessage as r, type SandboxPermissionResponseMessage as s, Session as t, type SessionAgentOptions as u, type SessionOptions as v, type ShutdownApprovedMessage as w, type ShutdownRequestMessage as x, type SpawnAgentOptions as y, type TaskCompletedMessage as z };
@@ -8,7 +8,7 @@ interface InboxMessage {
8
8
  read: boolean;
9
9
  summary?: string;
10
10
  }
11
- type StructuredMessage = TaskAssignmentMessage | ShutdownRequestMessage | ShutdownApprovedMessage | IdleNotificationMessage | PlanApprovalRequestMessage | PlanApprovalResponseMessage | PermissionRequestMessage | PermissionResponseMessage | PlainTextMessage;
11
+ type StructuredMessage = TaskAssignmentMessage | TaskCompletedMessage | ShutdownRequestMessage | ShutdownApprovedMessage | IdleNotificationMessage | PlanApprovalRequestMessage | PlanApprovalResponseMessage | PermissionRequestMessage | PermissionResponseMessage | SandboxPermissionRequestMessage | SandboxPermissionResponseMessage | PlainTextMessage;
12
12
  interface TaskAssignmentMessage {
13
13
  type: "task_assignment";
14
14
  taskId: string;
@@ -37,6 +37,10 @@ interface IdleNotificationMessage {
37
37
  from: string;
38
38
  timestamp: string;
39
39
  idleReason: string;
40
+ summary?: string;
41
+ completedTaskId?: string;
42
+ completedStatus?: string;
43
+ failureReason?: string;
40
44
  }
41
45
  interface PlanApprovalRequestMessage {
42
46
  type: "plan_approval_request";
@@ -71,6 +75,29 @@ interface PermissionResponseMessage {
71
75
  approved: boolean;
72
76
  timestamp: string;
73
77
  }
78
+ interface TaskCompletedMessage {
79
+ type: "task_completed";
80
+ from: string;
81
+ taskId: string;
82
+ taskSubject: string;
83
+ timestamp: string;
84
+ }
85
+ interface SandboxPermissionRequestMessage {
86
+ type: "sandbox_permission_request";
87
+ requestId: string;
88
+ workerId: string;
89
+ workerName: string;
90
+ workerColor?: string;
91
+ hostPattern: string;
92
+ timestamp: string;
93
+ }
94
+ interface SandboxPermissionResponseMessage {
95
+ type: "sandbox_permission_response";
96
+ requestId: string;
97
+ host: string;
98
+ allow: boolean;
99
+ timestamp: string;
100
+ }
74
101
  interface PlainTextMessage {
75
102
  type: "plain_text";
76
103
  text: string;
@@ -88,10 +115,14 @@ interface TeamMember {
88
115
  name: string;
89
116
  agentType: string;
90
117
  model?: string;
118
+ prompt?: string;
119
+ color?: string;
120
+ planModeRequired?: boolean;
91
121
  joinedAt: number;
92
122
  tmuxPaneId?: string;
93
123
  cwd: string;
94
124
  subscriptions?: string[];
125
+ backendType?: string;
95
126
  }
96
127
  interface TaskFile {
97
128
  id: string;
@@ -105,7 +136,7 @@ interface TaskFile {
105
136
  metadata?: Record<string, unknown>;
106
137
  }
107
138
  type TaskStatus = "pending" | "in_progress" | "completed";
108
- type AgentType = "general-purpose" | "Bash" | "Explore" | "Plan" | string;
139
+ type AgentType = "general-purpose" | "Bash" | "Explore" | "Plan" | "claude-code-guide" | "statusline-setup" | string;
109
140
  type PermissionMode = "default" | "acceptEdits" | "bypassPermissions" | "plan" | "dontAsk" | "delegate";
110
141
  interface SpawnAgentOptions {
111
142
  name: string;
@@ -134,7 +165,7 @@ interface ReceiveOptions {
134
165
  }
135
166
  interface ControllerEvents {
136
167
  message: [agentName: string, message: InboxMessage];
137
- idle: [agentName: string];
168
+ idle: [agentName: string, details: IdleNotificationMessage];
138
169
  "shutdown:approved": [agentName: string, message: ShutdownApprovedMessage];
139
170
  "plan:approval_request": [agentName: string, message: PlanApprovalRequestMessage];
140
171
  "permission:request": [agentName: string, message: PermissionRequestMessage];
@@ -396,4 +427,240 @@ declare class ClaudeCodeController extends EventEmitter<ControllerEvents> implem
396
427
  private ensureInitialized;
397
428
  }
398
429
 
399
- export { AgentHandle as A, ClaudeCodeController as C, type InboxMessage as I, type Logger as L, type PermissionMode as P, type ReceiveOptions as R, type StructuredMessage as S, type TaskAssignmentMessage as T, type LogLevel as a, type AgentType as b, type ControllerEvents as c, type ControllerOptions as d, type IdleNotificationMessage as e, type PermissionRequestMessage as f, type PermissionResponseMessage as g, type PlainTextMessage as h, type PlanApprovalRequestMessage as i, type PlanApprovalResponseMessage as j, type ShutdownApprovedMessage as k, type ShutdownRequestMessage as l, type SpawnAgentOptions as m, type TaskFile as n, TaskManager as o, type TaskStatus as p, type TeamConfig as q, TeamManager as r, type TeamMember as s };
430
+ type PermissionPreset = "full" | "edit" | "plan" | "ask";
431
+ interface ClaudeOptions {
432
+ /** Model to use: "sonnet" | "opus" | "haiku" | full model ID */
433
+ model?: "sonnet" | "opus" | "haiku" | (string & {});
434
+ /** Anthropic API key. Maps to ANTHROPIC_AUTH_TOKEN env var. */
435
+ apiKey?: string;
436
+ /** API base URL. Maps to ANTHROPIC_BASE_URL env var. */
437
+ baseUrl?: string;
438
+ /** Request timeout in ms. Maps to API_TIMEOUT_MS env var. */
439
+ timeout?: number;
440
+ /** Working directory for the agent. Defaults to process.cwd(). */
441
+ cwd?: string;
442
+ /**
443
+ * Permission level:
444
+ * - "full" (default) — all tools, no approval needed
445
+ * - "edit" — auto-approve read/write/bash
446
+ * - "plan" — read-only exploration
447
+ * - "ask" — fires permission events for each tool use
448
+ */
449
+ permissions?: PermissionPreset;
450
+ /**
451
+ * Auto-approve permission and plan requests.
452
+ * - `true` — approve everything automatically
453
+ * - `string[]` — only auto-approve these tool names, reject the rest
454
+ *
455
+ * Only meaningful with `permissions: "ask"`. Ignored when "full" or "edit".
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * // Approve everything
460
+ * await claude.agent({ permissions: "ask", autoApprove: true });
461
+ *
462
+ * // Only approve safe tools
463
+ * await claude.agent({ permissions: "ask", autoApprove: ["Read", "Glob", "Grep"] });
464
+ * ```
465
+ */
466
+ autoApprove?: boolean | string[];
467
+ /**
468
+ * Inline callback for permission requests.
469
+ * Called when the agent wants to use a tool.
470
+ * Provides `req.approve()` / `req.reject()` methods.
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * await claude.agent({
475
+ * permissions: "ask",
476
+ * onPermission: (req) => {
477
+ * req.toolName === "Bash" ? req.reject() : req.approve();
478
+ * },
479
+ * });
480
+ * ```
481
+ */
482
+ onPermission?: (request: PermissionRequestInfo) => void;
483
+ /**
484
+ * Inline callback for plan approval requests.
485
+ * Called when the agent submits a plan for review.
486
+ *
487
+ * @example
488
+ * ```ts
489
+ * await claude.agent({
490
+ * onPlan: (req) => {
491
+ * console.log(req.planContent);
492
+ * req.approve();
493
+ * },
494
+ * });
495
+ * ```
496
+ */
497
+ onPlan?: (request: PlanRequestInfo) => void;
498
+ /** Additional environment variables (escape hatch). */
499
+ env?: Record<string, string>;
500
+ /** Log level. Defaults to "warn" for the simplified API. */
501
+ logLevel?: LogLevel;
502
+ /** Custom logger instance. */
503
+ logger?: Logger;
504
+ /** Agent name. Auto-generated if omitted. */
505
+ name?: string;
506
+ /** Agent type. Defaults to "general-purpose". */
507
+ type?: AgentType;
508
+ /** Path to the claude binary. */
509
+ claudeBinary?: string;
510
+ /** Max time in ms to wait for agent to become ready. Default: 60_000. */
511
+ readyTimeout?: number;
512
+ }
513
+ interface AskOptions {
514
+ /** Response timeout in ms. Default: 120_000. */
515
+ timeout?: number;
516
+ /** Poll interval in ms. Default: 500. */
517
+ pollInterval?: number;
518
+ }
519
+ interface SessionOptions extends ClaudeOptions {
520
+ /** Team name. Auto-generated if omitted. */
521
+ teamName?: string;
522
+ }
523
+ interface SessionAgentOptions {
524
+ /** Model override for this agent. */
525
+ model?: string;
526
+ /** Working directory override. */
527
+ cwd?: string;
528
+ /** Agent type override. */
529
+ type?: AgentType;
530
+ /** Permission preset override. */
531
+ permissions?: PermissionPreset;
532
+ /** Auto-approve permission/plan requests. See ClaudeOptions.autoApprove. */
533
+ autoApprove?: boolean | string[];
534
+ /** Inline permission callback. See ClaudeOptions.onPermission. */
535
+ onPermission?: (request: PermissionRequestInfo) => void;
536
+ /** Inline plan callback. See ClaudeOptions.onPlan. */
537
+ onPlan?: (request: PlanRequestInfo) => void;
538
+ /** Per-agent env overrides. */
539
+ env?: Record<string, string>;
540
+ /** Max time in ms to wait for agent to become ready. Default: 60_000. */
541
+ readyTimeout?: number;
542
+ }
543
+ interface PermissionRequestInfo {
544
+ requestId: string;
545
+ toolName: string;
546
+ description: string;
547
+ input?: unknown;
548
+ approve(): Promise<void>;
549
+ reject(): Promise<void>;
550
+ }
551
+ interface PlanRequestInfo {
552
+ requestId: string;
553
+ planContent?: string;
554
+ approve(feedback?: string): Promise<void>;
555
+ reject(feedback: string): Promise<void>;
556
+ }
557
+ interface AgentEvents {
558
+ message: [text: string];
559
+ idle: [];
560
+ permission: [request: PermissionRequestInfo];
561
+ plan: [request: PlanRequestInfo];
562
+ exit: [code: number | null];
563
+ error: [error: Error];
564
+ }
565
+ declare class Agent extends EventEmitter<AgentEvents> {
566
+ private controller;
567
+ private handle;
568
+ private ownsController;
569
+ private disposed;
570
+ private boundListeners;
571
+ private constructor();
572
+ /** Create a standalone agent (owns its own controller). */
573
+ static create(opts?: ClaudeOptions): Promise<Agent>;
574
+ /** Create an agent within an existing session (session owns the controller). */
575
+ static createInSession(controller: ClaudeCodeController, name: string, opts?: SessionAgentOptions): Promise<Agent>;
576
+ /** The agent's name. */
577
+ get name(): string;
578
+ /** The agent process PID. */
579
+ get pid(): number | undefined;
580
+ /** Whether the agent process is still running. */
581
+ get isRunning(): boolean;
582
+ /**
583
+ * Send a message and wait for the response.
584
+ *
585
+ * Uses event-based waiting (via the controller's InboxPoller) instead of
586
+ * polling `readUnread()` directly, which avoids a race condition where the
587
+ * poller marks inbox messages as read before `receive()` can see them.
588
+ */
589
+ ask(question: string, opts?: AskOptions): Promise<string>;
590
+ /** Send a message without waiting for a response. */
591
+ send(message: string): Promise<void>;
592
+ /** Wait for the next response from this agent. */
593
+ receive(opts?: AskOptions): Promise<string>;
594
+ /**
595
+ * Close this agent. If standalone, shuts down the entire controller.
596
+ * If session-owned, kills only this agent's process.
597
+ */
598
+ close(): Promise<void>;
599
+ /** Mark as disposed (used by Session when it closes). */
600
+ markDisposed(): void;
601
+ [Symbol.asyncDispose](): Promise<void>;
602
+ private wireEvents;
603
+ private unwireEvents;
604
+ private wireBehavior;
605
+ private ensureNotDisposed;
606
+ }
607
+ declare class Session {
608
+ readonly controller: ClaudeCodeController;
609
+ private defaults;
610
+ private agents;
611
+ private disposed;
612
+ private constructor();
613
+ static create(opts?: SessionOptions): Promise<Session>;
614
+ /** Spawn a named agent in this session. Inherits session defaults. */
615
+ agent(name: string, opts?: SessionAgentOptions): Promise<Agent>;
616
+ /** Get an existing agent by name. */
617
+ get(name: string): Agent | undefined;
618
+ /** Close all agents and shut down the session. */
619
+ close(): Promise<void>;
620
+ [Symbol.asyncDispose](): Promise<void>;
621
+ private ensureNotDisposed;
622
+ }
623
+ /**
624
+ * One-liner: send a prompt, get a response.
625
+ * Creates an ephemeral agent, sends the message, returns the answer, cleans up.
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const answer = await claude("What does this project do?", { model: "sonnet" });
630
+ * ```
631
+ */
632
+ declare function claudeCall(prompt: string, opts?: ClaudeOptions): Promise<string>;
633
+ /**
634
+ * The simplified Claude Code API.
635
+ *
636
+ * - `claude(prompt, opts?)` — one-liner: ask a question, get an answer
637
+ * - `claude.agent(opts?)` — create a persistent agent for multi-turn conversations
638
+ * - `claude.session(opts?)` — create a multi-agent session
639
+ */
640
+ declare const claude: typeof claudeCall & {
641
+ /**
642
+ * Create a persistent agent for multi-turn conversations.
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * const agent = await claude.agent({ model: "sonnet" });
647
+ * const answer = await agent.ask("What is 2+2?");
648
+ * await agent.close();
649
+ * ```
650
+ */
651
+ agent: (opts?: ClaudeOptions) => Promise<Agent>;
652
+ /**
653
+ * Create a multi-agent session.
654
+ *
655
+ * @example
656
+ * ```ts
657
+ * const session = await claude.session({ model: "sonnet" });
658
+ * const reviewer = await session.agent("reviewer", { model: "opus" });
659
+ * const coder = await session.agent("coder");
660
+ * await session.close();
661
+ * ```
662
+ */
663
+ session: (opts?: SessionOptions) => Promise<Session>;
664
+ };
665
+
666
+ export { Agent as A, type TaskFile as B, ClaudeCodeController as C, TaskManager as D, type TaskStatus as E, type TeamConfig as F, TeamManager as G, type TeamMember as H, type InboxMessage as I, claude as J, type Logger as L, type PermissionMode as P, type ReceiveOptions as R, type StructuredMessage as S, type TaskAssignmentMessage as T, type LogLevel as a, type AgentEvents as b, AgentHandle as c, type AgentType as d, type AskOptions as e, type ClaudeOptions as f, type ControllerEvents as g, type ControllerOptions as h, type IdleNotificationMessage as i, type PermissionPreset as j, type PermissionRequestInfo as k, type PermissionRequestMessage as l, type PermissionResponseMessage as m, type PlainTextMessage as n, type PlanApprovalRequestMessage as o, type PlanApprovalResponseMessage as p, type PlanRequestInfo as q, type SandboxPermissionRequestMessage as r, type SandboxPermissionResponseMessage as s, Session as t, type SessionAgentOptions as u, type SessionOptions as v, type ShutdownApprovedMessage as w, type ShutdownRequestMessage as x, type SpawnAgentOptions as y, type TaskCompletedMessage as z };