LevelUpWith

Explore / AI Coder: Claude Code & Coding Agents / Lesson 2

Lesson 2: Inline Completion Mastery: Copilot & Codex

Leverage GitHub Copilot and OpenAI Codex effectively by steering inline suggestions through prompt comments and active context cues.

Free to read, no account needed. Part of AI Coder: Claude Code & Coding Agents.

By the end of this level you'll be able to

  • Steer multi-line completions using targeted docstrings and comment anchors
  • Manage open editor tabs to prime cross-file context retrieval
  • Configure Copilot ignore rules to protect sensitive codebase secrets

How Inline Completion Really Thinks

When you use inline completion tools like GitHub Copilot or OpenAI Codex, it helps to remember: the model is not thinking ahead, it is simply predicting what comes next based on the text surrounding your cursor.

If you type a vague comment like // process user, the model has to guess from millions of possible interpretations across open-source code. But if you provide clear anchors—type annotations, step-by-step intent, and precise variable names—the probabilistic space collapses into the exact implementation you want.

Let's explore how to take control of inline completions rather than passively accepting whatever pops up.


Steering Multi-Line Completions with Comment Anchors

Modern inline engines look backwards from your cursor (prefix context) and forwards (suffix context). To steer multi-line logic reliably, write comment anchors before you write the code.

Weak vs. Strong Comment Anchors

// ❌ WEAK: Ambiguous, model often hallucinates external libraries
// calculate order total
function calc(o) {
// ✅ STRONG: Specifies inputs, business rules, rounding, and expected output
/**
 * Calculates the final order total.
 * - Applies percentage discount if promoCode starts with 'SAVE'
 * - Adds standard 8.25% sales tax
 * - Rounds output to two decimal places
 * @param items Array of { price: number, quantity: number }
 * @param promoCode Optional discount string (e.g. 'SAVE20' for 20% off)
 * @returns Calculated total as a number
 */
function calculateOrderTotal(items: Array<{ price: number; quantity: number }>, promoCode?: string): number {
  // 1. Sum line items
  const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);

  // 2. Parse promo code discount percentage
  // [Cursor placed here -> Copilot triggers exact multi-line logic matching the docstring]

The "Step-List" Pattern

If a function has complex branches, write out the numbered steps as inline comments first:

def refund_transaction(transaction_id: str, amount_cents: int) -> bool:
    # Step 1: Validate transaction exists and status is 'SETTLED'
    # Step 2: Ensure refund amount <= remaining unsettled balance
    # Step 3: Issue refund through payment gateway client
    # Step 4: Record refund ledger event in database

By placing your cursor beneath # Step 1, Copilot will fill in step 1, advance you to # Step 2, and complete subsequent steps sequentially with consistent variable names.


Cross-File Priming: The Neighboring Tabs Heuristic

Copilot does not index your entire million-line repository in real time. Instead, it uses heuristics to build a short prompt payload. One of the strongest heuristics is neighboring open tabs in your IDE.

When you request a completion in order_service.ts, the extension scans recently active tabs in your editor (using text matching and lexical similarity heuristics like Jaccard similarity) to inject relevant snippets into the prompt context.

[Open Tab 1: types/order.ts]  ──┐
[Open Tab 2: db/schema.prisma] ──┼─► [Copilot Context Builder] ─► [High-Accuracy Suggestions]
[Active Tab: order_service.ts] ─┘

Practical Tab Management

  1. Prime before implementing: Before asking Copilot to write a repository method or API route, open the relevant data model file (schema.prisma or types.ts) in an adjacent editor tab.
  2. Close noise: If you have 30 tabs open spanning frontend components, migration scripts, and legacy utilities, the prompt builder may select irrelevant snippets (context poisoning). Keep open only the files relevant to the current feature.

Protecting Secrets with .copilotignore

Inline completion sends context chunks to remote inference servers. You must ensure credentials, PII schemas, and proprietary internal algorithms never enter the prompt payload.

GitHub Copilot supports .copilotignore files placed in your repository root or subdirectories. Its syntax mirrors standard .gitignore rules.

# .copilotignore at repository root

# Ignore environment files and secret stores
.env*
*.pem
secrets/

# Ignore high-security or proprietary business logic
src/core/pricing_engine/proprietary_algo.py
src/compliance/pii_mappings.json

How .copilotignore Behaves in Practice

  • In ignored files: Copilot inline suggestions are completely disabled.
  • In neighboring files: Content from ignored files is excluded from context building and will not be sent to prime completions in other open tabs.

Key Takeaways

  • Anchor with intent: Use typed docstrings and numbered comment steps to lock down completion boundaries.
  • Prime the context window: Open relevant type definitions and interfaces in adjacent tabs so Copilot references your project's existing shapes.
  • Prune tab clutter: Close unrelated tabs to prevent irrelevant code from poisoning the context heuristic.
  • Enforce .copilotignore: Prevent secret keys and sensitive internal logic from being processed by remote models.

A 6-question knowledge check follows this lesson in the app, free and without an account.

Keep going: levels 3 and 4 are free

Create a free account to open the next two levels, save your progress and pick up where you left off. No card needed.

Next: Level 3, Context-Aware Editing with Cursor IDE.

Create a free account →See the whole course

More like this

  • Finding and Fixing Vulnerabilities with Claude

    Scan a practice repository with Claude's security layers, verify and triage what they report, and land patches safely on a branch. You will leave with a repeat…

    Course · Claude · IT Support, Networking & Security · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • 10x Developer: Claude Code & LLM Selection Mastery

    Master Claude Code CLI, advanced context management, tool integration, and optimal LLM model selection to multiply your software engineering throughput.

    Beyond the Obvious · AI & Agents · Expert · 29 levels · 4 free · Professionally curated by levelupwith.com

  • Claude at Work: No-Code Skills for Knowledge Workers

    Learn to brief Claude clearly, check what it gives you, and set up Projects, Artifacts, Skills, memory, connectors and Research for real work in sales, marketi…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Delegating Real Work to Claude: Tasks, Files and Apps

    Learn to hand Claude multi-step work on your real files, browser and Office apps, with clear briefs, firm limits and approval gates, then review the results so…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Prompting Claude: Instructions, Context and Testing

    Write prompts that Claude follows reliably, manage what goes into its context window, and test and improve your prompts with evidence instead of guesswork. Eac…

    Course · Claude · AI & Agents · Capable · 20 levels · 4 free · Professionally curated by levelupwith.com

  • Finished Work with Claude Artifacts, No Code

    Brief, refine, brand, check, share and export finished designs, decks, documents, dashboards and motion pieces in Claude without writing code. Every level ends…

    Course · Claude · AI & Agents · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com