Copy4AICopy code with its dependencies in AI-optimized Markdown format. Copy4AI is a VS Code extension that lets you select code, automatically resolve its dependencies (up to 3 levels deep), and copy everything as a structured Markdown snippet ready to paste into Claude, ChatGPT, or any other AI assistant. It also supports applying AI-generated code changes back into your files with a single shortcut.
FeaturesCopy with Context (
|
| Language | Import Parsing | Dependency Resolution |
|---|---|---|
| TypeScript | Yes | Yes |
| TypeScript (React) | Yes | Yes |
| JavaScript | Yes | Yes |
| JavaScript (React) | Yes | Yes |
| Python | Yes | Yes |
| Go | Yes | Yes |
For unsupported languages, Copy4AI still copies the selected code -- dependency resolution is skipped gracefully with a warning banner.
Installation
From Source
# Clone the repository
git clone https://github.com/copy4ai/extension.git
cd extension
# Install dependencies
pnpm install
# Build the extension
pnpm run build:dev
# Open in VS Code and press F5 to launch the Extension Development Host
code .
From VS Code Marketplace
Search for Copy4AI in the VS Code Extensions panel, or install via the command line:
code --install-extension copy4ai.copy4ai
Usage
- Select code in any supported file
- Press
Ctrl+Shift+C(orCmd+Shift+Con macOS), or right-click and choose "Copy with Copy4AI" - The Copy4AI panel opens with your code and its resolved dependencies
- Adjust depth, toggle dependencies, and preview the Markdown output
- Click Copy to copy the AI-optimized Markdown to your clipboard
- Paste into your AI assistant of choice
Applying AI Responses
- Copy the AI's code response to your clipboard
- Press
Ctrl+Shift+V(orCmd+Shift+Von macOS) - Copy4AI parses the response and applies changes to the correct files
The paste command understands the structured <<<FILE: ... | LINES: ...>>> format as well as common code-fence variations that AI assistants produce.
Configuration
Available settings under copy4ai.* in VS Code:
| Setting | Default | Description |
|---|---|---|
copy4ai.apiUrl |
"" |
Custom API URL (leave empty for production) |
copy4ai.aiProvider |
"copy4ai" |
AI provider for JSDoc: copy4ai, anthropic, openai |
copy4ai.anthropicApiKey |
"" |
Your Anthropic API key (bring-your-own-key mode) |
copy4ai.openaiApiKey |
"" |
Your OpenAI API key (bring-your-own-key mode) |
Architecture
src/
commands/ Command handlers (copy, paste)
parsers/ Language-specific import extractors (TS, Python, Go)
providers/ VS Code webview providers (panel, sidebar)
services/ Core business logic
apiClient.ts REST API communication
authService.ts PKCE OAuth authentication
config.ts Environment configuration
dependencyResolver.ts Recursive dependency discovery
historyService.ts Local copy history
markdownBuilder.ts AI-optimized Markdown generation
types/ Shared TypeScript interfaces
utils/ Constants, token/credit estimation
webview/
panel/
components/ React UI components (12+ components)
hooks/ VS Code message handling hooks
utils/ Syntax highlighting utilities
extension.ts Extension entry point
media/ Icons and CSS stylesheets
esbuild.js Build configuration (dual-bundle)
Key Design Decisions
- Zero runtime dependencies -- everything is self-contained; no npm packages bundled at runtime
- Dual esbuild bundles -- one for the Node.js extension host (CommonJS), one for the browser-based webview (IIFE with React)
- VS Code native APIs for definition resolution -- no custom language servers or AST parsers for dependency traversal
- Regex-based import parsing per language, with a strategy pattern for extensibility
- PKCE OAuth for secure authentication without exposing client secrets
- Message-based communication between extension and webview via a typed protocol
Development
# Development build (with source maps)
pnpm run build:dev
# Production build (minified)
pnpm run build:prod
# Watch mode (rebuilds on file changes)
pnpm run watch
# Lint
pnpm run lint
Adding a New Language Parser
- Create a new file in
src/parsers/implementing the parser interface - Export
extractIdentifiers(code: string): string[]and optionallyextractNamespaceImports(code: string): string[] - Register the parser in
src/parsers/index.ts - Add the language ID to
SUPPORTED_LANGUAGESinsrc/utils/constants.ts
How It Works
- Selection -- user selects code and triggers the copy command
- Parsing -- a language-specific parser extracts imported identifiers from the selection (falls back to file-level imports filtered by usage)
- Resolution -- the
DependencyResolveruses VS Code'svscode.executeDefinitionProviderto locate each identifier's source, skippingnode_modulesand circular references - Recursion -- dependencies of dependencies are resolved up to the configured depth (max 3)
- Markdown generation -- the
MarkdownBuilderassembles a structured Markdown document with AI instructions, file paths, line numbers, and code blocks - Clipboard -- the result is copied and the interactive panel opens for review
Credits and Pricing
Copy4AI uses a credit system for AI-powered features (JSDoc generation). Copy operations themselves are free. You can:
- Use Copy4AI credits (included with your account)
- Bring your own Anthropic or OpenAI API key
Credit costs scale with code size:
| Code Size | Credits |
|---|---|
| Small (< 2K chars) | 1 |
| Medium (< 8K chars) | 2 |
| Large (8K+ chars) | 3 |
| JSDoc generation | 2 |
Requirements
- VS Code 1.85 or later
- Node.js 20+ (for development)
- pnpm (for development)
License
See LICENSE for details.