Skip to content

agent: launches get one env policy, no API key unless named - #20

Merged
foxnne merged 2 commits into
mainfrom
chat/agent-env-policy
Oct 21, 2026
Merged

foxnne merged 2 commits into
mainfrom
chat/agent-env-policy

Conversation

@foxnne

@foxnne foxnne commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of fizzyedit/work#10

Linux and Windows spawned the agent with fizzy's whole environment, so a stray *_API_KEY could bill per token instead of the person's plan login. Now:

  • src/env.zig: child() copies the environment minus every *_API_KEY and ANTHROPIC_AUTH_TOKEN (case-insensitive), then adds back only the names the person listed. Agent.spawn passes it as environ_map.
  • Settings: use_api_key ("Use API key from environment", off by default) and api_key_vars (names only, never a value).
  • Status: the chat's "Starting ..." note ends with (plan login) or (API key: <VAR> forwarded); only names are ever printed.
  • Unit tests (zig build test, including one that spawns a real child and checks its environment, which fails if environ_map is dropped) fail if any *_API_KEY reaches the child by default, and check opt-in forwards only named variables and that status never contains a value.

Limits: the filter is name-based (*_API_KEY, ANTHROPIC_AUTH_TOKEN), so CLAUDE_CODE_OAUTH_TOKEN, AWS_BEARER_TOKEN_BEDROCK and *_APIKEY still pass; the opt-in list can name any variable, ANTHROPIC_AUTH_TOKEN included. Environ.Map compares names case-insensitively on Windows (checked in std, with a Windows-only test).

Not done: macOS still goes through core.darwin_spawn, whose fixed allowlist already carries no API key but cannot add the opt-in; that needs an env option in fizzy's darwin_spawn (a fizzy PR). The macOS status always says "plan login".

Verified on Windows 11: zig fmt, zig build, zig build test pass (SDK 0.2.32). The app was not launched, so the status note and settings rows were not seen on screen.

🤖 Generated with Claude Code

foxnne and others added 2 commits October 21, 2026 09:16
Linux and Windows inherited fizzy's whole environment, so a stray
ANTHROPIC_API_KEY could bill per token instead of the plan login. env.zig
strips every *_API_KEY (and ANTHROPIC_AUTH_TOKEN) from the child's
environment; "Use API key from environment" (off by default) forwards only
the variables named in "api_key_vars". The chat's start note says
"plan login" or "API key: <VAR> forwarded".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Policy struct carries the setting so "off" forwards nothing by construction;
env.spawn is the one place environ_map is set, with a test that spawns a
child and checks its environment; status allocates instead of truncating;
no file-scope buffer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@foxnne
foxnne marked this pull request as ready for review October 21, 2026 14:38
@foxnne
foxnne merged commit ea0323c into main Oct 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant