Method reference for CoderClient from the standalone @agentuity/coder package. Coder is not a ctx.* service; the client is used from agents, scripts, or external apps.
Coder has HTTP endpoints, but no single static base URL. CoderClient calls the Agentuity API to discover your org's Hub address, then routes session and workspace requests there. For concepts, session lifecycle, and workflows, see Coder.
If you want practical examples before reading the full reference, see: Managing Coder Sessions with the SDK, Choosing Built-In Agents for a Coder Session, Attaching Skills to a Coder Session, Using Workspaces to Reuse Repos, Skills, and Agent Selection, Reconnecting to Existing Coder Sessions, and Creating Loop-Mode Coder Sessions.
Install
bun add @agentuity/coderimport { CoderClient } from '@agentuity/coder';
const client = new CoderClient();Constructor
new CoderClient(options?: CoderClientOptions)
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | AGENTUITY_SDK_KEY env var | API key for authentication |
url | string | Auto-discovered | Explicit Hub base URL. Set to skip discovery |
region | string | AGENTUITY_REGION or 'usc' | Region used during discovery. Ignored when url or AGENTUITY_CODER_URL is set |
orgId | string | - | Organization scope for multi-tenant operations (optional) |
logger | Logger | Minimal logger | Custom logger instance |
The client resolves the Hub URL in this order:
options.url(explicit)AGENTUITY_CODER_URLenvironment variable- Auto-discovery via the Agentuity API
Most apps only need the API key. Set AGENTUITY_SDK_KEY and let the client discover the rest.
getUrl()
Resolve the active Coder base URL. This returns the explicit url when you set one, otherwise it uses AGENTUITY_CODER_URL or discovery through the Agentuity API.
Returns: Promise<string>
const client = new CoderClient();
const url = await client.getUrl();
console.log(url);Sessions
createSession(body)
Create a new coder session.
| Param | Type | Required | Description |
|---|---|---|---|
body.task | string | yes | Primary task prompt for the session |
body.label | string | no | Human-readable session label |
body.agent | string | no | Default agent identifier |
body.defaultAgent | string | no | Preferred default agent identifier for routed session work |
body.visibility | 'private' | 'organization' | 'collaborate' | no | Session visibility |
body.workflowMode | 'standard' | 'loop' | no | Workflow execution mode |
body.loop | CoderSessionLoopConfig | no | Loop-mode configuration (goal, maxIterations, autoContinue, allowDetached) |
body.tags | string[] | no | Tags for filtering |
body.enabledAgents | string[] | no | Built-in or custom agent roster attached to the session |
body.savedSkillIds | string[] | no | Saved skill IDs to attach |
body.skillBucketIds | string[] | no | Skill bucket IDs to attach |
body.skills | CoderSkillRef[] | no | Inline skill definitions attached to the session |
body.repo | CoderSessionRepositoryRef | no | Primary repository to mount |
body.repos | CoderSessionRepositoryRef[] | no | Multiple repositories to mount |
body.workspaceId | string | no | Workspace to attach to the session |
body.env | Record<string, string> | no | Environment variables injected into the runtime |
body.metadata | Record<string, string> | no | Arbitrary metadata |
Returns: Promise<CoderCreateSessionResponse>
const session = await client.createSession({
task: 'Implement OAuth login with GitHub provider',
workflowMode: 'standard',
tags: ['auth', 'feature'],
});
console.log(session.sessionId);createAgentBuilderSession(body)
Create a dedicated agent-builder session for creating or editing custom agents.
| Param | Type | Required | Description |
|---|---|---|---|
body.label | string | no | Builder session label override |
body.prompt | string | no | Optional focus prompt for the builder kickoff |
body.mode | 'new' | 'edit' | 'from_session' | no | Builder launch mode. Inferred from IDs when omitted |
body.visibility | 'private' | 'organization' | 'collaborate' | no | Builder session visibility |
body.sourceSessionId | string | required for from_session | Source session identifier |
body.targetAgentId | string | required for edit unless targetAgentSlug is set | Target custom-agent ID |
body.targetAgentSlug | string | required for edit unless targetAgentId is set | Target custom-agent slug |
Returns: Promise<CoderCreateSessionResponse>
getSession(sessionId)
Retrieve a session by ID.
| Param | Type | Required | Description |
|---|---|---|---|
sessionId | string | yes | Session identifier |
Returns: Promise<CoderSession>
const session = await client.getSession('codesess_abc123');updateSession(sessionId, body)
Update an existing session.
| Param | Type | Required | Description |
|---|---|---|---|
sessionId | string | yes | Session identifier |
body.label | string | no | Updated label |
body.agent | string | no | Updated default agent |
body.defaultAgent | string | no | Updated preferred default agent identifier |
body.visibility | 'private' | 'organization' | 'collaborate' | no | Updated visibility |
body.workflowMode | 'standard' | 'loop' | no | Updated workflow mode |
body.loop | CoderSessionLoopConfig | no | Updated loop-mode configuration |
body.tags | string[] | no | Updated tag set |
body.enabledAgents | string[] | no | Updated session agent roster |
body.skills | CoderSkillRef[] | no | Updated attached skills for the session |
body.metadata | Record<string, string> | no | Updated arbitrary metadata associated with the session |
Returns: Promise<CoderUpdateSessionResponse>
await client.updateSession('codesess_abc123', {
tags: ['auth', 'feature', 'phase-2'],
visibility: 'organization',
});listSessions(params?)
List sessions with optional filtering and pagination.
params fields (all optional):
| Field | Type | Description |
|---|---|---|
search | string | Search query across title, task, and metadata |
includeArchived | boolean | Include archived sessions |
limit | number | Max sessions to return |
offset | number | Pagination offset |
Returns: Promise<CoderSessionListResponse>
const { sessions, total } = await client.listSessions({ limit: 20 });
for (const s of sessions) {
console.log(`${s.sessionId}: ${s.label} (${s.status})`);
}listConnectableSessions(params?)
List sessions the caller can currently connect to. Archived and history-only sessions are filtered out.
params fields (all optional):
| Field | Type | Description |
|---|---|---|
search | string | Search query for connectable sessions |
limit | number | Max sessions to return |
offset | number | Pagination offset |
Returns: Promise<CoderSessionListResponse>
deleteSession(sessionId)
Permanently delete a session.
Returns: Promise<void>
await client.deleteSession('codesess_abc123');archiveSession(sessionId)
Archive an active session. Session history remains available for replay and inspection.
Returns: Promise<CoderLifecycleResponse>
await client.archiveSession('codesess_abc123');resumeSession(sessionId)
Wake a paused sandbox session.
Returns: Promise<CoderLifecycleResponse>
await client.resumeSession('codesess_abc123');prepareSessionForRemoteAttach(sessionId, options?)
Ensure a paused remote session is attachable before opening a controller socket. If the session is history-only, returns immediately. If the session is wakeable and the runtime is unavailable, calls resumeSession and polls getSession until the runtime is back or the timeout elapses.
| Param | Type | Required | Description |
|---|---|---|---|
sessionId | string | yes | Session identifier |
options.timeoutMs | number | no | Max time to wait for the runtime to come back. Default 30000 |
options.pollIntervalMs | number | no | Interval between getSession polls while waking. Default 1000 |
Returns: Promise<CoderSession>. Returns the latest session detail, which may still be detached if the timeout elapsed.
const session = await client.prepareSessionForRemoteAttach('codesess_abc123', {
timeoutMs: 60_000,
});
if (session.runtimeAvailable) {
// Safe to open the controller socket
}Session Data
getReplay(sessionId, params?)
Retrieve the data a late-joining client uses to catch up to the session's current state.
| Param | Type | Required | Description |
|---|---|---|---|
sessionId | string | yes | Session identifier |
params.limit | number | no | Max records to return |
params.offset | number | no | Pagination offset |
Returns: Promise<CoderSessionReplay>
const replay = await client.getReplay('codesess_abc123');Use getReplay() when a late-joining client needs to catch up to the Hub's current state. For a structured timeline, use listEventHistory() instead.
listParticipants(sessionId, params?)
List participants for a session (primary agents, sub-agents, and observers).
Returns: Promise<CoderSessionParticipants>
const { participants } = await client.listParticipants('codesess_abc123');listEventHistory(sessionId, params?)
List historical events for a session.
| Param | Type | Required | Description |
|---|---|---|---|
sessionId | string | yes | Session identifier |
params.limit | number | no | Max events to return |
params.offset | number | no | Pagination offset |
Returns: Promise<CoderSessionEventHistory>
const history = await client.listEventHistory('codesess_abc123', { limit: 50 });Loop State
getLoopState(sessionId, params?)
Get loop-mode state for an autonomous session. Returns null loop when the session is not in loop mode.
Returns: Promise<CoderLoopStateResponse>
const { loop } = await client.getLoopState('codesess_abc123');
if (loop) {
console.log(`Status: ${loop.status}, iteration ${loop.iteration}`);
}The loop state includes status, iteration, maxIterations, goal, summary, nextAction, and timing fields. Status values: idle, starting, running, paused, completed, cancelled, blocked, awaiting_input.
Workspaces
Workspaces group repositories and skills into reusable configurations attachable to sessions.
createWorkspace(body)
Create a reusable workspace definition. A workspace cannot be empty: include at least one repo, saved skill, skill bucket, or agent selection.
| Param | Type | Required | Description |
|---|---|---|---|
body.name | string | yes | Workspace name |
body.description | string | no | Workspace description |
body.scope | 'user' | 'org' | no | Ownership scope |
body.repos | CoderSessionRepositoryRef[] | no | Repositories to include |
body.savedSkillIds | string[] | no | Saved skill IDs |
body.skillBucketIds | string[] | no | Skill bucket IDs |
body.enabledAgents | string[] | no | Built-in or custom agent roster to store on the workspace |
Returns: Promise<CoderWorkspaceDetail>
const workspace = await client.createWorkspace({
name: 'Auth System',
description: 'OAuth and session management',
enabledAgents: ['builder', 'reviewer'],
});listWorkspaces()
List all available workspaces.
Returns: Promise<CoderWorkspaceListResponse>
getWorkspace(workspaceId)
Retrieve a workspace by ID.
Returns: Promise<CoderWorkspaceDetail>
deleteWorkspace(workspaceId)
Delete a workspace.
Returns: Promise<void>
Custom Agents
listCustomAgents(options?)
List custom agents in the organization library.
options fields (all optional):
| Field | Type | Description |
|---|---|---|
includeArchived | boolean | Include archived custom agents |
Returns: Promise<CoderCustomAgentListResponse>
getCustomAgent(agentIdOrSlug)
Retrieve a custom agent by ID or slug.
Returns: Promise<CoderCustomAgent>
createCustomAgent(body)
Create a new custom-agent draft.
| Param | Type | Required | Description |
|---|---|---|---|
body.slug | string | yes | Stable custom agent slug |
body.displayName | string | yes | Human-readable custom agent name |
body.instructions | string | yes | Standalone custom-agent system prompt |
body.description | string | no | Optional description |
body.model | string | no | Optional model override |
body.thinkingLevel | 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | no | Optional thinking level override |
body.headlessCompatible | boolean | no | Whether the custom agent is safe for non-interactive callers |
body.tools | CoderCustomAgentTool[] | no | Workspace tools to grant |
body.serviceTools | CoderCustomAgentServiceTool[] | no | Service tools to grant |
body.savedSkillIds | string[] | no | Saved skill IDs to snapshot onto the custom agent |
body.companionAgents | string[] | no | Agent names to auto-include alongside this custom agent |
Returns: Promise<CoderCustomAgent>
updateCustomAgent(agentIdOrSlug, body)
Update an existing custom-agent draft. All body fields are optional; nullable fields such as description, model, and thinkingLevel can be set to null to clear them.
Returns: Promise<CoderCustomAgent>
publishCustomAgent(agentIdOrSlug)
Publish the latest draft as an immutable custom-agent version.
Returns: Promise<CoderCustomAgent>
archiveCustomAgent(agentIdOrSlug)
Archive a custom agent from the organization library.
Returns: Promise<CoderCustomAgent>
listCustomAgentVersions(agentIdOrSlug)
List published versions for a custom agent.
Returns: Promise<CoderCustomAgentVersionListResponse>
Skills
saveSkill(body)
Save a reusable skill to the caller's library.
| Param | Type | Required | Description |
|---|---|---|---|
body.repo | string | yes | Repository identifier for the skill |
body.skillId | string | yes | Skill identifier within the repository |
body.name | string | yes | Human-readable name |
body.description | string | no | Skill description |
body.url | string | no | Canonical skill URL |
body.source | string | no | Skill source (default: 'registry') |
body.content | string | no | Inline skill content |
Returns: Promise<CoderSavedSkill>
const skill = await client.saveSkill({
repo: 'my-org/my-skills',
skillId: 'code-review',
name: 'code-review',
description: 'Review code for security issues',
content: 'Review the changes for OWASP top 10 vulnerabilities...',
});listSavedSkills()
List saved skills in the caller's library.
Returns: Promise<CoderSavedSkillListResponse>
deleteSavedSkill(skillId)
Delete a saved skill.
Returns: Promise<void>
createSkillBucket(body)
Group saved skills into a bucket that can be attached to sessions.
| Param | Type | Required | Description |
|---|---|---|---|
body.name | string | yes | Bucket name |
body.description | string | no | Bucket description |
body.savedSkillIds | string[] | no | Saved skill IDs to include |
Returns: Promise<CoderSkillBucket>
listSkillBuckets()
List all skill buckets.
Returns: Promise<CoderSkillBucketListResponse>
deleteSkillBucket(bucketId)
Delete a skill bucket.
Returns: Promise<void>
GitHub
listGitHubAccounts()
List GitHub accounts available via the caller's GitHub App installations. Sign in to Agentuity before calling this method. Without an Agentuity OAuth login, the Hub returns HTTP 409 and the client throws before it can return account data.
Returns: Promise<CoderGitHubAccountListResponse>
try {
const { connected, accounts } = await client.listGitHubAccounts();
if (!connected) {
console.log('Connect GitHub in the Agentuity Console first');
} else {
console.log(accounts.map((account) => account.accountName));
}
} catch {
console.log('Sign in to Agentuity first, then call listGitHubAccounts() again');
}listGitHubRepos(accountId)
List repositories accessible under a specific GitHub account.
| Param | Type | Required | Description |
|---|---|---|---|
accountId | string | yes | GitHub account ID from listGitHubAccounts |
Returns: Promise<CoderGitHubRepositoryListResponse>
const { repositories } = await client.listGitHubRepos('12345');Users
listUsers(params?)
List known users in the Coder Hub. Supports search and pagination.
params fields (all optional):
| Field | Type | Description |
|---|---|---|
search | string | Search query to filter by display name |
limit | number | Max users to return |
offset | number | Pagination offset |
Returns: Promise<CoderListUsersResponse>
const { users } = await client.listUsers({ search: 'alice', limit: 10 });Next Steps
- Coder: Concepts, session lifecycle, and workflow guidance
@agentuity/coderPackage: Install and constructor overview- Coder CLI Commands: Full
agentuity codercommand reference