Skip to content

Conversation

@ramarivera
Copy link

@ramarivera ramarivera commented Dec 31, 2025

Summary

  • Adds support for CLAUDE_CONFIG_DIR environment variable
  • Falls back to ~/.config/claude (new Claude Code default) then ~/.claude (legacy)
  • Fixes ENOTDIR error when ~/.claude is a file instead of directory

Fixes #6551

Changes

  • Added CLAUDE_CONFIG_DIR to Flag namespace
  • Added Global.claudeConfigDir() function with proper fallback logic
  • Updated system.ts to use dynamic path for CLAUDE.md
  • Updated skill.ts to use dynamic path for skills directory
  • Added unit tests for the new logic

Testing

  • Added unit tests covering all fallback scenarios (8 tests, all passing)
  • Manually tested with CLAUDE_CONFIG_DIR set to custom path

- Add CLAUDE_CONFIG_DIR to Flag namespace
- Add Global.claudeConfigDir() function with proper fallback logic:
  1. CLAUDE_CONFIG_DIR env var (if set and is a directory)
  2. ~/.config/claude (new Claude Code default)
  3. ~/.claude (legacy path)
- Update system.ts to use dynamic path for CLAUDE.md
- Update skill.ts to use dynamic path for skills directory
- Add unit tests for claudeConfigDir logic

This fixes compatibility with Claude Code v1.0.30+ which changed
the default config directory from ~/.claude to ~/.config/claude.
Comment on lines 13 to 15
async function isDirectory(p: string): Promise<boolean> {
const stat = await fs.stat(p).catch(() => undefined)
return stat?.isDirectory() ?? false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer Bun apis, see style guide

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thanks for the speedy review <3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigated Bun APIs - Bun.file().exists() returns false for directories, so there is no Bun-native way to check if a path is a directory. The fs.stat approach is necessary and consistent with other directory operations in this file (fs.mkdir, fs.readdir, fs.rm). Implemented by Claude (claude-opus-4-5-thinking).

Copy link
Collaborator

@rekram1-node rekram1-node Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have u seen stats method for a bun file? see other locations in our codebase there is an isDirectory check

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a bun installation problem, one min

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@rekram1-node
Copy link
Collaborator

/review

const envDir = process.env.CLAUDE_CONFIG_DIR
if (envDir && (await isDirectory(envDir))) return envDir

const xdgPath = process.env.XDG_CONFIG_HOME || path.join(Path.home, ".config")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const xdgPath = process.env.XDG_CONFIG_HOME || path.join(Path.home, ".config")

Whats the purpose of this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I particularly have my XDG vars set to "standard" values, but in theory (and maybe windows?) you could set them to any directory and most linux/macos software "should" honor them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rekram1-node 👋🏻 Did I answer your question?

- packages/opencode/src/global/index.ts
- packages/opencode/test/global/claude-config-dir.test.ts
@ramarivera
Copy link
Author

Hey @rekram1-node 👋🏻
Could you let me know if this PR is still worth merging (it is to me at least), but would like to know before trying to solve merge conflicts, or I just close it. Thanks

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.

opencode doesn't respect CLAUDE_CONFIG_DIR environment variable

2 participants