permissions

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package permissions implements Claude Code's permission gate.

Mirrors src/utils/permissions/permissions.ts and shellRuleMatching.ts.

A permission rule is a string like:

"Bash"              — allow/deny all Bash calls
"Bash(git log)"     — exact command match
"Bash(git log *)"   — prefix match (trailing space + * = prefix)
"Edit"              — all Edit calls
"Edit(/path/*)"     — path prefix match

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PersistAllow

func PersistAllow(rule, cwd string) error

PersistAllow writes rule to the allow list in <cwd>/.claude/settings.local.json. This is the "always allow" persistence path — mirrors TS localSettings destination. Uses raw-JSON map so unknown fields are preserved.

func SuggestRule

func SuggestRule(toolName, toolInput string) string

SuggestRule returns the broad rule string to use for "always allow". Mirrors TS suggestionForPrefix / createReadRuleSuggestion:

  • Read/Edit/Write: directory-level Read(//dir/**)
  • Bash: prefix wildcard Bash(cmd subcmd:*) or exact Bash(full command)
  • others: tool name only

Types

type Decision

type Decision int

Decision is the result of a permission check.

const (
	DecisionAllow Decision = iota
	DecisionDeny
	DecisionAsk
)

type Gate

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

Gate holds the active permission state for a session.

func New

func New(mode Mode, allow, deny, ask []string) *Gate

New constructs a Gate with the given settings.

func (*Gate) AllowForSession

func (g *Gate) AllowForSession(rule string)

AllowForSession adds a rule to the session-level allow list.

func (*Gate) Check

func (g *Gate) Check(toolName, toolInput string) Decision

Check determines whether toolName with toolInput may run. toolInput is the raw argument string (e.g. the command for Bash).

func (*Gate) Lists

func (g *Gate) Lists() (allow, deny, ask []string)

Lists returns copies of the allow, deny, and ask rule lists (excluding session-level allow). This is used for display in the /permissions slash command.

func (*Gate) Mode

func (g *Gate) Mode() Mode

Mode returns the current permission mode.

func (*Gate) SetMode

func (g *Gate) SetMode(m Mode)

SetMode changes the active permission mode.

type Mode

type Mode string

Mode is the active permission mode.

const (
	ModeDefault           Mode = "default"
	ModeAcceptEdits       Mode = "acceptEdits"
	ModeBypassPermissions Mode = "bypassPermissions"
	ModePlan              Mode = "plan"
)

Jump to

Keyboard shortcuts

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