Session env
Explain and verify how a Claude session pins itself (and all its n8nac workflow/instance commands) to exactly ONE n8n environment without clobbering other sessions' global active env. Use when the user asks "which env am I on", "how does session env pinning work", "pin this session to env X", "why was my env command blocked", or wants to verify env isolation. Reports the session-resolved env vs the shared global active, and can run the empirical isolation test.From its SKILL.md
npx -y skills add neurawork-git/n8n-autopilot --skill session-envAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 18 stars18 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.6 KB, as published. Nobody here has run it
Session Env Pinning — one session, one env, no cross-session clobber
The model (why this exists)
n8nac stores a machine-GLOBAL active environment (activeEnvironmentId in
~/n8nac-config.json), set by n8nac env use <name> / env pin. It is shared by
every shell and every Claude session on the machine. If two sessions each run
env use, the last one wins and silently re-points the other session's commands at
the wrong instance/project. That is the failure mode we prevent.
The rule: a session pins itself with the N8NAC_ENVIRONMENT env var — never with
env use. Instance-touching n8nac commands honour N8NAC_ENVIRONMENT (and the
per-call --env flag) and route to that env's instance without writing the global
active. So N sessions can target N different envs concurrently, and none disturbs
the others.
Three ways to resolve an env for a command (all session-scoped, none mutate global)
| Scope | How | When |
|---|---|---|
| Whole session (default) | .claude/settings.json → "env": { "N8NAC_ENVIRONMENT": "<name>" } | the normal per-repo pin — set once |
| Whole shell | export N8NAC_ENVIRONMENT=<name> | ad-hoc terminal work |
| One command | npx n8nac --env <name> <cmd> or N8NAC_ENVIRONMENT=<name> npx n8nac <cmd> | override for a single call |
.claude/settings.json in this repo pins the session via the env block — that value
is exported into every Bash tool call, so every n8nac command inherits it.
Enforcement (two hooks)
scripts/enforce-env.sh(PreToolUse / Bash) — fail-closed:- Any instance-touching
npx n8naccommand that resolves to no env (no--env, no inlineN8NAC_ENVIRONMENT=, no session$N8NAC_ENVIRONMENT) is BLOCKED (exit 2) — otherwise it would silently hit the shared global active. env use/env pinare BLOCKED unconditionally (clobber-guard) — they mutate the shared global. Bypass only for a deliberate machine-default change:N8N_AUTOPILOT_ALLOW_ENV_USE=1 npx n8nac env use <name>.- Local-only subcommands (
skills,convert,workspace,env list/status/...,setup,telemetry,update-ai,help) never touch an instance → never gated.
- Any instance-touching
scripts/report-session-env.sh(SessionStart) — prints the session's resolved env (name + host + project) up front, or warns if it is falling back to the shared global active (no session var set).
Known gotcha — workspace status is env-BLIND
npx n8nac workspace status always reflects the global active env and ignores
N8NAC_ENVIRONMENT / --env. For session-aware resolution use env status or
env list --json filtered by N8NAC_ENVIRONMENT. Routing of actual instance
calls (pull/push/list --remote/…) DOES honour the session var — only the
workspace status reporter is blind. (Empirically confirmed; see the test below.)
Verify it (this session)
# Which env does THIS session actually target (honours N8NAC_ENVIRONMENT)?
npx n8nac env status --json
# What is the shared global active (what un-pinned sessions get)?
npx n8nac env list --json | node -e "let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{const j=JSON.parse(d.slice(d.indexOf('{')));console.log('global active:',j.activeEnvironmentId)})"
If env status resolves a different env than the global active, the pin is working
exactly as intended — your session is isolated.
Extensive isolation test
scripts/test-env-isolation.sh is the empirical proof harness. It is read-only
against instances, never runs env use (the clobber op under test), captures the
global active at start, and re-asserts it is unchanged at the end. It checks:
N8NAC_ENVIRONMENTroutes each env to its own host.--envflag routes identically, independent of any session var.- SAFETY — global active is untouched by session-scoped resolution.
workspace statusenv-blindness (documents the gotcha).- The gate blocks no-env instance commands, allows resolved/local ones.
- The clobber-guard blocks
env use/env pinbut still allowsenv list/env status.
bash scripts/test-env-isolation.sh
# or pick the two envs explicitly:
ENV_A=dev ENV_B=prod bash scripts/test-env-isolation.sh
Expected: === 17 passed, 0 failed === and SAFETY OK: global active unchanged.
Propagation into Claude Workflows (build-workflow-v2 / build-stack-v2)
The v2 pipelines are JS Workflows that spawn agent() subagents (n8n-researcher,
n8n-author, n8n-validator, n8n-deployer, n8n-tester). Their scripts pass no
--env; the agent defs say "env is inherited, run every n8nac command bare." That
relies on N8NAC_ENVIRONMENT propagating session → Workflow runtime → subagent Bash.
Verified (5.0.0): a probe Workflow (a generic agent AND the real n8n-tester
agentType) both saw N8NAC_ENVIRONMENT, resolved the session env + host via
env status --json, and ran a bare instance command against the correct instance —
leaving the global active untouched. So the inherited-bare model is correct: do not
add --env inside pipeline agents, and never set the session pin via env use. If a
future session sets no N8NAC_ENVIRONMENT, subagents inherit none either → bare instance
commands are gated/ambiguous, exactly as in the main session (fail-closed, not silent).
Quick answers
- "Which env am I on?" →
npx n8nac env status --json(session-aware). - "Pin this session to X" → add
"N8NAC_ENVIRONMENT": "X"to.claude/settings.jsonenvblock (NOTenv use X). Verify withenv status --json. - "My command was blocked" → either no env resolved (set
N8NAC_ENVIRONMENTor pass--env), or you ranenv use/env pin(use the session var instead; bypass only for a real machine-default change). - "Switch the machine default for everyone" → that is
env use, intentionally guarded:N8N_AUTOPILOT_ALLOW_ENV_USE=1 npx n8nac env use <name>.