Skip to content

feat: support CLAUDE_CONFIG_DIR environment variable#6550

Closed
ramarivera wants to merge 4 commits into
anomalyco:devfrom
ramarivera:feat/CLAUDE_CONFIG_DIR
Closed

feat: support CLAUDE_CONFIG_DIR environment variable#6550
ramarivera wants to merge 4 commits into
anomalyco:devfrom
ramarivera:feat/CLAUDE_CONFIG_DIR

Conversation

@ramarivera

@ramarivera ramarivera commented Dec 31, 2025

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

@rekram1-node rekram1-node Dec 31, 2025

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

/review

Comment thread packages/opencode/src/flag/flag.ts Outdated
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

of XDG_CONFIG_HOME you mean? 🤔
https://specifications.freedesktop.org/basedir/latest/

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@ramarivera

Copy link
Copy Markdown
Author

Hey @thdxr + @rekram1-node 👋🏻
Anything I could do/help to get this one across the finish line? :)

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Apr 12, 2026
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