opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add .claude/commands/ compatibility for command discovery

Open SeanZoR opened this issue 3 months ago • 4 comments

Summary

Adds support for Claude Code compatible command paths, enabling seamless migration for users coming from Claude Code.

  • .claude/commands/ (project-level)
  • ~/.claude/commands/ (global)

OpenCode native paths take precedence over Claude-compatible paths.

Fixes #6985

Changes

  • config.ts: Added getClaudeDirectories() helper and integrated Claude command loading before OpenCode directories
  • config.test.ts: Added 3 tests for Claude command discovery, precedence, and nested paths
  • commands.mdx: Updated docs to list Claude-compatible paths with precedence note

SeanZoR avatar Jan 05 '26 20:01 SeanZoR

The following comment was made by an LLM, it may be inaccurate:

Duplicate PR Search Results

POTENTIAL RELATED PR FOUND:

  • #6963 - "fix(desktop): desktop won't read project scope commands/skills"
    • https://github.com/anomalyco/opencode/pull/6963
    • Reason: This appears directly related - it addresses reading project-scope commands, which overlaps with the command discovery functionality in PR #6990. Should verify if this is already handling Claude command paths or if they're complementary fixes.

OTHER POTENTIALLY RELEVANT PRs:

  • #722 - "feat(mcp): add support to claude code style .mcp.json project scoped mcps"

    • https://github.com/anomalyco/opencode/pull/722
    • Reason: Adds Claude Code style support for MCP configuration, similar pattern to adding .claude/ directory compatibility
  • #1304 - "Feat: custom commands"

    • https://github.com/anomalyco/opencode/pull/1304
    • Reason: Foundational PR for custom command support that may relate to command discovery mechanisms

Recommendation: Verify PR #6963 carefully, as it may already address some of the command discovery issues this PR is fixing, or they may be working on different aspects of the same feature.

github-actions[bot] avatar Jan 05 '26 20:01 github-actions[bot]

Thanks for flagging #6963! I checked it - there's significant overlap in the config.ts changes.

Key difference:

  • #6963 loads Claude commands after OpenCode directories → Claude takes precedence
  • This PR loads Claude commands before OpenCode directories → OpenCode takes precedence

I believe OpenCode should take precedence (matching how skills work), allowing users to override Claude Code commands with OpenCode-specific versions.

Happy to coordinate with the author of #6963 or close this if they update their PR with the correct precedence order.

SeanZoR avatar Jan 05 '26 20:01 SeanZoR

TODOs for allowed-tools Translation

Thanks for the feedback @rekram1-node! You're right - Claude commands have an allowed-tools field that needs translation.

I've added failing tests (TDD style) that document the expected behavior:

  • translates claude allowed-tools to opencode command permissions
  • translates claude allowed-tools with multiple tool types
  • claude commands without allowed-tools have no permission field

Claude Code allowed-tools format (from their repo):

allowed-tools: Bash(git checkout:*), Bash(git add:*), Bash(git commit:*), TodoWrite

Proposed Translation:

Claude Code OpenCode
Bash(git checkout:*) permission.bash: ["git checkout *"]
Bash(gh issue list:*) permission.bash: ["gh issue list *"]
TodoWrite permission.todowrite: "allow"

Implementation TODOs:

  • [ ] Add permission field to Command schema
  • [ ] Parse Claude's allowed-tools syntax in loadCommand()
  • [ ] Translate Bash(pattern:*) to bash permission patterns
  • [ ] Translate simple tool names (e.g., TodoWrite) to "allow"
  • [ ] Emit warning for untranslatable patterns
  • [ ] Make the failing tests pass

Let me know if you'd like me to proceed with the implementation or if you'd prefer a different approach!

SeanZoR avatar Jan 06 '26 05:01 SeanZoR

Thanks for flagging #6963! I checked it - there's significant overlap in the config.ts changes.

Key difference:

I believe OpenCode should take precedence (matching how skills work), allowing users to override Claude Code commands with OpenCode-specific versions.

Happy to coordinate with the author of #6963 or close this if they update their PR with the correct precedence order.

I think PR #6963 should drop the Claude command-loading changes and just focus on fixing the CWD issue. Thanks for calling it out.

kaichen avatar Jan 06 '26 16:01 kaichen