Copy for AgentA VS Code extension that adds a Copy for Agent item to the editor right-click menu. Instead of copying a bare snippet, it copies the selected code plus the context an AI agent needs — project root, file path (relative to the root), language, line range, and optionally the git branch — formatted so it pastes cleanly into Claude, Codex, or any chat window. WhyWhen you paste a loose snippet into an agent, it has no idea where the code lives. This extension wraps the selection with that context in one keystroke, so the agent immediately knows the file, its location in the project, and the exact lines. Features
FormatsSet the default via the
|
| Setting | Default | Description |
|---|---|---|
copyForAgent.format |
collapsed |
Default format: collapsed, markdown, xml, or plain. |
copyForAgent.includeProjectRoot |
true |
Include the absolute project-root path in the metadata. |
copyForAgent.includeAbsolutePath |
false |
Include the absolute file path in the metadata. |
copyForAgent.includeGitBranch |
false |
Include the current git branch (read from .git/HEAD) when available. |
Local development & testing
Prerequisites
- Node.js 18+ and npm
- Visual Studio Code
1. Install dependencies
cd copy-for-agent
npm install
2. Compile (or watch)
npm run compile # one-off build into ./out
# or
npm run watch # rebuild on every change
3. Launch the Extension Development Host
- Open this folder in VS Code.
- Press
F5(or Run → Start Debugging). This runs the Run Extension launch config, which builds the project and opens a second VS Code window titled [Extension Development Host] with the extension loaded. - In that window, open any file, select some code, right-click, and choose Copy for Agent. Paste into a scratch file or your agent window to verify.
- Edit the source, then click the green Restart button in the debug toolbar
(or press
Cmd/Ctrl+Shift+F5) to reload with your changes.
Tip: set breakpoints in
src/extension.ts— they'll hit in the debug window.
4. Test by installing the packaged build (optional)
To exercise the real install path rather than the dev host:
npm run package # produces copy-for-agent-0.0.1.vsix
code --install-extension copy-for-agent-0.0.1.vsix
Reload VS Code, and the extension is installed as a normal extension. Remove it
with code --uninstall-extension your-publisher-name.copy-for-agent.
Publishing to the VS Code Marketplace
Publishing uses @vscode/vsce
(already a dev dependency, run via npx vsce … or the npm scripts).
1. Create a publisher
- Sign in to the Visual Studio Marketplace publisher management page with a Microsoft account.
- Create a publisher (e.g.
your-publisher-name). - Set that exact id as the
"publisher"field inpackage.json.
2. Create a Personal Access Token (PAT)
- Go to https://dev.azure.com and sign in with the same Microsoft account.
- User settings → Personal access tokens → New Token.
- Configure:
- Organization: All accessible organizations
- Scopes: Custom defined → Marketplace → Manage
- Copy the token (you only see it once).
3. Log in with vsce
npx vsce login your-publisher-name
# paste the PAT when prompted
4. Fill in required metadata before first publish
In package.json, make sure these are real values (the Marketplace rejects
placeholders):
publisher— your publisher idrepository.url— your repo URLversion— bump on every publish (the Marketplace rejects duplicate versions)- (optional) an icon: add a 128×128 PNG (e.g.
images/icon.png) and an"icon": "images/icon.png"field topackage.json
5. Package and publish
# Inspect the .vsix locally first:
npm run package
# Publish the current version:
npm run publish
# Or bump + publish in one step (patch / minor / major):
npx vsce publish patch
After publishing, the extension appears at
https://marketplace.visualstudio.com/items?itemName=your-publisher-name.copy-for-agent
(allow a few minutes for indexing).
Updating
- Make changes and update
CHANGELOG.md. npx vsce publish patch(orminor/major) to bump the version and ship.
Alternative: Open VSX (for Cursor, VSCodium, Windsurf, etc.)
Editors that don't use the Microsoft Marketplace pull from Open VSX:
npm install -g ovsx
ovsx create-namespace your-publisher-name -p <openvsx-token>
ovsx publish copy-for-agent-0.0.1.vsix -p <openvsx-token>
Project layout
copy-for-agent/
├─ src/
│ ├─ extension.ts # command registration + entry points
│ ├─ context.ts # gathers snippet + project/file/git metadata
│ └─ format.ts # renders the four output formats
├─ .vscode/ # F5 debug + watch task config
├─ package.json # manifest: commands, menu, keybinding, settings
├─ tsconfig.json
└─ README.md
License
MIT — see LICENSE.