Skip to main content

Task Session Integration

Tasks that reference an Agent (agentRef) expose OpenCode session information in their status, enabling tracking of token usage, cost, and session details.

Session Info in Task Status

When a Task runs via an Agent (using agentRef), the controller populates the status.session field:

kubectl get task my-task -o jsonpath='{.status.session}'
{
"id": "abc123-session-id",
"url": "http://my-agent.kubeopencode-system.svc.cluster.local:4096",
"title": "Fix login timeout bug",
"summary": {
"messageCount": 15,
"tokenUsage": 45000,
"cost": 0.23,
"filesChanged": 3,
"additions": 120,
"deletions": 45
}
}

Session Fields

FieldTypeDescription
idstringOpenCode session identifier
urlstringFull URL to the session (for agentRef Tasks)
titlestringSession title set by OpenCode
summary.messageCountint64Total messages in the session
summary.tokenUsageint64Total tokens consumed
summary.costfloat64Estimated cost in USD
summary.filesChangedint64Number of files modified
summary.additionsint64Lines added
summary.deletionsint64Lines removed
info

The summary field is populated after the Task completes. It is not available during execution.

Template Tasks

Tasks that reference an AgentTemplate (templateRef) create ephemeral standalone Pods. These Tasks do not have session info in their status — the session field is only populated for agentRef tasks.

Querying Session Info

Get session details

kubectl get task my-task -o jsonpath='{.status.session}' | jq

Get token usage

kubectl get task my-task -o jsonpath='{.status.session.summary.tokenUsage}'

Get cost

kubectl get task my-task -o jsonpath='{.status.session.summary.cost}'

List tasks sorted by cost

kubectl get tasks -o custom-columns=NAME:.metadata.name,COST:.status.session.summary.cost