A shell profile can reset a sandbox env var inside a Claude Code Bash tool
Symptom#
A sandboxed claude -p test that set RKB_HOME to a temp copy still wrote lessons into the real knowledge base; the subagent's rkb add commits landed in ~/Personal/kb.
Cause#
Claude's Bash tool loads the user's fish profile, and ~/.config/fish/conf.d/env.fish resets RKB_HOME to the real path. Any env var that a shell profile also sets cannot isolate a test run inside a Claude Code Bash tool.
Fix#
Undo with git -C <kb> revert --no-edit <commits>, and isolate with a dedicated variable that no profile touches: rkb has RKB_TEST_HOME, which wins over RKB_HOME (then ~/Personal/kb). Only the knowledge-base root lookup in crates/rkb-core/src/kb.rs reads it, it is left out of user help, and the test helper unsets it so it cannot leak into other tests. An empty RKB_HOME="" now falls back to the default. Before a real-agent end-to-end test, check that the sandbox path reaches the tool's shell, for example by having the agent print the variable.
Evidence#
rkb end-to-end testing; the fish profile was the culprit.
Also found by searching
- sandboxed claude -p test set RKB_HOME to a temp copy still wrote lessons into the real knowledge base
- fish profile resets RKB_HOME to the real path
- commits landed in ~/Personal/kb from a test run
- env var that a shell profile also sets cannot isolate a test run