Repository navigation
Description
Bug description
An agent-facing shell cannot use a CLI tool the operator has authenticated via an
environment variable. The most common case is the GitHub CLI: gh works in the
operator's own terminal, but the identical command fails inside mecatl with an
authentication error, and the model then reports back that the human needs to log
in — when in fact the credential exists and mecatl removed it.
Root cause: internal/adapter/envscrub (DenyExact, IsSecretName) drops
GH_TOKEN and GITHUB_TOKEN by name, and the _TOKEN/_API_KEY/_SECRET
suffix patterns drop every other token-shaped variable as defence-in-depth. That
scrub is applied to every agent-facing runner — the main runner
(internal/app/build.go (buildCommandRunnerForRoot)), the hardened child
runners (newHardenedRunnerForRoot), and the forker's git
(internal/adapter/forker/forker.go) — so the behaviour is identical in the main
session and in subagents, team members, and parallel branches.
The scrub itself is correct and deliberate (security review "Finding B", issue
#375, docs/design/principles.md): an allow-all posture must not let a
prompt-injected agent echo $OPENROUTER_API_KEY. GH_TOKEN is genuinely
high-value, so this is not a request to stop scrubbing it. The gap is that there
is no way for an operator to deliberately grant a credential to the agent shell,
and no signal when a command fails because of the scrub.
Two distinct problems, either of which could be fixed independently:
- No opt-in. The denylist is compiled in. There is no config key, no flag,
and no per-session surface that lets an operator say "this shell may see
GH_TOKEN". The tradeoff is currently made for the operator, not by them. - The failure is silent and misattributed.
Scrubdrops variables without
a diagnostic, so the tool's own "not authenticated" message is the only
signal. The model reasonably concludes the human is logged out and asks them
to authenticate, which sends the operator to fix something that is not broken.
Nothing in the tool result, the operator log, or the Shell tool's spec
mentions that the harness removed a variable.
The documented behaviour is accurate but reads as a security guarantee rather
than a constraint the operator will hit
(user-docs/features/execution-environments.md,
user-docs/building/what-you-get/permissions.md), and it does not say what to do
when a legitimately-authenticated tool stops working.
Steps to reproduce
- Authenticate
ghvia an environment variable only — e.g. exportGH_TOKEN
from a shell startup file — with no~/.config/gh/hosts.ymlentry. - In a normal terminal, confirm
gh issue view <n> --repo <owner>/<repo>works. - Start mecatl in that environment and ask the agent to read the same issue.
Expected behavior
Either the command succeeds because the operator deliberately granted that
variable to agent shells, or it fails with an honest, attributable explanation
that names the harness as the cause so neither the model nor the operator is sent
to re-authenticate something that is already authenticated.
Actual behavior
gh runs, fails as unauthenticated, and the model asks the operator to log in.
Nothing attributes the failure to the env scrub. An operator whose gh auth
lives in ~/.config/gh/hosts.yml never sees this; one who uses a token
environment variable sees it every time and has no way to fix it short of
patching the binary.
Additional context
Design questions this needs answered before implementation (not decided here):
- What is the grant surface? An operator-tier allowlist of variable names
that overrides the denylist is the obvious shape, and it fits the existing
operator-tier-only precedent used forguardrails:andopenrouter:— a
project-tier file must not be able to hand itself a credential. Whether it is
a settings key, a flag, or both, and whether the grant is per-deployment or
per-session, is open. - Does the grant bind children? A read-only subagent summarising a hostile
web page is a materially different risk from the main session. The subagent
posture axis already distinguishes these (governance.Audience), so the grant
probably should too, rather than being global by default. - What does the operator see? A build-once posture line naming the granted
variables would make the decision visible, in the shape of the existing
guardrails: ON …line. - What does the model see? If the grant is refused or absent, a note on the
Shell tool's spec or in the failure path is the difference between the model
telling the operator the truth and the model inventing a login problem. This
is the "model-visible affordance needs a model-visible instruction" rule in
CLAUDE.md. - Is a name allowlist even the right primitive? Granting
GH_TOKENgrants it
to every command in the session, including whatever a prompt injection asks for
next. A narrower grant (per-command, or via a credential helper the agent
cannot read) would be safer and considerably more work.
Acceptance criteria are deliberately left open pending those decisions, but any
fix should preserve: the scrub stays the default for every variable not
explicitly granted; a project-tier config cannot grant anything; and the
mutation-tested oracle in internal/app/command_runner_secret_scrub_test.go
keeps proving that one policy governs every runner.
Environment
- OS/version: macOS
- Deployment shape: mecatui
Activity
jbeda commentedon Sep 15, 2026
I'm going to implement the override. Some restrictions in the version described in #1587:
MECATL_*and any of the provider API key env variables.Let me know if that works for you.
jbeda commentedon Sep 15, 2026
@aponcedeleonch Give it a test and let me know how it works for you!
aponcedeleonch commentedon Sep 16, 2026
@jbeda yep! working after creating
~/.config/mecatl/settings.yamland adding: