Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add CLAUDE_CONFIG_DIR environment variable support #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ This plugin creates a WebSocket server that Claude Code CLI connects to, impleme
The protocol uses a WebSocket-based variant of MCP (Model Context Protocol) that:

1. Creates a WebSocket server on a random port
2. Writes a lock file to `~/.claude/ide/[port].lock` with connection info
2. Writes a lock file to `~/.claude/ide/[port].lock` (or `$CLAUDE_CONFIG_DIR/ide/[port].lock` if `CLAUDE_CONFIG_DIR` is set) with connection info
3. Sets environment variables that tell Claude where to connect
4. Implements MCP tools that Claude can call

Expand Down Expand Up @@ -176,7 +176,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).

## Troubleshooting

- **Claude not connecting?** Check `:ClaudeCodeStatus` and verify lock file exists in `~/.claude/ide/`
- **Claude not connecting?** Check `:ClaudeCodeStatus` and verify lock file exists in `~/.claude/ide/` (or `$CLAUDE_CONFIG_DIR/ide/` if `CLAUDE_CONFIG_DIR` is set)
- **Need debug logs?** Set `log_level = "debug"` in opts
- **Terminal issues?** Try `provider = "native"` if using snacks.nvim

Expand Down
12 changes: 11 additions & 1 deletion lua/claudecode/lockfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
local M = {}

--- Path to the lock file directory
M.lock_dir = vim.fn.expand("~/.claude/ide")
---@return string lock_dir The path to the lock file directory
local function get_lock_dir()
local claude_config_dir = os.getenv("CLAUDE_CONFIG_DIR")
if claude_config_dir and claude_config_dir ~= "" then
return vim.fn.expand(claude_config_dir .. "/ide")
else
return vim.fn.expand("~/.claude/ide")
end
end

M.lock_dir = get_lock_dir()

-- Track if random seed has been initialized
local random_initialized = false
Expand Down
8 changes: 6 additions & 2 deletions scripts/lib_claude.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# This library provides reusable functions for interacting with Claude Code's WebSocket API

# Configuration
export CLAUDE_LOCKFILE_DIR="$HOME/.claude/ide"
if [ -n "$CLAUDE_CONFIG_DIR" ]; then
export CLAUDE_LOCKFILE_DIR="$CLAUDE_CONFIG_DIR/ide"
else
export CLAUDE_LOCKFILE_DIR="$HOME/.claude/ide"
fi
export CLAUDE_LOG_DIR="mcp_test_logs" # Default log directory
export CLAUDE_WS_TIMEOUT=10 # Default timeout in seconds

Expand All @@ -13,7 +17,7 @@ export CLAUDE_WS_TIMEOUT=10 # Default timeout in seconds
# Find the Claude lockfile and extract the port
find_claude_lockfile() {
# Get all .lock files
lock_files=$(find ~/.claude/ide -name "*.lock" 2>/dev/null || echo "")
lock_files=$(find "$CLAUDE_LOCKFILE_DIR" -name "*.lock" 2>/dev/null || echo "")

if [ -z "$lock_files" ]; then
echo "No Claude lockfiles found. Is the VSCode extension running?" >&2
Expand Down