Documentation
¶
Overview ¶
Package claudecode provides the adapter for Claude Code integration.
Index ¶
- Constants
- Variables
- func Detect(ctx context.Context) (*agent.DetectionResult, error)
- func GetHookStatus(ctx context.Context) (*agent.HookStatus, error)
- func InstallHooks(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)
- func Register(registry *agent.Registry, privacyChecker *events.PrivacyChecker, ...)
- func UninstallHooks(ctx context.Context, opts agent.UninstallOptions) (*agent.UninstallResult, error)
- type Adapter
- func (a *Adapter) Detect(ctx context.Context) (*agent.DetectionResult, error)
- func (a *Adapter) DisplayName() string
- func (a *Adapter) Install(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)
- func (a *Adapter) Name() string
- func (a *Adapter) ParseEvent(ctx context.Context, hookType string, rawData []byte) (*events.Event, error)
- func (a *Adapter) Status(ctx context.Context) (*agent.HookStatus, error)
- func (a *Adapter) Uninstall(ctx context.Context, opts agent.UninstallOptions) (*agent.UninstallResult, error)
- type HookCommand
- type HookDecision
- type HookInput
- type HookMatcher
- type HookResponse
- type NotificationInput
- type PostToolUseInput
- type PreToolUseInput
- type SessionEndInput
- type SessionStartInput
- type Settings
- type SettingsHooks
- type SubagentStartInput
- type SubagentStopInput
- type TranscriptCollector
Constants ¶
const ( // AgentName is the machine identifier for Claude Code. AgentName = agent.AgentClaudeCode // DisplayName is the human-readable name for Claude Code. DisplayName = agent.DisplayClaudeCode )
Variables ¶
var HookTypes = []string{
"PreToolUse",
"PostToolUse",
"PostToolUseFailure",
"SessionStart",
"SessionEnd",
"Notification",
"SubagentStart",
"SubagentStop",
}
HookTypes are the hook types supported by Claude Code that we want to capture.
var ToolNameMapping = map[string]events.ActionType{ "Read": events.ActionFileRead, "View": events.ActionFileRead, "Write": events.ActionFileWrite, "Edit": events.ActionFileWrite, "NotebookEdit": events.ActionFileWrite, "Bash": events.ActionCommandExec, "Execute": events.ActionCommandExec, "WebSearch": events.ActionToolUse, "WebFetch": events.ActionToolUse, "Grep": events.ActionFileRead, "Glob": events.ActionFileRead, "LS": events.ActionFileRead, "Task": events.ActionToolUse, "TodoRead": events.ActionToolUse, "TodoWrite": events.ActionToolUse, "AskUser": events.ActionToolUse, }
ToolNameMapping maps Claude Code tool names to action types.
Functions ¶
func Detect ¶
func Detect(ctx context.Context) (*agent.DetectionResult, error)
Detect checks if Claude Code is installed on the system.
func GetHookStatus ¶
func GetHookStatus(ctx context.Context) (*agent.HookStatus, error)
GetHookStatus checks the current hook state.
func InstallHooks ¶
func InstallHooks(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)
InstallHooks installs hooks for Claude Code by modifying settings.json.
func Register ¶
func Register(registry *agent.Registry, privacyChecker *events.PrivacyChecker, loggingLevel config.LoggingLevel, contentHash bool)
Register adds this adapter to the given registry.
func UninstallHooks ¶
func UninstallHooks(ctx context.Context, opts agent.UninstallOptions) (*agent.UninstallResult, error)
UninstallHooks removes hooks from Claude Code.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements the agent.Adapter interface for Claude Code.
func New ¶
func New(privacyChecker *events.PrivacyChecker, loggingLevel config.LoggingLevel, contentHash bool) *Adapter
New creates a new Claude Code adapter.
func (*Adapter) DisplayName ¶
DisplayName returns the human-readable name.
func (*Adapter) Install ¶
func (a *Adapter) Install(ctx context.Context, opts agent.InstallOptions) (*agent.InstallResult, error)
Install installs hooks for Claude Code.
func (*Adapter) ParseEvent ¶
func (a *Adapter) ParseEvent(ctx context.Context, hookType string, rawData []byte) (*events.Event, error)
ParseEvent converts a Claude Code event to the common format.
func (*Adapter) Uninstall ¶
func (a *Adapter) Uninstall(ctx context.Context, opts agent.UninstallOptions) (*agent.UninstallResult, error)
Uninstall removes hooks from Claude Code.
type HookCommand ¶
HookCommand represents a hook command configuration.
type HookDecision ¶
type HookDecision int
HookDecision represents the decision for a Claude Code hook.
const ( // HookAllow allows the action to proceed (exit code 0). HookAllow HookDecision = iota // HookBlock blocks the action (exit code 2, message to stderr, shown to Claude). HookBlock // HookError is a non-blocking error (exit code 1, message to stderr, shown to user in verbose mode). HookError // HookGuidance allows the action but emits advisory text to stderr (exit code 0, stderr shown to user in verbose mode). // Used when a security check returns DecisionGuidance — advisory, not blocking. HookGuidance )
type HookInput ¶
type HookInput struct {
SessionID string `json:"session_id"`
TranscriptPath string `json:"transcript_path"`
Cwd string `json:"cwd"`
PermissionMode string `json:"permission_mode"`
HookEventName string `json:"hook_event_name"`
}
HookInput represents the common fields in all Claude Code hook inputs.
type HookMatcher ¶
type HookMatcher struct {
Matcher string `json:"matcher,omitempty"`
Hooks []HookCommand `json:"hooks"`
}
HookMatcher represents a matcher entry for a hook type.
type HookResponse ¶
type HookResponse struct {
// Decision is whether to allow, block, or report error.
Decision HookDecision
// Message is the reason (used for HookBlock and HookError).
Message string
}
HookResponse represents a response to Claude Code hooks.
func NewAllowResponse ¶
func NewAllowResponse() *HookResponse
NewAllowResponse creates a response that allows the action.
func NewBlockResponse ¶
func NewBlockResponse(message string) *HookResponse
NewBlockResponse creates a response that blocks the action with a reason. The message is shown to Claude.
func NewErrorResponse ¶
func NewErrorResponse(message string) *HookResponse
NewErrorResponse creates a non-blocking error response. The message is shown to the user in verbose mode, execution continues.
func NewGuidanceResponse ¶ added in v0.7.0
func NewGuidanceResponse(message string) *HookResponse
NewGuidanceResponse creates a non-blocking advisory response. Exit code 0 (allow); message shown to user in verbose mode. Used when a security check returns DecisionGuidance — advisory, not blocking.
func (*HookResponse) ExitCode ¶
func (r *HookResponse) ExitCode() int
ExitCode returns the exit code for this response. Exit code 0 = allow (or guidance), exit code 2 = block, exit code 1 = non-blocking error.
func (*HookResponse) Stderr ¶
func (r *HookResponse) Stderr() string
Stderr returns the message to write to stderr. Written for HookBlock (shown to Claude), HookError (verbose mode), and HookGuidance (advisory, verbose mode).
type NotificationInput ¶
type NotificationInput struct {
HookInput
Message string `json:"message"`
NotificationType string `json:"notification_type"`
}
NotificationInput represents the input for Notification hooks.
type PostToolUseInput ¶
type PostToolUseInput struct {
HookInput
ToolName string `json:"tool_name"`
ToolInput map[string]interface{} `json:"tool_input"`
ToolResponse map[string]interface{} `json:"tool_response"`
ToolUseID string `json:"tool_use_id"`
AgentID string `json:"agent_id,omitempty"`
AgentType string `json:"agent_type,omitempty"`
}
PostToolUseInput represents the input for PostToolUse and PostToolUseFailure hooks.
type PreToolUseInput ¶
type PreToolUseInput struct {
HookInput
ToolName string `json:"tool_name"`
ToolInput map[string]interface{} `json:"tool_input"`
ToolUseID string `json:"tool_use_id"`
AgentID string `json:"agent_id,omitempty"`
AgentType string `json:"agent_type,omitempty"`
}
PreToolUseInput represents the input for PreToolUse hooks.
type SessionEndInput ¶
SessionEndInput represents the input for SessionEnd hooks.
type SessionStartInput ¶
type SessionStartInput struct {
HookInput
Source string `json:"source"`
Model string `json:"model"`
AgentType string `json:"agent_type,omitempty"`
}
SessionStartInput represents the input for SessionStart hooks.
type Settings ¶
type Settings struct {
Hooks map[string][]HookMatcher `json:"hooks,omitempty"`
// Other fields preserved during read/write
Other map[string]interface{} `json:"-"`
}
Settings represents the Claude Code settings.json structure.
type SettingsHooks ¶
type SettingsHooks map[string][]HookMatcher
SettingsHooks represents the hooks section in settings.json.
func GenerateHooksConfig ¶
func GenerateHooksConfig() SettingsHooks
GenerateHooksConfig generates the hooks configuration for gryph.
type SubagentStartInput ¶ added in v0.7.0
type SubagentStartInput struct {
HookInput
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
}
SubagentStartInput represents the input for SubagentStart hooks.
type SubagentStopInput ¶ added in v0.7.0
type SubagentStopInput struct {
HookInput
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
StopHookActive bool `json:"stop_hook_active"`
AgentTranscriptPath string `json:"agent_transcript_path"`
LastAssistantMessage string `json:"last_assistant_message"`
}
SubagentStopInput represents the input for SubagentStop hooks.
type TranscriptCollector ¶ added in v0.4.0
type TranscriptCollector struct{}
TranscriptCollector implements cost.TokenCollector by parsing Claude Code transcript files.
func NewTranscriptCollector ¶ added in v0.4.0
func NewTranscriptCollector() *TranscriptCollector
func (*TranscriptCollector) Collect ¶ added in v0.4.0
func (c *TranscriptCollector) Collect(_ context.Context, transcriptPath string) (*cost.SessionUsage, error)
func (*TranscriptCollector) Source ¶ added in v0.4.0
func (c *TranscriptCollector) Source() cost.CostSource