Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Code Context for AINew to Visual Studio Code? Get it now.
Code Context for AI

Code Context for AI

Adan Ayaz

| (0) | Free
Built for AI chats. Copy your code with exactly the dependencies it uses — no bloat, just surgical context.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Code Context Logo (512x512)

Code Context

Copy code with its actual dependencies.
Surgical AI context. Zero clipboard bloat.


VS Code Marketplace Downloads Tests TypeScript License: MIT


Install Now · Report a Bug · Request a Feature




The Problem

When you paste code into an AI chat, the AI only sees what you copied.

Your function imports from three files. The AI sees none of them. It guesses. You get a hallucinated answer.

The obvious fix — copying the whole folder — just trades one problem for another. Test files, unrelated utilities, 2,000 lines of noise for a 40-line question.

Code Context reads your actual import graph and copies exactly what's needed. Nothing more.



Three Levels of Precision

Right-click any file. One menu. Three modes.


Level 1   Copy File

The foundation. Copies a single file with its workspace-relative path as a clean header — formatted and ready to paste.

$(copy) Copied 1 file (47 lines)

Level 2   Copy with Dependencies

Walks your import graph up to a configurable depth. Copies the root file plus every local dependency it imports — deduplicated, ordered dependencies-first, exactly how an LLM needs to read them.

$(copy) Copied 3 files (211 lines)

Level 3   Copy Function + Dependencies   ✦

The one that changes how you work.

Place your cursor inside any function. Right-click. That's it.

Code Context parses the AST, finds your function, traces every identifier it references, and copies only that function with only the imports it actually uses. A 1,000-line file with 15 imports? You get the function and the 2 files it needs. The other 13 are ignored.

$(copy) Copied function `area` + 1 dependency (23 lines)


See It in Action

Level 2 · Copy with Dependencies

You have this structure:

src/
├── main.ts          ← right-click here
├── utils.ts
└── date-helper.ts

src/main.ts

import { greet } from "./utils";
import { formatDate } from "./date-helper";

export function main() {
  const message = greet("World");
  const today = formatDate(new Date());
  console.log(`${message} — today is ${today}`);
}

After Copy with Dependencies (depth 1), your clipboard:

// src/date-helper.ts
export function formatDate(date: Date): string {
  return date.toISOString().split("T")[0];
}

// src/utils.ts
export function greet(name: string): string {
  return `Hello, ${name}!`;
}

// src/main.ts
import { greet } from "./utils";
import { formatDate } from "./date-helper";

export function main() {
  const message = greet("World");
  const today = formatDate(new Date());
  console.log(`${message} — today is ${today}`);
}

Dependencies appear before the files that import them. Exactly the reading order an LLM needs.



Level 3 · Copy Function + Dependencies

A 500-line service file. Many imports. You only care about area().

// src/services/geometry.ts

import { multiply, square } from "./math/operations";
import { fetchConfig } from "./config/loader";
import { Logger } from "./utils/logger";
import * as fs from "fs";

export function area(width: number, height: number): number {
  return multiply(width, height); // ← cursor is here
}

export function squareArea(side: number): number {
  return square(side);
}

export function readConfig(path: string) {
  Logger.info("loading");
  return fetchConfig(path);
}

// ... 400 more lines

Copy Function + Dependencies gives you:

// Dependency: src/math/operations.ts
export function multiply(a: number, b: number): number {
  return a * b;
}

export function square(n: number): number {
  return multiply(n, n);
}

// Function: area  (src/services/geometry.ts)
export function area(width: number, height: number): number {
  return multiply(width, height);
}

fetchConfig, Logger, and fs are not included. The AST confirmed area never touches them.



How It Compares

Folder copy tools Code Context
Copies file content ✅ ✅
Skips unrelated files ❌ ✅
Follows the actual import graph ❌ ✅
Dependency-first ordering ❌ ✅
Function-level granularity ❌ ✅
Respects tsconfig path aliases ❌ ✅
Excludes test files by default ❌ ✅


Installation

From the Marketplace:

  1. Open VS Code
  2. Press Ctrl+P / Cmd+P
  3. Paste: ext install code-context.code-context
  4. Hit Enter

Or open the Extensions panel (Ctrl+Shift+X) and search Code Context.



Usage

All commands appear in both the Explorer context menu and the Editor context menu. Right-click any .ts, .tsx, .js, or .jsx file.

Command Where What happens
Code Context: Copy File Explorer · Editor Copies the file with a path header
Code Context: Copy with Dependencies Explorer · Editor Prompts for depth, walks the import graph
Code Context: Copy Function + Dependencies Editor (cursor inside function) Copies just that function + its used imports

Depth Prompt (Level 2)

A quick-input appears pre-filled with your configured default:

How many levels of imports should be followed? (1 = direct imports only)
> 2
Depth What you get
1 Root file + its direct imports
2 Root + imports + imports-of-imports
N Full transitive graph up to N hops

Circular imports are handled safely — each file is visited at most once.


Status Bar Feedback

Every copy shows a brief summary in the status bar, then fades after 5 seconds:

$(copy) Copied 3 files (247 lines)


Configuration

All settings live under the codeContext namespace. Search Code Context in Settings (Ctrl+,) or edit settings.json directly.

Setting Type Default Description
codeContext.defaultDepth number (1–10) 2 Depth pre-filled in the Level 2 prompt
codeContext.outputFormat "comment-path" · "markdown-codeblock" "comment-path" How each file is wrapped in the output
codeContext.excludePatterns string[] test & spec files Glob patterns for files to skip
codeContext.followTsConfigPaths boolean true Resolve tsconfig.json path aliases

