feat(config): respect CLAUDE_CONFIG_DIR environment variable#4
Open
moiri-gamboni wants to merge 1 commit intofrmoretto:mainfrom
Open
feat(config): respect CLAUDE_CONFIG_DIR environment variable#4moiri-gamboni wants to merge 1 commit intofrmoretto:mainfrom
moiri-gamboni wants to merge 1 commit intofrmoretto:mainfrom
Conversation
Claude Code supports CLAUDE_CONFIG_DIR for custom config locations (https://code.claude.com/docs/en/env-vars). Hardstop now works correctly when this is set. Approach: runtime Python files (hooks, commands) derive their location from __file__ rather than resolving the env var independently. This means the installers are the single entry point for CLAUDE_CONFIG_DIR resolution, and the runtime files just know where they are on disk. - bin/install.js: resolve CLAUDE_CONFIG_DIR with tilde expansion and trailing slash stripping; template paths into installed skill file - install.sh / uninstall.sh: use ${CLAUDE_CONFIG_DIR:-$HOME/.claude} for all path variables - hooks/pre_tool_use.py: derive _CLAUDE_DIR from __file__ for safe-command whitelist regexes - commands/hs_cmd.py: derive PLUGIN_DIR from __file__ - tests: verify safe-pattern derivation from file location Note: install.ps1 (PowerShell) not updated in this change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Claude Code supports
CLAUDE_CONFIG_DIRfor overriding the default~/.claudeconfiguration directory. Hardstop currently hardcodes~/.claudein all installers, hooks, and commands, so it can't install or run correctly when this variable is set.Approach
Installers (
bin/install.js,install.sh,install.ps1,uninstall.sh) resolveCLAUDE_CONFIG_DIRat install time, falling back to~/.claude.Runtime Python files (
hooks/pre_tool_use.py,commands/hs_cmd.py) derive their location from__file__rather than re-resolving the env var. Since the installer writes absolute paths intosettings.jsonand the skill file, the runtime scripts already know where they live on disk. This avoids duplicating normalization logic across languages and handles edge cases (env var not propagated to subprocesses) more robustly.Changes
bin/install.js: ResolveCLAUDE_CONFIG_DIRwith tilde expansion and trailing slash stripping; rewrite paths in installed skill fileinstall.sh/uninstall.sh: Use${CLAUDE_CONFIG_DIR:-$HOME/.claude}install.ps1: Use$env:CLAUDE_CONFIG_DIRwith fallbackhooks/pre_tool_use.py: Derive config dir from__file__for safe-command whitelist regexescommands/hs_cmd.py: Derive plugin dir from__file__for version lookuptests/: 7 new tests for path derivation and safe-pattern matching (the dynamic safe patterns were previously untested)No behavior change when
CLAUDE_CONFIG_DIRis unset.🤖 Generated with Claude Code