Coder Client — Agentuity Documentation

Coder Client

Manage AI coding sessions, workspaces, and skills with CoderClient

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.

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/coder
import { CoderClient } from '@agentuity/coder';
 
const client = new CoderClient();

Constructor

new CoderClient(options?: CoderClientOptions)

OptionTypeDefaultDescription
apiKeystringAGENTUITY_SDK_KEY env varAPI key for authentication
urlstringAuto-discoveredExplicit Hub base URL. Set to skip discovery
regionstringAGENTUITY_REGION or 'usc'Region used during discovery. Ignored when url or AGENTUITY_CODER_URL is set
orgIdstring-Organization scope for multi-tenant operations (optional)
loggerLoggerMinimal loggerCustom logger instance

The client resolves the Hub URL in this order:

  1. options.url (explicit)
  2. AGENTUITY_CODER_URL environment variable
  3. 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.

ParamTypeRequiredDescription
body.taskstringyesPrimary task prompt for the session
body.labelstringnoHuman-readable session label
body.agentstringnoDefault agent identifier
body.defaultAgentstringnoPreferred default agent identifier for routed session work
body.visibility'private' | 'organization' | 'collaborate'noSession visibility
body.workflowMode'standard' | 'loop'noWorkflow execution mode
body.loopCoderSessionLoopConfignoLoop-mode configuration (goal, maxIterations, autoContinue, allowDetached)
body.tagsstring[]noTags for filtering
body.enabledAgentsstring[]noBuilt-in or custom agent roster attached to the session
body.savedSkillIdsstring[]noSaved skill IDs to attach
body.skillBucketIdsstring[]noSkill bucket IDs to attach
body.skillsCoderSkillRef[]noInline skill definitions attached to the session
body.repoCoderSessionRepositoryRefnoPrimary repository to mount
body.reposCoderSessionRepositoryRef[]noMultiple repositories to mount
body.workspaceIdstringnoWorkspace to attach to the session
body.envRecord<string, string>noEnvironment variables injected into the runtime
body.metadataRecord<string, string>noArbitrary 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.

ParamTypeRequiredDescription
body.labelstringnoBuilder session label override
body.promptstringnoOptional focus prompt for the builder kickoff
body.mode'new' | 'edit' | 'from_session'noBuilder launch mode. Inferred from IDs when omitted
body.visibility'private' | 'organization' | 'collaborate'noBuilder session visibility
body.sourceSessionIdstringrequired for from_sessionSource session identifier
body.targetAgentIdstringrequired for edit unless targetAgentSlug is setTarget custom-agent ID
body.targetAgentSlugstringrequired for edit unless targetAgentId is setTarget custom-agent slug

Returns: Promise<CoderCreateSessionResponse>

getSession(sessionId)

Retrieve a session by ID.

ParamTypeRequiredDescription
sessionIdstringyesSession identifier

Returns: Promise<CoderSession>

const session = await client.getSession('codesess_abc123');

updateSession(sessionId, body)

Update an existing session.

ParamTypeRequiredDescription
sessionIdstringyesSession identifier
body.labelstringnoUpdated label
body.agentstringnoUpdated default agent
body.defaultAgentstringnoUpdated preferred default agent identifier
body.visibility'private' | 'organization' | 'collaborate'noUpdated visibility
body.workflowMode'standard' | 'loop'noUpdated workflow mode
body.loopCoderSessionLoopConfignoUpdated loop-mode configuration
body.tagsstring[]noUpdated tag set
body.enabledAgentsstring[]noUpdated session agent roster
body.skillsCoderSkillRef[]noUpdated attached skills for the session
body.metadataRecord<string, string>noUpdated 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):

FieldTypeDescription
searchstringSearch query across title, task, and metadata
includeArchivedbooleanInclude archived sessions
limitnumberMax sessions to return
offsetnumberPagination 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):

FieldTypeDescription
searchstringSearch query for connectable sessions
limitnumberMax sessions to return
offsetnumberPagination 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.

ParamTypeRequiredDescription
sessionIdstringyesSession identifier
options.timeoutMsnumbernoMax time to wait for the runtime to come back. Default 30000
options.pollIntervalMsnumbernoInterval 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.

ParamTypeRequiredDescription
sessionIdstringyesSession identifier
params.limitnumbernoMax records to return
params.offsetnumbernoPagination 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.

ParamTypeRequiredDescription
sessionIdstringyesSession identifier
params.limitnumbernoMax events to return
params.offsetnumbernoPagination 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.

ParamTypeRequiredDescription
body.namestringyesWorkspace name
body.descriptionstringnoWorkspace description
body.scope'user' | 'org'noOwnership scope
body.reposCoderSessionRepositoryRef[]noRepositories to include
body.savedSkillIdsstring[]noSaved skill IDs
body.skillBucketIdsstring[]noSkill bucket IDs
body.enabledAgentsstring[]noBuilt-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):

FieldTypeDescription
includeArchivedbooleanInclude 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.

ParamTypeRequiredDescription
body.slugstringyesStable custom agent slug
body.displayNamestringyesHuman-readable custom agent name
body.instructionsstringyesStandalone custom-agent system prompt
body.descriptionstringnoOptional description
body.modelstringnoOptional model override
body.thinkingLevel'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'noOptional thinking level override
body.headlessCompatiblebooleannoWhether the custom agent is safe for non-interactive callers
body.toolsCoderCustomAgentTool[]noWorkspace tools to grant
body.serviceToolsCoderCustomAgentServiceTool[]noService tools to grant
body.savedSkillIdsstring[]noSaved skill IDs to snapshot onto the custom agent
body.companionAgentsstring[]noAgent 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.

ParamTypeRequiredDescription
body.repostringyesRepository identifier for the skill
body.skillIdstringyesSkill identifier within the repository
body.namestringyesHuman-readable name
body.descriptionstringnoSkill description
body.urlstringnoCanonical skill URL
body.sourcestringnoSkill source (default: 'registry')
body.contentstringnoInline 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.

ParamTypeRequiredDescription
body.namestringyesBucket name
body.descriptionstringnoBucket description
body.savedSkillIdsstring[]noSaved 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.

ParamTypeRequiredDescription
accountIdstringyesGitHub 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):

FieldTypeDescription
searchstringSearch query to filter by display name
limitnumberMax users to return
offsetnumberPagination offset

Returns: Promise<CoderListUsersResponse>

const { users } = await client.listUsers({ search: 'alice', limit: 10 });

Next Steps