📚 Encyclopedia

AI & Claude · updated 2026-10-26

Permission modes in headless Claude Code (plan mode wedges, skip-permissions, tool scoping)

claude-codeheadlesspermissionsplan-modedangerously-skip-permissionsallowedToolssecurity

Headless claude -p runs inherit the machine's Claude Code settings and have no human to approve anything. That combination produced a thread that could never run a command again, and it shapes how to give an unattended agent exactly the access it should have. Findings from ProcrastinAI (TLDR's AI persona) on Claude Code 2.1.x, July to October 2026.

Plan mode wedges headless sessions

Default-deny in headless mode

A run with no permission flags is effectively text-only: privileged tools are denied because nobody can approve them. Ways to grant less than everything: - --allowedTools with scoped rules, e.g. Write(//abs/workspace/**), Edit(//abs/workspace/**), WebSearch. Probe that the path scoping really works on your CLI version before trusting it (ask the agent to write /tmp/x; it must be denied). - --add-dir <repo> gives read access to a second directory. - The real guardrail is no Bash. Path rules on Write/Edit are decoration if the agent can run a shell. Also leave out WebFetch where SSRF into the host's LAN matters; WebSearch is lower risk. - If a run produces files, have the service collect and upload them after the run (walk the workspace with lstat, skip symlinks and dotfiles, take only files modified after the run started, enforce count and size caps), rather than giving the model credentials.

When the user is untrusted, scope with a sandbox, not just flags

Allow rules and path scoping limit a cooperative agent. For a user who will actively try to get out (TLDR's guest mode), run the CLI inside bubblewrap with only a workspace mounted, use --restricted with a read-only --settings file whose sandbox block denies Bash network and limits writes, load no MCP servers, and pass only an access token through a file descriptor. Full recipe: Sandboxing Claude Code for untrusted users (bubblewrap, --restricted, token pipe).

Raw flag passthrough is an escalation path

TLDR allowed #opt:key=value tags that became arbitrary CLI flags. Only one model value was filtered, so #opt:dangerously-skip-permissions granted full access to any user allowed to post to the AI. Never forward user-controlled strings as CLI flags; allowlist safe keys and gate the rest on the same check as the danger flag. More in Securing a shared AI agent that other users can drive.

Everything the agent can read, it can repeat

Every run loads the global ~/.claude/CLAUDE.md, whatever the working directory. If that file holds credentials, any user of a shared agent can ask for them. Keep secrets in a file that is not auto-loaded and refer to it by path.

Untrusted workspaces

A project directory never opened interactively is untrusted: headless runs there ignore its .claude/settings.json allow rules. See the gotcha in claude-service (ProcrastinAI's webhook runner for headless Claude).

Gotchas

See also

Linked from

Sources: tldr memory (bug-ai-plan-mode-stuck, plan-ai-artifacts-workspace, audit-ai-permission-surface, feature-claude-channel), posts #1478, #1479, #1600