Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Copy for AgentNew to Visual Studio Code? Get it now.
Copy for Agent

Copy for Agent

esc.pub

| (0) | Free
Copy a code snippet together with its context (project root, path, language, line range, git branch) formatted for pasting into an AI agent window (Claude, Codex, etc.).
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Copy for Agent

A 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.

Why

When 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

  • Copy for Agent — copies the current selection (or the current line if nothing is selected) using your configured format.
  • Copy for Agent (Choose Format)… — pick a format from a quick menu for a one-off copy.
  • Four output formats (see below).
  • Robust code fencing: if your snippet itself contains ```, the fence is automatically widened so it never breaks.
  • Default keybinding: Cmd+Alt+C (macOS) / Ctrl+Alt+C (Windows/Linux).

Formats

Set the default via the copyForAgent.format setting, or choose per-copy with Copy for Agent (Choose Format)….

collapsed (default)

Renders as an expandable section in Markdown viewers (Claude, Codex, GitHub), keeping long snippets out of the way:

<details>
<summary>📄 <code>src/format.ts</code> · lines 24–31</summary>

​```typescript
export function formatSnippet(ctx, format, opts) {
  // ...
}
​```

- **Project:** `copy-for-agent`
- **Root:** `/Users/you/Projects/copy-for-agent`
- **File:** `src/format.ts` (lines 24–31)
</details>

markdown

A metadata list followed by a fenced code block:

- **Project:** `copy-for-agent`
- **File:** `src/format.ts` (lines 24–31)

​```typescript
export function formatSnippet(ctx, format, opts) {
  // ...
}
​```

xml

Claude-style tags with metadata as attributes — handy when you want the model to parse fields:

<code_snippet path="src/format.ts" lines="24-31" language="typescript" project="copy-for-agent">
export function formatSnippet(ctx, format, opts) {
  // ...
}
</code_snippet>

plain

Minimal path:lines header plus a fenced block:

src/format.ts:24-31
​```typescript
export function formatSnippet(ctx, format, opts) {
  // ...
}
​```

Settings

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

  1. Open this folder in VS Code.
  2. 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.
  3. 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.
  4. 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

  1. Sign in to the Visual Studio Marketplace publisher management page with a Microsoft account.
  2. Create a publisher (e.g. your-publisher-name).
  3. Set that exact id as the "publisher" field in package.json.

2. Create a Personal Access Token (PAT)

  1. Go to https://dev.azure.com and sign in with the same Microsoft account.
  2. User settings → Personal access tokens → New Token.
  3. Configure:
    • Organization: All accessible organizations
    • Scopes: Custom defined → Marketplace → Manage
  4. 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 id
  • repository.url — your repo URL
  • version — 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 to package.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

  1. Make changes and update CHANGELOG.md.
  2. npx vsce publish patch (or minor / 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.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft