Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Copy Path for OpenCodeNew to Visual Studio Code? Get it now.
Copy Path for OpenCode

Copy Path for OpenCode

shaokaodashi

| (0) | Free
Copy code block, file, and folder paths for OpenCode.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Copy Path for OpenCode

Copy file, folder, and code location paths from VSCode in a format that works well in OpenCode prompts and commands.

What it does

  • Copies code block paths from the editor context menu.
  • Copies file and folder paths from the Explorer context menu.
  • Supports both absolute and workspace-relative output modes.
  • Normalizes path separators to / for OpenCode-friendly output.
  • Falls back to absolute output when a workspace-relative path is unavailable.

Editor usage

In an open local file, right-click in the editor and choose one of these commands:

  • Copy Code Block Path (Absolute)
  • Copy Code Block Path (Relative)

The copied value includes the file path plus the selection start line and column, or the current cursor position when nothing is selected.

Examples:

  • Absolute: /Users/me/project/src/extension.ts:12:3
  • Relative: src/extension.ts:12:3

Relative output is workspace-relative when the file belongs to an open workspace folder. If VSCode cannot determine a workspace-relative path, the extension copies the absolute path instead.

Explorer usage

In the Explorer, right-click a local file-scheme resource for a file or folder and choose one of these commands:

  • Copy File/Folder Path (Absolute)
  • Copy File/Folder Path (Relative)

Examples:

  • File, absolute: /Users/me/project/src/extension.ts
  • File, relative: src/extension.ts
  • Folder, absolute: /Users/me/project/src
  • Folder, relative: src

Absolute vs relative output

  • Absolute output always copies the full local filesystem path.
  • Relative output copies a workspace-relative path when one is available.
  • If no workspace-relative path is available, relative mode falls back to the absolute path.
  • All copied paths use / separators, even on platforms that normally use \.

OpenCode-oriented examples

Use copied paths directly in prompts such as:

  • Check /Users/me/project/src/extension.ts:12:3
  • Review src/extension.ts:12:3
  • Open src/workspace.ts
  • Compare /Users/me/project/src with src/pathFormatter.ts

Local testing

Use this flow to manually test the extension in VSCode:

  1. Open the project directory:
    • code .
  2. Start the Extension Development Host:
    • Press F5 in the main VSCode window
  3. In the new Extension Development Host window, open a test workspace with a few files and folders.
  4. Verify editor commands:
    • Open a local file
    • Select some code, right-click, and run Copy Code Block Path (Absolute)
    • Select some code, right-click, and run Copy Code Block Path (Relative)
    • Clear the selection, place the cursor somewhere else, and run the same commands again
  5. Verify Explorer commands:
    • Right-click a file and run the absolute and relative copy commands
    • Right-click a folder and run the absolute and relative copy commands
  6. Paste the results into a scratch file and confirm:
    • editor output looks like path:line:column
    • file and folder output looks like a plain path
    • relative mode falls back to absolute when needed
    • copied paths use / separators

Suggested test targets:

  • src/extension.ts
  • src/pathFormatter.ts
  • src/workspace.ts
  • a folder such as src
  • a file outside the current workspace, to check relative-to-absolute fallback behavior

Notes

  • The editor command works only for local file-backed editors.
  • Explorer commands support only local file-scheme resources for files and folders.
  • Workspace-relative output depends on the selected resource being inside an open workspace folder.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft