Agent Session Reporting
List agent sessions, read their transcripts and trace comments, and pull usage and analytics
Overview
An agent session is one AI agent run: a Claude Code, Codex, or other harness session that Closedloop collected. These tools let an MCP client enumerate sessions, read a session's archived transcript files and trace comments, and pull the same usage and analytics aggregates the Sessions page shows.
| Tool | Purpose |
|---|---|
list-agent-sessions | List individual sessions with harness, model, repository, tokens, cost, and status |
get-agent-session-transcript | Get short-lived signed URLs to a session's archived transcript files |
get-agent-session-usage | Aggregated usage: session count, tokens, estimated cost, and breakdowns |
get-agent-session-analytics | Breakdowns by tool, agent type, repository, and project |
list-session-comments | List the trace comments on one session |
Scope: every tool on this page requires the read scope. A session whose credential lacks read is not offered these tools.
All five tools are read-only. The API scopes every read to your organization and to the viewer scope (self, team, or organization) you are authorized for. Requesting viewerScope: "team" for a team you may not read returns a 403.
Errors: a failed call returns an MCP tool result with isError: true whose text gives a title, a description, any remediation steps, and the error's code, message, and timestamp. Input that fails the parameter schema is rejected by the MCP SDK before any API call.
Shared reporting filters
get-agent-session-usage and get-agent-session-analytics take the same optional filters. list-agent-sessions takes these plus status, userId, limit, and offset.
| Name | Type | Required | Description |
|---|---|---|---|
startDate | string | No | ISO 8601 date or timestamp (e.g. 2026-07-01). Keeps sessions whose lastActivityAt is on or after it. |
endDate | string | No | ISO 8601 date or timestamp. Keeps sessions whose lastActivityAt is on or before it. |
harness | string | No | A single agent harness, e.g. "claude-code" or "codex". |
quality | "substantive" | "idle" | "all" | No | Defaults to "substantive", which hides idle sessions (0 turns, 0 tokens, and 0 tool uses). "all" includes them; "idle" returns only idle sessions. |
viewerScope | "self" | "organization" | "team" | No | Visibility scope. Defaults to the widest scope you are authorized for. |
teamId | string (UUID) | Conditional | Required when viewerScope is "team"; must be omitted for any other scope. |
startDate and endDate are an activity window on lastActivityAt, not a start-date filter. A session that started before startDate is included when its last activity falls inside the window. A session that was active inside the window and again after endDate is excluded, because only its final lastActivityAt is tested.
The MCP tools send quality: "substantive" when you omit it. The REST API's own default is all, so a direct API call without quality counts idle sessions that these tools hide.
List Agent Sessions
Tool: list-agent-sessions
Scope: read
Underlying API: GET /agent-sessions
Lists individual sessions. The API applies limit and offset and sorts by most recent activity.
list-agent-sessions(
startDate?: string, // ISO 8601 date/timestamp — activity window on lastActivityAt (on or after)
endDate?: string, // ISO 8601 date/timestamp — activity window on lastActivityAt (on or before)
harness?: string, // Single agent harness (e.g. "claude-code", "codex")
status?: string, // "active" | "inactive" | "error" — "inactive" covers finished (non-failed) runs
userId?: string, // UUID — filter to sessions whose Owner (assignee) is this user
quality?: string, // "substantive" | "idle" | "all" — defaults to "substantive" (hides idle 0-turn/0-token/0-tool sessions)
viewerScope?: string, // "self" | "organization" | "team"
teamId?: string, // UUID — required when viewerScope is "team", omit otherwise
limit?: number, // Maximum sessions to return (1-100)
offset?: number // Starting offset for pagination (0-10000, default 0)
)| Name | Type | Required | Description |
|---|---|---|---|
startDate, endDate, harness, quality, viewerScope, teamId | No | See Shared reporting filters. | |
status | string | No | One session status to filter on. Use "inactive" to find finished runs. |
userId | string (UUID) | No | Only sessions whose Owner (assignee) is this user. |
limit | integer | No | 1–100. When omitted, the API returns 25. |
offset | integer | No | 0–10000. Default 0. |
status is a free string so that an older client sending a retired value gets an empty page rather than a validation error. A value outside the three listed matches nothing.
The status on a returned row is derived when it is read, so it is not limited to the filter values. It can be waiting, stale, or unknown, and a value this build does not recognize comes back as unknown (or waiting when the row carries an awaiting-input marker and has not ended). Do not assume every returned status is one of the filter values.
Returns:
{
"items": [
{
"id": "11111111-1111-4111-8111-111111111111",
"slug": "SES-812",
"externalSessionId": "c0ffee00-...",
"name": "Fix the login redirect",
"status": "inactive",
"harness": "claude-code",
"model": "claude-opus-4-1",
"repositoryFullName": "acme/web",
"baseBranch": null,
"startedAt": "2026-07-01T09:12:00.000Z",
"lastActivityAt": "2026-07-01T10:02:00.000Z",
"endedAt": "2026-07-01T10:02:00.000Z",
"estimatedCost": 1.84,
"inputTokens": 120400,
"outputTokens": 18200,
"cacheReadTokens": 950000,
"cacheWriteTokens": 40100,
"agentCount": 2,
"toolUseCount": 64,
"errorCount": 0,
"sourceArtifactId": null,
"sourceLoopId": null,
"user": { "id": "...", "email": "dev@acme.com", "firstName": "Dana", "lastName": "Lee" },
"assignee": { "id": "...", "email": "dev@acme.com", "firstName": "Dana", "lastName": "Lee" }
}
],
"returned": 1,
"total": 214,
"viewerScope": "organization"
}idis the session's artifact UUID. Pass it toget-agent-session-transcriptandlist-session-comments.totalis the count of all matching sessions, not just this page. Page withoffsetuntiloffset + returnedreachestotal.baseBranchandsourceArtifactIdare alwaysnull. They are kept so existing clients that read them do not break.assigneeis the session's Owner.userrepeats the Owner for clients that read it under that name.assigneeis omitted when the API row omits it.- A field the API did not send, or sent with the wrong type, comes back as
null.
Example:
list-agent-sessions(status: "inactive", harness: "codex", limit: 10)Get Agent-Session Transcript
Tool: get-agent-session-transcript
Scope: read
Underlying API: GET /agent-sessions/{sessionId}/transcript
Returns read access to a session's archived transcript files: the main run file plus any subagent sidechain files.
| Name | Type | Required | Description |
|---|---|---|---|
sessionId | string (UUID) | Yes | The id from list-agent-sessions. The SES-* slug is not accepted. |
Returns one descriptor per transcript file:
{
"sessionId": "11111111-1111-4111-8111-111111111111",
"files": [
{
"fileKey": "main",
"availability": "available",
"url": "https://...signed-s3-get...",
"byteSize": 48213,
"rawSha256": "...",
"uploadedAt": "2026-07-01T10:00:00Z",
"lastObservedAt": "2026-07-01T10:00:05Z",
"permanentFailureReason": null
}
]
}| Field | Meaning |
|---|---|
fileKey | main for the primary run file, or subagent:{fileId} for a subagent sidechain. |
availability | available, stale, uploadPending, uploadFailed, permanentlyUnavailable, or missing. |
url | A signed S3 GET URL that expires about 5 minutes after it is issued. Non-null only when availability is available or stale. |
byteSize, rawSha256, uploadedAt | null until an upload has completed. |
lastObservedAt | When the file was last observed; null for a missing file. |
permanentFailureReason | Why a permanentlyUnavailable file was skipped (for example too_large); null otherwise. |
Fetch each non-null url directly to read the raw JSONL. If a URL expires before you finish, call the tool again for fresh ones.
Errors: 404 when no session with that id exists in your organization.
Example:
get-agent-session-transcript(sessionId: "11111111-1111-4111-8111-111111111111")Get Agent-Session Usage
Tool: get-agent-session-usage
Scope: read
Underlying API: GET /agent-sessions/usage
Takes only the shared reporting filters. Returns an aggregated usage summary over the matching sessions. Main fields:
| Field | Meaning |
|---|---|
viewerScope | The scope the aggregate was computed for. |
totalSessions | Number of matching sessions. |
earliestSessionAt, latestSessionAt | Earliest and latest session start among matches; null when nothing matches. |
totalInputTokens, totalOutputTokens, totalCacheReadTokens, totalCacheWriteTokens | Token totals. |
totalEstimatedCost, subscriptionEstimatedCost, apiEstimatedCost | Estimated cost, split into subscription-covered and API-key compute. |
byUser | Breakdown by Owner (the session's assignee). |
byHarness, byRepository | Breakdowns by harness and repository. |
byModel, byProject | Optional breakdowns, present when the API computes them. |
The response can carry further optional delivery fields (such as mergedPrCount and medianPrSize) when the API computes them. The tool returns the API's summary unchanged.
Because this tool takes neither status nor userId, its totals match list-agent-sessions only when the list is narrowed by the shared filters alone.
Example:
get-agent-session-usage(startDate: "2026-07-01", endDate: "2026-07-31", viewerScope: "organization")Get Agent-Session Analytics
Tool: get-agent-session-analytics
Scope: read
Underlying API: GET /agent-sessions/analytics
Takes only the shared reporting filters. Returns the API's analytics object unchanged:
| Field | Meaning |
|---|---|
viewerScope | The scope the analytics were computed for. |
byTool | Breakdown by tool. |
byAgentType | Breakdown by agent type. |
agentRosterIncomplete | Present only when byAgentType is a lower bound because some session's agent roster could not be fully read. Its absence means the breakdown is complete. |
byRepository, byProject | Breakdowns by repository and project. |
byBranch, byPr | Optional breakdowns by branch and pull request. |
Example:
get-agent-session-analytics(harness: "claude-code", quality: "all")List Session Comments
Tool: list-session-comments
Scope: read
Underlying API: GET /artifacts/{sessionId}/comments?surface=session_detail
Lists the trace comments on one session, each with its replies. The tool reads every page of the session's comments (100 threads per request), keeps only threads anchored to the trace, and then applies your limit and offset. It does not create, edit, resolve, or delete comments.
| Name | Type | Required | Description |
|---|---|---|---|
sessionId | string, 1–500 characters | One of sessionId or sessionUrl | The session's artifact UUID from list-agent-sessions, or the desktop-local external session id for a session with no cloud artifact. Slugs such as SES-123 are rejected, as is a value with leading or trailing whitespace. |
sessionUrl | string (URL) | One of sessionId or sessionUrl | A Closedloop session URL whose path ends in exactly one /sessions/{uuid}. |
computeTargetId | string (UUID) | No | Scopes an external sessionId to one of your devices. Omit it unless you have the right UUID: a wrong one returns 404 instead of searching across your sessions. |
status | "OPEN" | "RESOLVED" | No | Thread-state filter. |
limit | integer | No | 1–100. Default 25. |
offset | integer | No | 0 or more. Default 0. |
Provide exactly one of sessionId or sessionUrl; passing both or neither is an error.
Returns a paginated envelope:
{
"total": 3,
"offset": 0,
"limit": 25,
"returned": 3,
"hasMore": false,
"nextOffset": null,
"items": [
{
"id": "root-comment-id",
"threadId": "thread-id",
"body": "This retry loop never backs off.",
"status": "OPEN",
"resolvedAt": null,
"resolvedById": null,
"resolvedByName": null,
"resolvedByAvatarUrl": null,
"target": { "type": "session", "id": "11111111-1111-4111-8111-111111111111" },
"artifactId": "11111111-1111-4111-8111-111111111111",
"anchor": {
"anchorType": "text",
"traceId": "...",
"turnId": "...",
"row": 42,
"selectedText": "retry()",
"sourceText": "...",
"startOffset": 10,
"endOffset": 17,
"sessionId": "...",
"actor": null
},
"createdAt": "2026-07-01T10:05:00.000Z",
"updatedAt": "2026-07-01T10:05:00.000Z",
"editedAt": null,
"authorId": "...",
"authorName": "Dana Lee",
"authorAvatarUrl": null,
"replies": []
}
]
}Each item is a thread's root comment; replies holds the rest of the thread with the same author and timestamp fields. total counts every trace thread on the session that matched status.
Errors: a validation message for a missing, duplicated, or malformed sessionId/sessionUrl; the API's error when it cannot resolve the session; an error if the comment pages do not end within 100 requests.
Example:
list-session-comments(sessionId: "11111111-1111-4111-8111-111111111111", status: "OPEN")
list-session-comments(
sessionUrl: "https://app.closedloop.ai/acme/sessions/11111111-1111-4111-8111-111111111111"
)Workflow example
# 1. Find recent finished Codex runs
list-agent-sessions(status: "inactive", harness: "codex", limit: 5)
# 2. Take a row's `id` and read its transcript files
get-agent-session-transcript(sessionId: "<id>")
→ fetch each non-null `url` to read the raw JSONL
# 3. Read the open review comments on that run
list-session-comments(sessionId: "<id>", status: "OPEN")
# 4. Usage for one team in July
get-agent-session-usage(
startDate: "2026-07-01",
endDate: "2026-07-31",
viewerScope: "team",
teamId: "00000000-0000-0000-0000-000000000000"
)For the components (skills, subagents, commands, and others) these sessions invoke, see Agent Components.