Example settings.json:

{
  "codeContext.defaultDepth": 3,
  "codeContext.outputFormat": "markdown-codeblock",
  "codeContext.excludePatterns": [
    "**/*.test.ts",
    "**/*.spec.ts",
    "**/mocks/**"
  ],
  "codeContext.followTsConfigPaths": true
}

Output Formats

comment-path (default) — clean, works in any AI chat:

// src/utils/auth.ts
export async function verifyToken(token: string): Promise<Payload> {
  // ...
}

markdown-codeblock — renders beautifully in Markdown-aware tools:

```typescript
// src/utils/auth.ts
export async function verifyToken(token: string): Promise<Payload> {
  // ...
}
```


Supported Languages

Extension Language
.ts · .tsx TypeScript · TypeScript + JSX
.js · .jsx JavaScript · JavaScript + JSX
.mts · .cts TypeScript ESM · CommonJS
.mjs · .cjs JavaScript ESM · CommonJS

tsconfig path aliases (@/, ~, custom prefixes) are fully resolved when codeContext.followTsConfigPaths is enabled and a tsconfig.json exists in the workspace root.



How It Works

Import Graph Walking (Level 2)
  1. Parses the file's AST using @typescript-eslint/typescript-estree — handles TS and JS without invoking the full TypeScript compiler.
  2. Extracts all ImportDeclaration nodes and resolves specifiers to absolute paths on disk.
  3. Skips node_modules and anything matching your excludePatterns.
  4. Performs a BFS walk up to maxDepth, tracking visited files in a Set to handle circular imports safely.
  5. Reverses the collection so dependencies appear before the files that consume them.
Surgical Function Copy (Level 3)
  1. Parses the full file AST.
  2. Finds the innermost function node (declaration, expression, or arrow function) containing the cursor position.
  3. Traverses that function's AST subtree, collecting every Identifier it references.
  4. Cross-references those identifiers against the file's import declarations — only imports whose exported names appear inside the function are kept.
  5. Resolves those import paths to disk and reads each dependency file.
Path Resolution

resolveImport probes each candidate in order:

  1. Exact match (specifier already has an extension)
  2. With each extension: .ts → .tsx → .js → .jsx → .mts → .cts → .mjs → .cjs
  3. As a directory index file (index.ts, index.js, etc.)
  4. Via tsconfig.json path aliases (when followTsConfigPaths is enabled)


Project Structure

code-context/
├── src/
│   ├── extension.ts              # Entry point — registers commands & status bar
│   ├── commands/
│   │   ├── copyFile.ts           # Level 1 — single file copy
│   │   ├── copyWithDeps.ts       # Level 2 — dependency graph copy
│   │   └── copyFunction.ts       # Level 3 — function + surgical imports
│   ├── core/
│   │   ├── astParser.ts          # AST parsing: imports, function nodes, identifiers
│   │   ├── dependencyResolver.ts # BFS graph walker + import resolver
│   │   ├── pathResolver.ts       # Import specifier → absolute path on disk
│   │   └── formatter.ts          # Output formatting
│   └── test/
│       ├── fixtures/
│       │   ├── simple/           # main.ts → utils.ts, date-helper.ts
│       │   ├── nested/           # a.ts → b.ts → c.ts
│       │   ├── circular/         # x.ts ↔ y.ts (circular guard)
│       │   └── function-level/   # multi-function with selective imports
│       └── unit/
│           ├── pathResolver.test.ts
│           ├── dependencyResolver.test.ts
│           ├── astParser.test.ts
│           └── formatter.test.ts
├── esbuild.js
├── tsconfig.json
└── package.json


Development

Prerequisites

  • Node.js 18+
  • pnpm — npm install -g pnpm
  • VS Code 1.114.0+

Setup

git clone https://github.com/adan-ayaz-stan/code-context
cd code-context
pnpm install

Run in Development

Press F5 in VS Code to launch an Extension Development Host with the extension loaded.

Or start the watch build manually:

pnpm run watch

Run Tests

pnpm test

The test suite runs inside a real VS Code instance via @vscode/test-electron. All 33 tests must pass before a PR is merged.

  pathResolver
    ✔ resolves a relative .ts import without extension
    ✔ resolves a relative .ts import with a sibling
    ✔ resolves a deeper relative path
    ✔ returns null for node_modules imports
    ✔ returns null for non-existent files
    ✔ findWorkspaceRoot walks up to find package.json
    ✔ loadTsConfigPaths returns empty paths gracefully

  formatter — formatFiles
    ✔ comment-path format: single file
    ✔ comment-path format: multiple files separated by blank line
    ✔ markdown-codeblock format: wraps in triple backticks
    ...

  dependencyResolver
    ✔ depth 0 — returns only the root file
    ✔ depth 1 — returns root + direct imports (simple)
    ✔ depth 2 — walks nested chain a → b → c
    ✔ depth 1 — stops at depth limit
    ✔ handles circular imports without infinite loop
    ✔ returns files in dependency-first order

  33 passing

Build for Production

pnpm run package

Produces dist/extension.js via esbuild — minified, tree-shaken, fast.

Lint

pnpm run lint


Contributing

Pull requests are welcome. For significant changes, open an issue first to discuss direction.

  1. Fork the repo
  2. Create your branch: git checkout -b feat/my-feature
  3. Make your changes with test coverage
  4. Run pnpm test — all 33 tests must pass
  5. Open a PR with a clear description of the change


License

MIT — free to use, modify, and distribute.



Built for the AI-assisted development workflow.

Copy less. Context more.


VS Code Marketplace

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