Skip to content

feat(config): respect CLAUDE_CONFIG_DIR environment variable#4

Open
moiri-gamboni wants to merge 1 commit intofrmoretto:mainfrom
moiri-gamboni:respect-claude-config-dir
Open

feat(config): respect CLAUDE_CONFIG_DIR environment variable#4
moiri-gamboni wants to merge 1 commit intofrmoretto:mainfrom
moiri-gamboni:respect-claude-config-dir

Conversation

@moiri-gamboni
Copy link
Copy Markdown

Summary

Claude Code supports CLAUDE_CONFIG_DIR for overriding the default ~/.claude configuration directory. Hardstop currently hardcodes ~/.claude in 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) resolve CLAUDE_CONFIG_DIR at 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 into settings.json and 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: Resolve CLAUDE_CONFIG_DIR with tilde expansion and trailing slash stripping; rewrite paths in installed skill file
  • install.sh / uninstall.sh: Use ${CLAUDE_CONFIG_DIR:-$HOME/.claude}
  • install.ps1: Use $env:CLAUDE_CONFIG_DIR with fallback
  • hooks/pre_tool_use.py: Derive config dir from __file__ for safe-command whitelist regexes
  • commands/hs_cmd.py: Derive plugin dir from __file__ for version lookup
  • tests/: 7 new tests for path derivation and safe-pattern matching (the dynamic safe patterns were previously untested)

No behavior change when CLAUDE_CONFIG_DIR is unset.

🤖 Generated with Claude Code

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>
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