Documentation
¶
Overview ¶
Package hook is the Claude Code PreToolUse guard and its settings installer.
Index ¶
- Constants
- Variables
- func CheckBash(cmd string, o Options) []string
- func CheckContent(tool string, ti map[string]any, o Options) string
- func CheckFile(tool, p string, o Options) string
- func Evaluate(in Input, o Options) string
- func HookCommand(binary string) string
- func Run(r io.Reader, w io.Writer, o Options) error
- func SettingsPath() (string, error)
- func WatcherEnvsFor(dirs []string) []string
- type Decision
- type Input
- type Options
- type Result
Constants ¶
const BinaryName = "telegram-agent-cli"
BinaryName is the program the guard watches for.
const DefaultDeadline = 3 * time.Second
DefaultDeadline bounds one check; past it the hook asks instead of waiting.
const HookArgs = "hook claude-pretooluse"
HookArgs is what Claude Code runs after the binary path.
const HookTimeout = 10
HookTimeout is the per-call limit written on the guard entries (seconds).
Variables ¶
var Matchers = []string{"Bash|Monitor", "Read|Edit|Write|MultiEdit|NotebookEdit|Grep"}
Matchers are the PreToolUse matchers the guard is installed under.
Functions ¶
func CheckContent ¶
CheckContent returns why a file tool's written content needs the owner's OK.
func HookCommand ¶
HookCommand is the hook command line for a binary path.
func Run ¶
Run reads one PreToolUse payload from r and writes an "ask" decision to w when the call needs the owner's OK, or when the check does not finish within the deadline. Bad input produces no output.
func SettingsPath ¶
SettingsPath is $CLAUDE_CONFIG_DIR/settings.json or ~/.claude/settings.json.
func WatcherEnvsFor ¶
WatcherEnvsFor returns the watcher session variable names: the default plus watcher_session_env from each data dir's config.json.
Types ¶
type Decision ¶
type Decision struct {
HookSpecificOutput struct {
HookEventName string `json:"hookEventName"`
PermissionDecision string `json:"permissionDecision"`
PermissionDecisionReason string `json:"permissionDecisionReason"`
} `json:"hookSpecificOutput"`
}
Decision is the hook's stdout when it asks.
type Input ¶
type Input struct {
ToolName string `json:"tool_name"`
ToolInput map[string]any `json:"tool_input"`
Cwd string `json:"cwd"`
}
Input is the part of the Claude Code PreToolUse payload the guard reads.
type Options ¶
type Options struct {
DataDirs []string // data dirs to protect (absolute)
UserHome string // for ~ and $HOME forms
Cwd string // base for relative paths
ReadFile func(path string) ([]byte, error) // script files named in a command
// WatcherEnvs are the watcher session variable names (config watcher_session_env);
// the default name is always included.
WatcherEnvs []string
// XDGConfigHome is $XDG_CONFIG_HOME ("" = ~/.config).
XDGConfigHome string
// ClaudeConfigDir is $CLAUDE_CONFIG_DIR; ~/.claude and every .claude dir are always protected.
ClaudeConfigDir string
Deadline time.Duration // Run's time budget (DefaultDeadline if zero)
}
Options configures a check. Zero values fall back to the real environment.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions protects $TGAC_HOME (if set) and the default data dir.
type Result ¶
type Result struct {
Settings string `json:"settings"`
DryRun bool `json:"dry_run"`
Changed bool `json:"changed"`
Actions []string `json:"actions"`
Backup string `json:"backup,omitempty"`
Diff string `json:"diff"`
Result json.RawMessage `json:"result,omitempty"` // the new settings (dry run only)
}
Result reports an install/uninstall.