Documentation
¶
Overview ¶
Package claudecode implements the Adapter interface for Claude Code.
Detection is by `executor.LookPath("claude")`. Settings live at <home>/.claude/settings.json. The hook command DMG writes is `<binaryPath> _hook claude-code <hookEvent>` where binaryPath is the absolute, symlink-resolved DMG binary path resolved at install time.
Restore + Status are intentionally absent — see the package-level doc on adapter.Adapter for why the interface is trimmed.
Index ¶
- Constants
- type Adapter
- func (a *Adapter) DecideResponse(ev *event.Event, d adapter.Decision) adapter.HookResponse
- func (a *Adapter) Detect(ctx context.Context, exec executor.Executor) (adapter.DetectionResult, error)
- func (a *Adapter) Install(ctx context.Context) (adapter.InstallResult, error)
- func (a *Adapter) ManagedFiles() []adapter.ManagedFile
- func (a *Adapter) Name() string
- func (a *Adapter) ParseEvent(ctx context.Context, hookType event.HookEvent, raw []byte) (*event.Event, error)
- func (a *Adapter) ShellCommand(ev *event.Event) (cmd string, cwd string, ok bool)
- func (a *Adapter) SupportedHooks() []event.HookEvent
- func (a *Adapter) Uninstall(ctx context.Context) (adapter.UninstallResult, error)
Constants ¶
const AgentBinary = "claude"
AgentBinary is the name `executor.LookPath` searches for during detection. Adapter-private.
const AgentName = "claude-code"
AgentName is the identifier DMG uses for Claude Code on the wire and in the `_hook <agent>` invocation. Adapter-private; the runtime never compares against it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements adapter.Adapter for Claude Code.
State is set once at construction and never mutated. settingsPath is derived from home; binaryPath is the absolute DMG binary path the install handler resolved via internal/aiagents/cli.Resolve.
func New ¶
New constructs an Adapter for the given user home and resolved DMG binary path. Both arguments must be absolute; behavior with relative paths is undefined.
func (*Adapter) DecideResponse ¶
DecideResponse renders a generic Decision into Claude Code's wire format. Routing is hook-type-aware: only PreToolUse has a defined block path today (the policy stage is filtered to PreToolUse + Bash). Every other hook event renders the generic allow shape on both allow and (defensively) on block, so a stray block decision can never accidentally halt the agent.
func (*Adapter) Detect ¶
func (a *Adapter) Detect(ctx context.Context, exec executor.Executor) (adapter.DetectionResult, error)
Detect reports whether the Claude Code CLI is on $PATH. Settings file presence is NOT a gate — install creates the file from scratch when absent.
func (*Adapter) Install ¶
Install adds DMG-owned hooks for every supported hook event.
Idempotent: when every entry is already in place, no file is written and HooksKept enumerates every event. When any entry is added or refreshed, the entire settings file is pretty-printed to canonical 2-space indent — formatting in keys we did not touch is normalized once on edit, which is an acceptable trade-off for human readability of the result.
func (*Adapter) ManagedFiles ¶
func (a *Adapter) ManagedFiles() []adapter.ManagedFile
ManagedFiles reports the single Claude settings file the adapter mutates. Used by the install handler for the chown sweep under root.
func (*Adapter) ParseEvent ¶
func (a *Adapter) ParseEvent(ctx context.Context, hookType event.HookEvent, raw []byte) (*event.Event, error)
ParseEvent normalizes a Claude Code hook stdin payload into an event. The raw payload is REDACTED before being attached to the result; the original bytes never appear in the returned event.
func (*Adapter) ShellCommand ¶
ShellCommand extracts the redacted shell command from a Claude Code hook payload, if any. Returns the empty string when no shell command is present. The result has already been redacted.
func (*Adapter) SupportedHooks ¶
SupportedHooks returns a fresh copy of the Claude-supported hook list. Callers may freely mutate the returned slice without affecting adapter internals.