Every named declaration in the file, 833 of them, verbatim and in the order Claude Code wrote them, 50 to a page. This is the page to land on from a signature: a verb that returns ToolCallResult links here, at whichever page it is on, and what you get is the declaration itself rather than a description of it.
The source is 22,468 lines of TypeScript mined from build 2.1.330. Anything longer than 12 lines is folded; click the line count to open it. To find a name on another page, search every symbol.
Names on this page, 401 to 450 of 833
SessionAttachInput type
#
line 14356
Added in 2.1.269
The input of session.attach: a surface joined the session's roster of attached clients (a phone opened the session; the desktop app connected).
A remote client attaches by saying so (ui_attach) or by its first ask to draw; the terminal's attachment is the REPL's binding and raises nothing. Every field is the engine's: a hook observes, next(e) passes them on.
16 lines
export type SessionAttachInput = {
/**
* Where the client draws: what it declared, a rendering fact.
*/
surface: RenderSurface;
/**
* The client's own id, unique in the roster; two phones are two clients on
* one surface. A client that never named itself is `<surface>:default`.
*/
clientId: string;
/**
* The size the client draws into, in character cells, and whether its
* layout docks a pane, when it said.
*/
viewport?: RenderViewport;
};
SessionAttachResult type
#
line 14377
Added in 2.1.269
What a session.attach hook returns and what next(e) resolves to: { clientId }, echoed by core; a hook's own value changes nothing.
export type SessionAttachResult = {
clientId: string;
};
SessionAuthorization type
#
line 14388
Added in 2.1.268
What $.session.authorize() answers: an opaque handle for the session's Anthropic credential and its kind, or null when there is none to hold.
The secret itself stays with the engine; the handle is its plugin-side face, spent through $.http.fetch(url, { auth: handle }).
export type SessionAuthorization = {
handle: string;
kind: 'bearer' | 'api-key';
} | null;
SessionCompactArgs type
#
line 14397
Added in 2.1.267
session.compact's input as a plugin's $.session.compact(args) takes it: trigger (plugin), messages and agentId are the engine's.
export type SessionCompactArgs = {
/**
* What the summary should keep or stress, as typed after `/compact`;
* absent, the engine's own compaction prompt alone.
*/
instructions?: string;
};
SessionCompacted type
#
line 14409
Added in 2.1.267 · changed in 2.1.280
A compaction that stands: the conversation as it reads afterwards, and the counts and request usage the engine recorded when it was the one compacting.
34 lines
export type SessionCompacted = {
/**
* The conversation after the compaction, oldest first: from core, its
* summary and the messages it kept; from a hook, whatever it hands up.
*
* What the transcript becomes (kept, on `precompute`, for the compaction
* that comes). A message with the engine's `handle` stands as the engine
* has it; one without is built from its `role`, `text` and tool blocks.
*/
messages: readonly SessionMessage[];
/**
* The conversation's size before, in tokens; absent when core did not
* record it.
*/
tokensBefore?: number;
/**
* Its size afterwards, in tokens; absent on `precompute` and when core
* did not record it.
*/
tokensAfter?: number;
/**
* What the compaction's own model request cost (ModelUsage), when core
* made one: the summarizer's token counts as the API reported them.
*
* Absent when a hook answered in core's place, when core reused a summary
* already computed, and when the response reported none. Accounting only:
* the session's cost ledger (`session.measure`'s `cost`) already holds it.
*
* @example
* const { usage } = await next(e); if (usage) spent += usage.output_tokens
*/
usage?: ModelUsage;
skip?: undefined;
};
SessionCompactInput type
#
line 14448
Added in 2.1.267
The input of session.compact: one compaction of the conversation, about to run; messages is the transcript it runs over.
31 lines
export type SessionCompactInput = {
/**
* What is compacting (SessionCompactTrigger); the key a matcher narrows
* on. Pinned: `next(e)` passes it on as received.
*/
trigger: SessionCompactTrigger;
/**
* The id of the loop compacting, for a subagent's or a fork's own
* transcript; absent for the main conversation (tool.call's `agentId`).
*
* Pinned: left out of a rewrite it is put back, changed it fails the hook.
* `e.messages` is this loop's transcript; `$.session.messages()` stays the
* main conversation, and `$.session.messages({ agentId })` reads this one.
*/
agentId?: string;
/**
* What the summary should keep or stress: the text after `/compact`, a
* plugin's, or absent.
*
* `next({ ...e, instructions })` changes what the summarizer is told.
*/
instructions?: string;
/**
* The transcript being compacted, in `$.session.messages()`'s shape, each
* message carrying the engine's `handle`; a subagent's own under `agentId`.
*
* `next({ ...e, messages })` changes what is summarized: a message kept
* with its handle is the engine's own, whole; one without is read as built.
*/
messages: readonly SessionMessage[];
};
SessionCompactResult type
#
line 14486
Added in 2.1.267
What a session.compact hook returns and what next(e) resolves to: the compaction ({ messages, tokensBefore?, tokensAfter?, usage? }) or a skip.
There is no summary string: the summary is a message.
export type SessionCompactResult = SessionCompacted | SessionCompactSkipped;
SessionCompactSkipped type
#
line 14494
Added in 2.1.267
A compaction vetoed: on precompute nothing is computed or kept; on any other trigger the conversation stays as it is and one line says why.
Core answers it too, when a classic PreCompact hook blocks.
export type SessionCompactSkipped = {
/**
* Why, as the notice reads.
*/
skip: string;
messages?: undefined;
};
SessionCompactTrigger type
#
line 14509
Added in 2.1.267
Who compacts: the person's /compact (manual), the engine at its threshold or on a prompt too long (auto), a plugin, or a precompute.
precompute is the one dispatch that installs nothing: its result is kept for the next compaction, if the conversation still holds what it ran over.
export type SessionCompactTrigger = 'manual' | 'auto' | 'plugin' | 'precompute';
SessionContextBreakdown type
#
line 14519
Added in 2.1.271 · changed in 2.1.280
The context window broken down as /context breaks it down: the rows, the grid and the lists beneath it, in the SDK's get_context_usage shape.
Less that reply's internal-build sections. Token counts are the engine's estimates as numbers, never formatted: a full breakdown counts with the token-count API where it can, a summary one estimates throughout.
75 lines
export type SessionContextBreakdown = {
/**
* One row per category, the free space and the compaction buffer among
* them; `kind` says which is which.
*/
categories: ContextCategory[];
/**
* Tokens in use, unclamped: past `rawMaxTokens` when over the window.
*/
totalTokens: number;
/**
* The window measured against, the same figure as `rawMaxTokens`.
*/
maxTokens: number;
/**
* The window measured against, in tokens: the model's limit, or a smaller
* compaction window (`autocompactSource` says which).
*/
rawMaxTokens: number;
/**
* How that window was settled (ContextWindowSource); the SDK's reply
* carries it under this name too, outside its typed schema.
*/
autocompactSource: ContextWindowSource;
/**
* `totalTokens` over `rawMaxTokens` as a whole percentage, 0 to 100 and
* past it when over.
*/
percentage: number;
/**
* The grid, row by row: 10 by 10, 20 by 10 for a window of a million or
* more, 5 wide when asked for under 80 `columns`.
*/
gridRows: ContextGridSquare[][];
/**
* Which model the breakdown was computed for, as `/model` shows it.
*/
model: string;
/**
* Each memory file in the context, with its path and tokens.
*/
memoryFiles: ContextMemoryFile[];
/**
* Each MCP tool's schema, with its server and tokens.
*/
mcpTools: ContextMcpTool[];
/**
* The custom agents the Agent tool describes, each with its tokens.
*/
agents: ContextAgent[];
/**
* The slash-command listing, counted; absent when the session lists none.
*/
slashCommands?: ContextSlashCommands;
/**
* The skill listing, counted, with one entry per skill; absent when the
* session lists none.
*/
skills?: ContextSkills;
/**
* The token count at which auto-compaction runs; absent when it is off.
*/
autoCompactThreshold?: number;
/**
* Whether auto-compaction is on for the session.
*/
isAutoCompactEnabled: boolean;
/**
* The token counts (ModelUsage) the live window's last API response
* reported, or null before one came back.
*
* The breakdown's `Messages` row is reconciled to it.
*/
apiUsage: ModelUsage | null;
};
SessionContextUsage type
#
line 14603
Added in 2.1.267 · changed in 2.1.268, 2.1.271
The live context window as the status line reads it, and by category as /context breaks it down when the call asked ({ breakdown }).
tokens and percent are the last API response's input side against the model's window, absent until the first response of the live window: a fresh session, or one just compacted, until its next response.
26 lines
export type SessionContextUsage = {
/**
* Input tokens the last response was answered over: uncached, cache-written
* and cache-read together (the status line's `total_input_tokens`).
*/
tokens?: number;
/**
* The context window of the session's model, in tokens (the status line's
* `context_window_size`).
*/
window: number;
/**
* `tokens` over `window` as a whole percentage, 0 to 100 (the status
* line's `used_percentage`).
*/
percent?: number;
/**
* The window by category, as /context breaks it down: present only when
* the call passed `breakdown`, and only with a session bound.
*
* It measures against the compaction window (`rawMaxTokens`), which may be
* smaller than `window`, and estimates every category, so its
* `totalTokens` need not equal `tokens`.
*/
breakdown?: SessionContextBreakdown;
};
SessionCost type
#
line 14643
Added in 2.1.267 · changed in 2.1.268, 2.1.326
What the session has cost, as /cost and the status line total it; on an agent (AgentInfo), its own requests' part of that.
A client-side estimate, priced locally at list price or the managed modelPricing rates, not authoritative billing data: it can run over or under. Server-side billing (the invoice, or the cloud provider's bill) is the final authority. On a subscription, usage inside the plan is not billed in dollars, so there the figure is no charge at all.
Do not bill anyone or make a financial decision from it. A mod that shows it should label it an estimate.
15 lines
export type SessionCost = {
/**
* US dollars, summed over every priced API response this session, a mod's
* `$.model` calls among them, and auto mode's classifier calls where the
* account is billed for them; the engine's other side queries stay out.
*/
usd: number;
/**
* Present once `usd` includes a model with no known price, which goes at
* another model's rates: the note `/cost` prints.
*
* On an agent, only its own requests set it.
*/
hasUnknownPrice?: true;
};
SessionCronSummary type
#
line 14659
Added in 2.1.265
15 lines
type SessionCronSummary = {
id: string;
/**
* Cron expression, e.g. "0 9 * * 1-5".
*/
schedule: string;
/**
* False for one-shot wakeups whose cron field encodes a single fire time; true for tasks that re-fire on every match.
*/
recurring: boolean;
/**
* Prompt text submitted when the cron fires. Capped at 1000 chars; clipped values append an in-string "... [+N chars]" marker.
*/
prompt: string;
};
SessionDetachInput type
#
line 14679
Added in 2.1.269
The input of session.detach: a client left the session's roster. Every field is the engine's: a hook observes, and next(e) passes them on.
14 lines
export type SessionDetachInput = {
/**
* Where the client drew.
*/
surface: RenderSurface;
/**
* The id it attached under.
*/
clientId: string;
/**
* Why it left: it detached, or the session ended under it.
*/
reason: SessionDetachReason;
};
SessionDetachReason type
#
line 14698
Added in 2.1.269
Why a client left the roster: detach, it said so (ui_detach); end, the session ended with it still attached.
export type SessionDetachReason = 'detach' | 'end';
SessionDetachResult type
#
line 14704
Added in 2.1.269
What a session.detach hook returns and what next(e) resolves to: { clientId }, echoed by core; a hook's own value changes nothing.
export type SessionDetachResult = {
clientId: string;
};
SessionEndHookInput type
#
line 14708
Added in 2.1.265
type SessionEndHookInput = BaseHookInput & {
hook_event_name: 'SessionEnd';
reason: ExitReason;
};
SessionEndInput type
#
line 14721
Added in 2.1.275
The input of session.end: the session is ending, why, and how to come back to it; every field is the engine's: a hook observes, next(e) passes it on.
One short wall-clock bound (1.5 s by default) covers every hook, its $ waits and core, and next.budget reads it: at it next.signal aborts, a $ call in flight with it; only a process a command let go of outlives it.
19 lines
export type SessionEndInput = {
/**
* Why it ends (SessionEndReason), the word the classic SessionEnd hook
* receives as its `reason`.
*
* `clear` is how a hook sees a `/clear`: the conversation ends, the process
* goes on under a new session id, and no `session.start` fires for it.
*/
reason: SessionEndReason;
/**
* The ending session's id (`$.session.id()` until now); after a `/clear`
* or a resume the process goes on under another.
*/
sessionId: string;
/**
* What `claude --resume` takes to return to it.
*/
resume: SessionResume;
};
SessionEndReason type
#
line 14749
Added in 2.1.275
Why the session ended: the classic SessionEnd hook's own reason, word for word.
prompt_input_exit, the person left (/exit, ctrl+c, ctrl+d); clear, a /clear started a fresh one; resume, another took its place; logout; other, a -p run finished or the process got SIGINT, SIGTERM or SIGHUP.
export type SessionEndReason = ClassicHookInputs['SessionEnd']['reason'];
SessionEndResult type
#
line 14755
Added in 2.1.275
What a session.end hook returns and what next(e) resolves to: { sessionId }, echoed by core; a hook's own value changes nothing.
export type SessionEndResult = {
sessionId: string;
};
SessionIdentity type
#
line 14767
Added in 2.1.299 · changed in 2.1.326
What $.session.identity() answers: how the session is signed in, the address the model was handed and, under a managed pin, the account the session holds.
The engine answers every caller alike; the built-in privacy and sec-default mods decide who gets what. That is a contract, not a wall: any mod can read the person's own config file, where a login keeps the same facts.
60 lines
export type SessionIdentity = {
/**
* How the session is authenticated: `claude.ai`, `console`, `api-key`,
* `oauth-token` (a token its host handed it), `none`, or a cloud
* provider's name (`bedrock`, `vertex`, ...).
*
* Builds add kinds: read an unknown one as a session with no identity.
*/
kind: string;
/**
* The organization the account belongs to, by its id, only where
* managed `forceLoginOrgUUID` lists that organization.
*
* Absent everywhere else, as are the two fields below: with no pin, a
* pin on another organization, an API key or a cloud provider. So these
* three never tell of another organization's account.
*/
organizationId?: string;
/**
* The organization's plan as the server names it (`claude_team`,
* `claude_enterprise`, ...), when the login recorded one.
*
* Always read from the login record on disk, which the person can
* edit, whatever `isVerified` says.
*/
organizationType?: string;
/**
* The account's email address, where the session holds one.
*/
email?: string;
/**
* Whether `organizationId` and `email` are the account the server told
* this process its credential signed in as, not the login record on disk.
*
* The person can edit that record. False until the server has answered
* this process, as with nonessential traffic off, and with no account.
*/
isVerified: boolean;
/**
* The address the context hands the model, pin or no pin, where it hands
* one. It can differ from `email`, and `isVerified` says nothing of it.
*
* privacy leaves it off the answer of a caller outside `builtin`. A hook
* above privacy still sees it on a built-in's read.
*/
contextEmail?: string;
deny?: undefined;
} | {
/**
* Why nothing is answered: privacy or sec-default refused a caller in
* the `user` tier, or privacy could not read the identity.
*/
deny: string;
kind?: undefined;
organizationId?: undefined;
organizationType?: undefined;
email?: undefined;
isVerified?: undefined;
contextEmail?: undefined;
};
SessionInfo type
#
line 14832
Added in 2.1.326
What $.session.info() answers: what a settings hook's input says of the session that no other read on $.session does, and where the engine runs.
43 lines
export type SessionInfo = {
/**
* The main conversation's transcript file (`transcript_path`); empty in a
* session that keeps none on this machine.
*
* A subagent's lies under the folder of that name, in `subagents/`.
*/
transcriptPath: string;
/**
* The session's scratchpad directory (`scratchpad_dir`); absent where the
* session has none.
*/
scratchpadDir?: string;
/**
* The id of the prompt the session is on (`prompt_id`); absent before the
* first.
*/
promptId?: string;
/**
* The agent the session itself runs as (`--agent`, `agent_type`); absent
* when it runs as none.
*/
agentType?: string;
/**
* The folder the project's settings are read from when it is not where the
* session stands, which a settings hook's command starts in; else absent.
*/
configRoot?: string;
/**
* The operating system the engine runs on; `wsl` is Linux under Windows.
*
* The engine always gives it; a hook that answers whole may leave it out.
*/
platform?: 'macos' | 'windows' | 'wsl' | 'linux' | 'unknown';
/**
* True on the hosted server, whose machine is not the session's own, so
* `platform` is the server's. False anywhere else, a cloud session with a
* machine of its own included.
*
* The engine always gives it; a hook that answers whole may leave it out.
*/
isHosted?: boolean;
};
SessionMachine type
#
line 14887
Added in 2.1.328
What $.session.machine() answers: the machine the engine runs on, as uname -s, -r and -m print it (on Windows, what the runtime reports in their place), and which of six developer tools its PATH holds.
The tool lists are the ones the engine's own analytics rows carry, found in the engine with no program run. On the server (not the CLI), where a session's tools run in another container, an installed mod is answered by that container, and the call rejects where it gives no answer; a built-in mod's own call gets the server's three names and empty lists.
26 lines
export type SessionMachine = {
/**
* The system's name as `uname -s` prints it: `Linux`, `Darwin`;
* `Windows_NT` on Windows.
*/
sysname: string;
/**
* The kernel's release as `uname -r` prints it (`6.8.0-48-generic`,
* `24.1.0`); on Windows the NT version (`10.0.22631`).
*/
release: string;
/**
* The hardware's name as the runtime reports it, in `uname -m`'s words:
* `x86_64`, and `arm64` or `aarch64` for 64-bit ARM (either may stand
* for the other).
*/
machine: string;
/**
* Of `npm`, `yarn` and `pnpm`, those found on the PATH, in that order.
*/
packageManagers: string[];
/**
* Of `bun`, `deno` and `node`, those found on the PATH, in that order.
*/
runtimes: string[];
};
SessionMeasureInput type
#
line 14922
Added in 2.1.275
The input of session.measure: what $.session.usage() answers at this moment, and which of its units moved since the last measurement a hook saw.
The same figures the op reads, without context.breakdown: call $.session.usage({ breakdown }) from the hook when the categories matter. Every field is the engine's: a hook observes, and next(e) passes them on.
28 lines
export type SessionMeasureInput = {
/**
* The live context window (`$.session.usage()`'s `context`): the window,
* and its fill once a response of the live window reported one.
*
* Never carries `breakdown` here.
*/
context: SessionContextUsage;
/**
* The rate-limit windows the last response reported, each with its
* `percentUsed`; empty off a subscription or before the first reading.
*/
rateLimits: SessionRateLimit[];
/**
* What the session has cost so far, an estimate, not the bill
* (SessionCost); absent where the host keeps no ledger.
*/
cost?: SessionCost;
/**
* Which units differ from the last measurement raised (UsageUnit), never
* empty; the first measurement names every unit it has a figure for.
*
* `context`: the fill moved; `rateLimits`: a window moved a whole point,
* appeared or left, or the account's limit status changed; `cost`: the
* total grew.
*/
changed: UsageUnit[];
};
SessionMeasureResult type
#
line 14955
Added in 2.1.275
What a session.measure hook returns and what next(e) resolves to: { changed }, echoed by core; a hook's own value changes nothing.
export type SessionMeasureResult = {
changed: UsageUnit[];
};
SessionMessage type
#
line 14962
In the first published surface (2.1.259) · changed in 2.1.267, 2.1.326
One message of the transcript as $.session.messages() returns it.
34 lines
export type SessionMessage = {
/**
* Who wrote it.
*/
role: 'user' | 'assistant';
/**
* Its text blocks joined; '' when it has none.
*/
text: string;
/**
* The tool_use blocks of an assistant message, each with its outcome
* (`result`, `text`, `isError`) once the transcript holds it.
*/
toolUses: ToolUseSummary[];
/**
* The tool_result blocks of a user message: `{ tool_use_id, text, isError,
* result }`.
*/
toolResults?: ToolResultSummary[];
/**
* The row's id, as `session.append` carries it: what a later
* `$.session.messages({ after })` reads on from.
*
* On a read that names `last` or `after`; absent on every other.
*/
uuid?: string;
/**
* An opaque token the engine stamps on a message it hands a
* `session.compact` hook, so a list handed back maps to its own messages.
*
* Absent on `$.session.messages()` and on a message a hook built.
*/
handle?: string;
};
SessionMessagesAgentArgs type
#
line 15001
Added in 2.1.280 · changed in 2.1.326
A $.session.messages call for the rows (SessionMessage) of the main conversation or of one agent's, whole or in part: no as.
18 lines
type SessionMessagesAgentArgs = {
/**
* Whose conversation; absent, the main one.
*/
agentId?: string;
/**
* Left out: the rows.
*/
as?: undefined;
/**
* How many of the newest rows (SessionMessagesArgs). Not with `after`.
*/
last?: number;
/**
* The row to read on from (SessionMessagesArgs). Not with `last`.
*/
after?: string;
};
SessionMessagesApiArgs type
#
line 15024
Added in 2.1.280 · changed in 2.1.326
A $.session.messages call for the Messages API form (ApiMessage) of the main conversation or, with agentId, of one of this session's agents'.
19 lines
type SessionMessagesApiArgs = {
/**
* `"api"`.
*/
as: 'api';
/**
* Whose conversation; absent, the main one.
*/
agentId?: string;
/**
* How many of the newest messages, walked back to a clean user one
* (SessionMessagesArgs).
*/
last?: number;
/**
* Left out: this form has no row to read on from.
*/
after?: undefined;
};
SessionMessagesApiResult type
#
line 15051
Added in 2.1.280
What $.session.messages({ as: "api", agentId }) resolves to: the agent's conversation as ApiMessage, or { deny } (SessionMessagesDeny).
Array.isArray tells the two apart; without agentId it is always the messages.
type SessionMessagesApiResult = ApiMessage[] | SessionMessagesDeny;
SessionMessagesArgs type
#
line 15057
Added in 2.1.280 · changed in 2.1.326
What $.session.messages(args) takes and a session.messages hook reads on e: whose conversation, in which form, and which part of it.
39 lines
type SessionMessagesArgs = {
/**
* Whose conversation to read: the id `tool.call`, `turn.step` and
* `turn.complete` carry inside that agent's loop. Absent, the main one.
*
* A subagent (foreground or background), a fork, or a teammate running in
* this process; `$.agent.list()` lists it, an Agent tool use's `toolUses`
* entry names it. Not an agent a workflow run filed under the run.
*/
agentId?: string;
/**
* `"api"` for the Messages API form (ApiMessage: `{ role, content }` with
* the content blocks intact); absent, the rows (SessionMessage).
*/
as?: 'api';
/**
* How many of the newest entries, a whole number from 1 to 4096; absent,
* 4096. Rows of a read naming it carry `uuid`. Not with `after`.
*
* With `as`, the cut walks back to the nearest user message carrying no
* tool_result, so more may come (4096 at most); with none that near, it
* opens on the first inside the cut, else mid-exchange where it was cut.
*/
last?: number;
/**
* A row's `uuid`: the rows after it, oldest first, none skipped, each with
* `uuid`; 4096 back may have more behind them. Not with `last` or `as`.
*
* Any row since the last compaction or kept by it anchors, listed or not;
* any other is `{ deny }` (SessionMessagesDeny). Nothing ahead of it comes:
* not a row whose tool answered since (its result row does), nor the
* summary of a compaction that kept it.
*
* The id `session.append` answered for a `user` row anchors at main's copy
* of it while that anchors. Else it stands where a request carries it: rows
* stored before then are ahead of it, and none is after it while it waits.
*/
after?: string;
};
SessionMessagesCall type
#
line 15104
Added in 2.1.280
$.session.messages: the main conversation's rows with no argument, with { as: "api" } its Messages API form; with agentId an agent's, or deny.
last or after asks for part of it; ranged rows are typed rows or deny, as a hook above may add an after that no longer anchors.
type SessionMessagesCall = {
(): Promise<SessionMessage[]>;
(args: SessionMessagesMainApiArgs): Promise<ApiMessage[]>;
(args: SessionMessagesApiArgs): Promise<SessionMessagesApiResult>;
(args: SessionMessagesAgentArgs): Promise<SessionMessagesResult>;
(args: SessionMessagesArgs): Promise<SessionMessagesValue>;
};
SessionMessagesDeny type
#
line 15120
Added in 2.1.280
What $.session.messages resolves to when agentId names no conversation this session can read, or after no row to read on from: why, in deny.
The agent is not one of this session's, runs in another process (a pane-hosted teammate), or finished and the session reads no saved transcript back for it (none saved; a workflow run's). Never main's rows in its place.
type SessionMessagesDeny = {
/**
* Why nothing was read, naming the agent's id or the row's uuid.
*
* A row was cleared, rewound or left behind the last compaction. Or, for a
* moment: a compaction that keeps it is still landing, or it is a turn's
* own row and its `session.append` hook still runs.
*/
deny: string;
};
SessionMessagesMainApiArgs type
#
line 15135
Added in 2.1.280 · changed in 2.1.326
A $.session.messages({ as: "api" }) call naming no agent: the main conversation, whose answer is always the messages (ApiMessage).
19 lines
type SessionMessagesMainApiArgs = {
/**
* `"api"`.
*/
as: 'api';
/**
* Left out: the main conversation.
*/
agentId?: undefined;
/**
* How many of the newest messages, walked back to a clean user one
* (SessionMessagesArgs).
*/
last?: number;
/**
* Left out: this form has no row to read on from.
*/
after?: undefined;
};
SessionMessagesResult type
#
line 15162
Added in 2.1.280
What $.session.messages({ agentId, last, after }) resolves to: the messages (SessionMessage), or { deny } (SessionMessagesDeny).
With an agent the session cannot read or a row it cannot read on from, the deny. Array.isArray tells the two apart.
type SessionMessagesResult = SessionMessage[] | SessionMessagesDeny;
SessionMessagesValue type
#
line 15168
Added in 2.1.280
What a session.messages hook's { value } holds, for any call: the rows (SessionMessage), the Messages API form (ApiMessage), or { deny }.
type SessionMessagesValue = SessionMessagesResult | SessionMessagesApiResult;
SessionRateLimit type
#
line 15173
Added in 2.1.267 · changed in 2.1.268
One rate-limit window as the rate-limit notices read it.
17 lines
export type SessionRateLimit = {
/**
* Which window: `five_hour`, `seven_day`, or a Claude gateway's
* `spend_limit`, which comes from the gateway's own estimate from token
* counts, not a billed amount.
*/
kind: string;
/**
* How much of the window is used, 0 to 100 with at most one decimal:
* 23.5, or 7, never 7.000000000000001; past 100 on an exceeded spend limit.
*/
percentUsed: number;
/**
* When the window resets, as an ISO 8601 timestamp.
*/
resetsAt?: string;
};
SessionReceiveEvent type
#
line 15195
Added in 2.1.267 · changed in 2.1.282
An external-event wake the delivery's text parsed as (a GitHub relay event, a signal's notice): the envelope's attributes and its JSON body.
31 lines
export type SessionReceiveEvent = {
/**
* The producing service (`github`; `artifact-room` for a page's events).
*/
source: string;
/**
* The event's discriminator (`pull_request.closed`, `check_suite`).
*/
kind: string;
/**
* The envelope's sender-kind attribute as the server stamped it (`system`
* for a relay's own event, `rc_owner` for the user's own relayed message);
* absent when the envelope carries none.
*/
from?: string;
/**
* The envelope's JSON body (`{ pr: "acme/app#12", outcome: "merged" }`).
*
* For `artifact-room`, kind `events`: `{ artifact, events, overflow }`, one
* burst under origin `task-notification`, each event `{ topic, from,
* isOwnViewer, data, isTruncated }` as the page's viewers wrote it.
*/
data: Record<string, unknown>;
/**
* The `data` keys whose values are free text a third party wrote (a
* commenter's `author` and `comment`), as the producer marked them.
*
* Empty when none; the server asserts every other key's value, not these.
*/
untrustedKeys: readonly string[];
};
SessionReceiveInput type
#
line 15231
Added in 2.1.267 · changed in 2.1.280
The input of session.receive: one inbound delivery, sanitized, before it is queued (a relay's event, a peer's message, a message for an agent).
33 lines
export type SessionReceiveInput = {
/**
* Where the delivery came from, as the bridge classified it; the key a
* matcher narrows on. `next(e)` passes it on as received.
*/
origin: SessionReceiveOrigin;
/**
* The delivery's body as the model would read it (a content-block
* delivery's text blocks, joined).
*/
text: string;
/**
* The external-event wake the text parsed as (`source` `github` for a
* subscribed pull request's event); passed on as received.
*
* Present only for a delivery the server itself rendered as a wake (a
* webhook relay, the session inbox), by its asserted origin; anyone else's
* wake-shaped text stays `text`. Its `untrustedKeys` name third-party text.
*/
event?: SessionReceiveEvent;
/**
* The id of the loop the delivery is for, when it is one of this session's
* agents (`$.agent.list()` lists it); absent for the main conversation's.
*
* Pinned: a rewrite that changes it is refused. An agent's message raises
* `session.send` with the sender's `agentId`, then this with the receiver's
* inside its turn, where a hook awaiting its own `$.prompt.submit` hangs.
*
* @example
* on("session.receive", { agentId: worker }, ($, e) => ({ consumed: "no" }))
*/
agentId?: string;
};
SessionReceiveOrigin type
#
line 15269
Added in 2.1.267 · changed in 2.1.268, 2.1.280
Where an inbound delivery came from, as the bridge classified it from the server's stamps: prompt.submit's e.origin, less what never arrives.
57 lines
export type SessionReceiveOrigin = {
/**
* `bridge` the user's own from a Remote Control client; `unclassified`
* one nobody could place; the rest as at `prompt.submit`.
*
* `task-notification` a relay's event or a trigger.
*/
kind: 'bridge' | 'task-notification' | 'scheduled-trigger' | 'peer-send-message' | 'projects-relay' | 'slack-ping' | 'unclassified';
} | {
/**
* `peer` another session's or agent's model; `coordinator` the main
* conversation to an agent of its own.
*/
kind: 'peer' | 'coordinator';
/**
* Which plugin's `$.session.send` composed it, AS THE SENDER SAYS;
* absent for a message the sending model wrote itself.
*
* A claim over a same-user channel, exactly as trustworthy as the
* sender's name: name it in a log line, never key a guard on it.
*/
plugin?: string;
} | {
/**
* A delivery through this session's agent-team mailbox: `coordinator`
* from the lead's harness, `peer` from a teammate's or when unverified.
*/
kind: 'peer' | 'coordinator';
/**
* Which plugin's `$.session.send` composed it, as the mailbox entry
* says; absent for a message the sending model wrote itself.
*/
plugin?: string;
/**
* The sending member's name in the team (`team-lead` for the lead):
* the harness's stamp when `isVerified`, else whatever the writer put.
*
* @example
* on("session.receive", { origin: { teammate: "researcher" } }, hook)
*/
teammate: string;
/**
* Whether this process can vouch for the mailbox entry: it wrote it (the
* lead's process, for its own and in-process teammates' sends), or it is
* a teammate in its own pane that accepted the lead's signature on it.
*
* `false`: this process could not check it, or it failed the check. The
* lead's process cannot check a pane teammate's send, and a pane teammate
* can check only what its lead sends, with a key from that lead. A failed
* check is no proof of forgery: such a teammate fails every entry its
* lead writes after restarting.
*
* @example
* on("session.receive", { origin: { isVerified: false } }, hook)
*/
isVerified: boolean;
};
SessionReceiveResult type
#
line 15334
Added in 2.1.267
What a session.receive hook returns and what next(e) resolves to: the delivery that was queued, { text }, or { consumed: reason }.
next(e) resolves once the delivery is queued; a hook answering without next queues nothing.
19 lines
export type SessionReceiveResult = {
/**
* The body the delivery was queued with; from core, `e.text` as it
* arrived at the bottom.
*
* A rewrite passes it down, `next({ ...e, text })`.
*/
text: string;
consumed?: undefined;
} | {
/**
* Takes the delivery, answered without `next`: it is not queued, not
* written to the transcript and never reaches the model.
*
* The reason is logged, the plugin named.
*/
consumed: string;
text?: undefined;
};
SessionRepo type
#
line 15358
In the first published surface (2.1.259)
What $.session.repo() answers: the repository's root and its origin remote, when the session is in one. A vcs.detect hook changes those two.
29 lines
export type SessionRepo = {
/**
* The repository's root, absolute: the main working tree's for a worktree
* (`vcs.detect`'s `mainRoot`, else its `root`).
*/
root: string;
/**
* The `origin` remote's URL as git has it (push URL preferred), or null when
* the repository has none. Another system's may be no URL.
*/
remote: string | null;
/**
* Whether the remote is one of the repositories this build treats as its
* own; false in a build that has none or when the remote is unrecognized.
*
* The engine matches the build's own list of repositories with its
* hardened remote parser. A plugin reads this to behave differently in a
* public repository; which repositories are the build's is its to say.
*/
internal: boolean;
/**
* The repository the allowlist matched, as `owner/name`; null when
* `internal` is false.
*
* A working copy without a remote that the engine still recognises is
* named by its own checkout configuration; a remote's name is its path.
*/
name: string | null;
};
SessionResume type
#
line 15391
Added in 2.1.275
How to come back to the session that ended: what claude --resume takes.
export type SessionResume = {
/**
* What `claude --resume <id>` takes, the ending session's own.
*
* It resumes a session that wrote a transcript: one that never ran a
* prompt, or ran with persistence off, left nothing under this id.
*/
id: string;
};
SessionSendAddress type
#
line 15409
Added in 2.1.280
Whom $.session.send addresses: a recipient as the SendMessage tool names one (a string), or a session or an agent of this session by id.
The engine spells the two id forms the tool's way before the send, and a session.send hook reads that spelling on e.to: { agentId } as the id (a live teammate's as its name), { sessionId } as its address.
19 lines
export type SessionSendAddress = string | {
/**
* One of the person's own sessions: what its `$.session.id()` answers
* on this machine, or a Remote Control or cloud id (`session_...`).
*
* A session that is not running now is not delivered to: the result
* says so.
*/
sessionId: string;
} | {
/**
* A subagent or teammate of this session: the id `$.agent.list()`
* lists and `agent.spawn` answered.
*
* A finished subagent is resumed from its transcript with the message,
* as the tool does. A live teammate's `teammateId` reaches it too.
*/
agentId: string;
};
SessionSendArgs type
#
line 15433
Added in 2.1.280
session.send's input as a plugin's $.session.send(args) takes it: origin (the calling plugin) and agentId are the engine's to set.
export type SessionSendArgs = {
/**
* The recipient: the tool's own spelling (a name, an agent id, a received
* `from` address), or `{ sessionId }` / `{ agentId }`.
*/
to: SessionSendAddress;
/**
* The message's text, non-empty.
*/
text: string;
};
SessionSendInput type
#
line 15449
Added in 2.1.280
The input of session.send: one plain-text message about to leave this conversation for another agent or session; the dual of session.receive.
30 lines
export type SessionSendInput = {
/**
* Whom it goes to, as the SendMessage tool spells a recipient: a name as
* ListAgents lists it, an agent id, or a received `from` address.
*
* A plugin's `{ sessionId }` or `{ agentId }` arrives already spelled so.
* `next({ ...e, to })` readdresses it, judged again as the tool judges a
* send there; a name nobody carries is refused after the hooks.
*/
to: string;
/**
* The message's text as the recipient will read it inside the engine's
* envelope; `next({ ...e, text })` is what is sent, with no new approval.
*/
text: string;
/**
* Who is sending: the model through its SendMessage tool, or a plugin
* through `$.session.send`. Pinned: a rewrite that changes it is refused.
*/
origin: SessionSendOrigin;
/**
* The id of the loop sending, when a subagent's or teammate's model sends
* (`$.agent.list()` lists it); absent for the main conversation's send.
*
* Pinned: the agent axis, not the origin. A message between two subagents
* carries the sender's id here and reaches the receiver's
* `session.receive` with that loop's own `agentId`.
*/
agentId?: string;
};
SessionSendOrigin type
#
line 15487
Added in 2.1.280
Who is sending at session.send: the model through its SendMessage tool, or a plugin through $.session.send; stamped by the engine, pinned.
The receiver's session.receive reads a plugin's name on its own e.origin.plugin, beside the peer or coordinator kind it keeps.
19 lines
export type SessionSendOrigin = {
/**
* The model's own SendMessage tool call, in the main conversation or
* in a subagent's or teammate's loop (`e.agentId` says which).
*/
kind: 'model';
} | {
/**
* A plugin's `$.session.send`, its `$.tool.call` of SendMessage, or the
* model inside an agent it spawned. Every hook of the plugin sees it, but
* for the one that made the `$` call.
*/
kind: 'plugin';
/**
* The sending plugin's name, which the receiver reads as its
* `session.receive` origin's `plugin` and shows beside the sender.
*/
name: string;
};
SessionSendResult type
#
line 15518
Added in 2.1.280
What a session.send hook returns and next(e) and $.session.send resolve to: whether the message was delivered, and why not when not.
Delivered means queued at the recipient (an agent's inbox, another session's socket, the server for a remote session), never read: the receiver's turn is its own, and it may hold the message for its person.
const { isDelivered, reason } = await $.session.send({ to, text })
21 lines
export type SessionSendResult = {
/**
* True: the message reached its recipient's queue or inbox.
*/
isDelivered: true;
reason?: undefined;
} | {
/**
* False: nothing was delivered. A hook answering this without `next`
* refuses the send, and the model reads `reason` as the tool's result.
*/
isDelivered: false;
/**
* Why not, as the SendMessage tool words it: nobody by that name,
* several by it, the recipient gone or refusing, or a hook's refusal.
*
* @example
* on('session.send', { to: 'prod' }, () => NOT_FROM_HERE)
*/
reason: string;
};
SessionStartHookInput type
#
line 15540
Added in 2.1.265
23 lines
type SessionStartHookInput = BaseHookInput & {
hook_event_name: 'SessionStart';
source: 'startup' | 'resume' | 'clear' | 'compact' | 'fork';
agent_type?: string;
model?: string;
session_title?: string;
/**
* resume/fork: seconds since the resumed transcript's last assistant response
*/
seconds_since_last_response?: number;
/**
* resume/fork: the resumed transcript's last response input + cache_read + cache_creation + output tokens (for a server-side tool loop, its last iteration's window, not the summed totals)
*/
context_tokens?: number;
/**
* resume/fork: seconds_since_last_response exceeds the prompt-cache TTL, so the first request re-caches context_tokens
*/
prompt_cache_likely_expired?: boolean;
/**
* resume/fork: estimated cost of re-caching context_tokens on the session model - the managed modelPricing when set, otherwise list price; excludes the response
*/
estimated_cache_write_usd?: number;
};
SessionStartInput type
#
line 15568
In the first published surface (2.1.259) · changed in 2.1.268
The input of session.start: the session the process starts with, read the way $.session reads it at that moment.
16 lines
export type SessionStartInput = {
/**
* The directory the session runs in, absolute (`$.session.cwd()`).
*/
cwd: string;
/**
* Where the session draws at start (`$.session.surfaces()[0]`): `terminal`
* under the REPL; null for a `-p` run or the SDK, which draw nowhere yet.
*/
surface: RenderSurface | null;
/**
* Whether a person is at the prompt: true under the REPL, false for a `-p`
* run or the SDK.
*/
isInteractive: boolean;
};