claude

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package claude is the Claude Code adapter: it starts sessions with claude -p and streamed JSON output, optionally under an id assigned by whoever starts them (--session-id, so the session keeps its log) or continuing one (--resume <id>, which works with -p, as claude --help shows, in the same directory the session ran in), and reads the result, the tokens and what the session cost from the stream. It warns when ANTHROPIC_API_KEY would take over the login, and names it when claude reports an invalid key. Its sessions' logs are read by claudelog.

Index

Constants

View Source
const Name = "claude-code"

Name is the agent's name as Physa records it.

Variables

This section is empty.

Functions

func InSession

func InSession(getenv func(string) string) bool

InSession reports whether the environment getenv reads marks the process as running inside a Claude Code session: CLAUDECODE or CLAUDE_CODE_SESSION_ID set to a non-empty value. The caller passes the environment's lookup, so the answer can be tested without the real environment.

func SettingsFile added in v0.0.17

func SettingsFile(home string) string

SettingsFile is where Claude Code reads a person's own settings, under the person's home, including the hooks it runs at the start of every session. Like SkillFile, it does not follow CLAUDE_CONFIG_DIR.

func SkillFile added in v0.0.15

func SkillFile(home, name string) string

SkillFile is where Claude Code reads a person's skill of that name, under the person's home: one SKILL.md in a directory named for the skill, per account.

Types

type Adapter

type Adapter struct {
	// Command is the claude command to run; empty means "claude" on PATH.
	Command string
	// Getenv reads the environment sessions inherit; nil means os.Getenv.
	Getenv func(string) string
}

Adapter runs sessions with the Claude Code command.

func New

func New() *Adapter

New returns an adapter that runs "claude" from PATH.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns "claude-code".

func (*Adapter) Start

func (a *Adapter) Start(ctx context.Context, s adapter.Spec) (adapter.Session, error)

Start runs claude -p in s.Dir with the prompt on stdin. An assigned session id that is not a UUID, and a resume without one, are refused before anything runs.

func (*Adapter) Usage added in v0.0.26

func (a *Adapter) Usage(ctx context.Context) (adapter.Usage, error)

Usage reads the plan's usage with claude -p /usage, run without ANTHROPIC_API_KEY, since /usage reports the login's plan. It needs a Claude Code that prints a usage_report; the text it also prints is never read.

func (*Adapter) Warnings added in v0.0.3

func (a *Adapter) Warnings() []string

Warnings warns when ANTHROPIC_API_KEY is set: claude then uses that key over the person's login, bills it, and fails every session if it is invalid.

func (*Adapter) Window

func (a *Adapter) Window() int

Window states 1,000,000 estimated tokens for one session.

Directories

Path Synopsis
Package claudelog is the Claude Code adapter's reader of session logs: it finds a session's transcript under Claude Code's config directory and returns what learning needs from it and its subagents, redacted, never writing anything there.
Package claudelog is the Claude Code adapter's reader of session logs: it finds a session's transcript under Claude Code's config directory and returns what learning needs from it and its subagents, redacted, never writing anything there.

Jump to

Keyboard shortcuts

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