claudecode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package claudecode implements the event-level adapter for the Claude Code CLI. It reads append-only JSONL transcripts under each config root's projects/ tree, maps Anthropic-style usage (cache tokens additive), and deduplicates message replays (including sidechain replays) within a cycle.

CRITICAL: strictly read-only. Files are opened O_RDONLY; nothing under the agent's directories is created, locked, or modified.

Index

Constants

View Source
const ConfigDirEnv = "CLAUDE_CONFIG_DIR"

ConfigDirEnv names the environment variable that moves the Claude Code configuration root, and with it every transcript this adapter reads. It is exported because a caller that copies this process's discovery into another one - the systemd units internal/service writes - has to know that the environment, not the defaults, decided what gets collected.

Variables

This section is empty.

Functions

func New

func New() adapter.Adapter

New returns a Claude Code adapter.

Types

type Adapter

type Adapter struct{}

Adapter reads Claude Code usage transcripts.

func (Adapter) Capabilities

func (Adapter) Capabilities() model.ToolCapability

Capabilities declares what this project can say about Claude Code.

Cost is COMPUTED: nothing here calls SetCost, so every row is valued from the public rate card by collect.stampCost or left unpriced. Activity is an EXACT join because a tool_use block and the .message.usage it was billed under sit in the SAME message, so mintActivity can name the usage row that paid for each call.

func (Adapter) Collect

func (a Adapter) Collect(ctx context.Context, src adapter.Source) (adapter.Observation, error)

Collect walks <root>/projects/**/*.jsonl, parses every usage line, applies in-cycle dedup, and returns the surviving events with any per-file errors. A bad transcript does not discard observations from readable files.

func (Adapter) CollectIncremental

func (a Adapter) CollectIncremental(ctx context.Context, src adapter.Source, cp *model.SourceCheckpoint) (adapter.Observation, error)

CollectIncremental gates the whole root on a per-file size+mtime manifest: when no transcript under projects/ changed, the walk is stats only and no file is opened. Any change re-parses EVERY file — the deduper's sidechain consolidation spans all files of a root in one pass, so per-file tail reads would break cross-file dedup. Correctness of the full re-parse is carried by the persisted dedup keys (INSERT OR IGNORE collapses re-derived events).

func (Adapter) Discover

func (a Adapter) Discover(ctx context.Context, cfg adapter.DiscoverConfig) ([]adapter.Source, error)

Discover locates Claude Code config roots that contain a projects/ tree.

Resolution order:

  1. An explicit override (DiscoverConfig.Overrides[claude-code]), normalised.
  2. env CLAUDE_CONFIG_DIR (comma list), each entry normalised.
  3. BOTH <home>/.config/claude and <home>/.claude.

A path ending in /projects is normalised to its parent. A root is accepted only if <root>/projects/ exists as a directory. Results are path-deduped.

func (Adapter) DisplayName

func (Adapter) DisplayName() string

DisplayName returns the human-friendly name.

func (Adapter) ID

func (Adapter) ID() string

ID returns the stable tool identifier.

Jump to

Keyboard shortcuts

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