Documentation
¶
Overview ¶
Package takeover hands a Claude Code session's permission requests to the person's screen while the screen has taken the session over, and back to the session's own window when it has not.
The state is files in one folder, so the PermissionRequest hook reads it without beekeeper's state lock: a session is taken over while its flag (<session>.json, naming the screen's process) exists and that process runs. Only then does the hook hold a request: it writes it into the session's folder (<session>/<id>.request) and waits for the screen's answer beside it (<id>.answer). Every other request is decided at once with no decision, as before.
Index ¶
Constants ¶
const ( Allow = "allow" Deny = "deny" )
The behaviours a Decision has, as Claude Code's PermissionRequest hook output names them.
const GiveUp = 290 * time.Second
GiveUp is how long the hook holds a request for the screen: under the hook's own 300 s timeout, so the outcome is the hook's and never depends on Claude Code cancelling it.
const Poll = 250 * time.Millisecond
Poll is how often a held request looks for its answer and its flag.
Variables ¶
var ErrHandedBack = errors.New("the request is no longer held: it went back to the session's window")
ErrHandedBack is an answer to a request the hook no longer holds: it gave up, or the session's window answered it.
Functions ¶
func Answer ¶
Answer gives the held request id of session the screen's decision; a request no longer held is ErrHandedBack.
func Release ¶
Release hands session back: its held requests go to its own window at their next look.
func ReleaseOwned ¶
ReleaseOwned hands session back only if its flag still matches the exact generation the caller wrote. Replacement and removal share the same lock.
Types ¶
type Decision ¶
type Decision struct {
Behavior string `json:"behavior"`
// Message tells the model why a request was denied.
Message string `json:"message,omitempty"`
}
Decision is the screen's answer to a request.
func Hold ¶
func Hold(ctx context.Context, dir string, r Request, alive func(pid int) bool, poll time.Duration) (d Decision, ok bool, err error)
Hold holds r for the screen until it answers, its flag goes or its screen stops, or ctx ends (the caller's GiveUp). Release and decision acceptance serialize on the session lock: an invalidation observed before consumption wins over a queued answer. A replacement flag starts a new takeover and cannot revive this hold. Request finalization holds the same lock as Answer, so an answer cannot be published after cleanup.
type Flag ¶
type Flag struct {
// PID is the screen's process: a flag whose process is gone is no
// take-over.
PID int `json:"pid"`
By string `json:"by"`
Since time.Time `json:"since"`
}
Flag says a screen has taken a session over.