claudecode

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 22 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 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

View Source
const AgentBinary = "claude"

AgentBinary is the name `executor.LookPath` searches for during detection. Adapter-private.

View Source
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

func New(home, binaryPath string) *Adapter

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

func (a *Adapter) DecideResponse(ev *event.Event, d adapter.Decision) adapter.HookResponse

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

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

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

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) Name

func (a *Adapter) Name() string

Name returns the adapter agent name.

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

func (a *Adapter) ShellCommand(ev *event.Event) (cmd string, cwd string, ok bool)

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

func (a *Adapter) SupportedHooks() []event.HookEvent

SupportedHooks returns a fresh copy of the Claude-supported hook list. Callers may freely mutate the returned slice without affecting adapter internals.

func (*Adapter) Uninstall

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

Uninstall removes only DMG-owned hook entries. The settings file is preserved even when uninstall removes the last hook — leaving an empty {} (or whatever non-hook keys remain) keeps any user customization intact.

Jump to

Keyboard shortcuts

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