hooksetup

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 14 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 hooksetup writes the files the coding agents call the runtime through: the port file, the status hook and status line scripts Claude Code runs, the Codex hook script, the `--settings` file with the hooks, the MCP config, the prompt editor Claude gets as VISUAL, and the Codex launcher. Running agents keep the paths and scripts they were started with, so the file names and the scripts' curl contract stay as they were; what names the product (the data folder as scripts spell it, header names, the MCP server, the editor) comes from Config.

Index

Constants

View Source
const (
	PortFile           = "port"
	TokenFile          = "cli-token"
	StatusHookFile     = "status-hook.sh"
	StatuslineFile     = "statusline.sh"
	CodexHookFile      = "codex-hook.sh"
	BudgetHookFile     = "budget-hook.sh"
	PermissionHookFile = "permission-hook.sh"
	HooksFile          = "hooks.json"
	MCPConfigFile      = "preview-mcp.json"
	LauncherFile       = "codex-launcher.js"
	HandoffDir         = "prompt-handoff"
	BinDir             = "bin"
)

File names in the data folder; agents started earlier hold these paths.

View Source
const WorkspaceIDPlaceholder = "{{workspaceId}}"

WorkspaceIDPlaceholder stands for the workspace's id in a prompt template.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DataDir is the runtime's data folder (absolute).
	DataDir string
	// ScriptDataDir is the data folder as the scripts spell it, read by the shell at run time ("$HOME/.<name>"): the
	// scripts do not follow an overridden data folder, as before.
	ScriptDataDir string
	// TokenHeaders carry the CLI token in the scripts' requests, the current name first.
	TokenHeaders []string
	// MCPServer is the runtime's MCP server name, MCPPath its route; its header is TokenHeaders[0].
	MCPServer string
	MCPPath   string
	// Allow are the permissions granted in the hook settings (the MCP server under its current and former names).
	Allow []string
	// EditorName is the prompt editor script's file name under bin/, EditorTitle the name its comment gives it.
	EditorName  string
	EditorTitle string
	// Editor and Handoff, when set, are the editor script's path and its hand-off folder instead of the data folder's
	// bin/<EditorName> and prompt-handoff.
	Editor, Handoff string
	// HumanEditorVar is the variable the editor finds the person's own editor in.
	HumanEditorVar string
	// LegacyTmuxSocket: a pane on this server keys its hand-off file by pane id alone, on any other by socket and id.
	LegacyTmuxSocket string
	// Codex is what the Codex launcher script needs; nil writes none.
	Codex *codex.LauncherScriptConfig
	// Budget writes the script that applies the hub's limits (internal/budget) and puts it in the Claude hook
	// settings. Off, the files are as they were; it is on where a hub carries the runtime.
	Budget bool
	// AppsLiveHook is the live hook of the apps on UserPromptSubmit (claude.HookSettingsConfig.AppsLiveHook); "" for none.
	AppsLiveHook string
	// StatusHookCLI is the status hook's own program (claude.HookSettingsConfig.StatusCLI); "" leaves the script alone.
	StatusHookCLI string
	// VoiceGuardHook is the voice mode's PreToolUse hook (claude.HookSettingsConfig.VoiceGuardHook); "" for none.
	VoiceGuardHook string
	// BudgetFile is the limits file as the script spells it (`$HOME/.<name>/budget.json`); "" is the data folder's.
	BudgetFile string
}

Config names the product's parts.

func (Config) BudgetHookScript added in v0.16.86

func (c Config) BudgetHookScript() []byte

BudgetHookScript is what Claude and Codex run on a prompt and before a tool (`sh <script> <provider> <event>`): it asks the runtime whether the hub's limit lets the chat go on and prints the answer, which the CLI reads as the hook's output (a notice, or a stop). It is silent, and quick, while no list is held or the list's mode is off. The runtime being away never stops a chat.

func (Config) CodexHookScript

func (c Config) CodexHookScript() []byte

CodexHookScript is what Codex runs for every hook: the payload goes to the runtime as it is, with the tmux session.

func (Config) EditorScript

func (c Config) EditorScript(handoffDir string) []byte

EditorScript is the prompt editor Claude runs for Ctrl+G: a hand-off file the runtime left for the pane is appended to Claude's buffer, so the text counts as typed; without one the person's own editor opens.

func (Config) MCPConfig

func (c Config) MCPConfig(port int, token string) []byte

MCPConfig is the `claude --mcp-config` file: the runtime's MCP server on loopback with the token in its header.

func (Config) PermissionHookScript added in v0.16.86

func (c Config) PermissionHookScript() []byte

PermissionHookScript is what Claude's PermissionRequest runs: the request goes to the runtime, which answers once the person decided; what it prints is the hook's answer. Printing nothing, for any reason at all, leaves the decision to Claude's own dialog in the terminal.

func (Config) StatusHookScript

func (c Config) StatusHookScript() []byte

StatusHookScript is what Claude's lifecycle hooks run (`sh <script> <event>`): it reports the event, the tmux session, a notification's type and when the hook fired, in the background, and returns at once (a hook Claude cancels on its timeout under load would leave the tab unaware of the turn).

func (Config) StatuslineScript

func (c Config) StatuslineScript() []byte

StatuslineScript is Claude's status line command: Claude's JSON goes to the runtime, the answer is the line shown.

type Prompts

type Prompts map[string]string

Prompts are the per-workspace system prompts of the agent CLIs by provider ("claude", "codex"). Their text is the platform's own, so it comes from a file the deployment names: a JSON object of templates.

func LoadPrompts

func LoadPrompts(file string) (Prompts, error)

LoadPrompts reads the templates file.

func (Prompts) Text

func (p Prompts) Text(provider, workspaceID string) (string, bool)

Text is the provider's prompt for one workspace; false when there is no template for it.

func (Prompts) Write

func (p Prompts) Write(dataDir, workspaceID string) error

Write writes a workspace's prompt files (<dataDir>/workspaces/<id>/<provider>-prompt.md), each only when its text changed, as the previous runtime did on start and on a new workspace.

type Result

type Result struct {
	// CodexHookFailed: the Codex hook script could not be written; Codex launches report nothing (tell the person).
	CodexHookFailed bool
}

Result reports what Ensure could not write without failing the start.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer writes the files of one data folder.

func New

func New(cfg Config) *Writer

New writes into cfg.DataDir.

func (*Writer) BudgetHookPath added in v0.16.86

func (w *Writer) BudgetHookPath() string

func (*Writer) CodexHookPath

func (w *Writer) CodexHookPath() string

func (*Writer) CodexLauncher

func (w *Writer) CodexLauncher() (string, error)

CodexLauncher writes the Codex launcher script when it differs and returns its path.

func (*Writer) EditorEnv

func (w *Writer) EditorEnv(path string) string

EditorEnv is the environment prefix giving Claude the prompt editor at path.

func (*Writer) EditorPath

func (w *Writer) EditorPath() string

func (*Writer) Ensure

func (w *Writer) Ensure(port int, token string) (Result, error)

Ensure writes the port file (always) and every script and settings file whose content changed, at runtime start.

func (*Writer) EnsureEditor

func (w *Writer) EnsureEditor() (string, error)

EnsureEditor writes the prompt editor script (and its hand-off folder) once per process, replacing whatever an older release left, and returns its path; it fits claude.LaunchConfig.EditorScript. A failed write is tried again next time.

func (*Writer) EnsureToken

func (w *Writer) EnsureToken() (string, error)

EnsureToken is the CLI token the scripts send: the token file's, or a new random one written to it (0600).

func (*Writer) HandoffDir

func (w *Writer) HandoffDir() string

func (*Writer) HookSettings

func (w *Writer) HookSettings() []byte

HookSettings is the `--settings` file Claude is launched with.

func (*Writer) HooksPath

func (w *Writer) HooksPath() string

func (*Writer) LauncherPath

func (w *Writer) LauncherPath() string

func (*Writer) MCPConfigPath

func (w *Writer) MCPConfigPath() string

func (*Writer) PermissionHookPath added in v0.16.86

func (w *Writer) PermissionHookPath() string

func (*Writer) PortPath

func (w *Writer) PortPath() string

Paths of the files.

func (*Writer) RemovePortFile

func (w *Writer) RemovePortFile() error

RemovePortFile removes the port file at shutdown, so the scripts stop calling a runtime that is gone.

func (*Writer) StatusHookPath

func (w *Writer) StatusHookPath() string

func (*Writer) StatuslinePath

func (w *Writer) StatuslinePath() string

func (*Writer) TokenPath

func (w *Writer) TokenPath() string

Jump to

Keyboard shortcuts

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