token

package
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package token reads Claude Code session JSONL files from agent volume mounts and aggregates token usage per agent. It is independent of the cost package — no pricing, no USD, just raw token counts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Timestamp    time.Time
	AgentName    string
	SessionID    string
	Model        string
	InputTokens  int64
	OutputTokens int64
	CacheRead    int64
	CacheCreate  int64
}

Entry represents a single token usage event from a JSONL session file.

func CollectAgent

func CollectAgent(agentsDir, agentName string) ([]Entry, error)

CollectAgent returns token entries for a single agent, useful for timeseries recording where individual timestamps matter.

func CollectAgentSince

func CollectAgentSince(agentsDir, agentName string, since time.Time) ([]Entry, error)

CollectAgentSince returns only entries after the given timestamp.

type Usage

type Usage struct {
	AgentName    string `json:"agent_name"`
	Model        string `json:"model"`
	InputTokens  int64  `json:"input_tokens"`
	OutputTokens int64  `json:"output_tokens"`
	CacheRead    int64  `json:"cache_read"`
	CacheCreate  int64  `json:"cache_create"`
	TotalTokens  int64  `json:"total_tokens"`
	Entries      int    `json:"entries"`
}

Usage represents aggregated token usage for a single agent.

func CollectAll

func CollectAll(agentsDir string) ([]Usage, error)

CollectAll scans all agent directories under agentsDir and returns aggregated token usage per agent. The expected layout is:

agentsDir/<agent>/claude/projects/*/*.jsonl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL