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
- type Config
- func (c Config) BudgetHookScript() []byte
- func (c Config) CodexHookScript() []byte
- func (c Config) EditorScript(handoffDir string) []byte
- func (c Config) MCPConfig(port int, token string) []byte
- func (c Config) PermissionHookScript() []byte
- func (c Config) StatusHookScript() []byte
- func (c Config) StatuslineScript() []byte
- type Prompts
- type Result
- type Writer
- func (w *Writer) BudgetHookPath() string
- func (w *Writer) CodexHookPath() string
- func (w *Writer) CodexLauncher() (string, error)
- func (w *Writer) EditorEnv(path string) string
- func (w *Writer) EditorPath() string
- func (w *Writer) Ensure(port int, token string) (Result, error)
- func (w *Writer) EnsureEditor() (string, error)
- func (w *Writer) EnsureToken() (string, error)
- func (w *Writer) HandoffDir() string
- func (w *Writer) HookSettings() []byte
- func (w *Writer) HooksPath() string
- func (w *Writer) LauncherPath() string
- func (w *Writer) MCPConfigPath() string
- func (w *Writer) PermissionHookPath() string
- func (w *Writer) PortPath() string
- func (w *Writer) RemovePortFile() error
- func (w *Writer) StatusHookPath() string
- func (w *Writer) StatuslinePath() string
- func (w *Writer) TokenPath() string
Constants ¶
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.
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
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 ¶
CodexHookScript is what Codex runs for every hook: the payload goes to the runtime as it is, with the tmux session.
func (Config) EditorScript ¶
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 ¶
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
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 ¶
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 ¶
StatuslineScript is Claude's status line command: Claude's JSON goes to the runtime, the answer is the line shown.
type Prompts ¶
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 ¶
LoadPrompts reads the templates file.
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 (*Writer) BudgetHookPath ¶ added in v0.16.86
func (*Writer) CodexHookPath ¶
func (*Writer) CodexLauncher ¶
CodexLauncher writes the Codex launcher script when it differs and returns its path.
func (*Writer) EditorEnv ¶
EditorEnv is the environment prefix giving Claude the prompt editor at path.
func (*Writer) EditorPath ¶
func (*Writer) Ensure ¶
Ensure writes the port file (always) and every script and settings file whose content changed, at runtime start.
func (*Writer) EnsureEditor ¶
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 ¶
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 (*Writer) HookSettings ¶
HookSettings is the `--settings` file Claude is launched with.
func (*Writer) LauncherPath ¶
func (*Writer) MCPConfigPath ¶
func (*Writer) PermissionHookPath ¶ added in v0.16.86
func (*Writer) RemovePortFile ¶
RemovePortFile removes the port file at shutdown, so the scripts stop calling a runtime that is gone.