AI coding tools are increasingly designed to understand an entire codebase rather than just the file currently open in an editor.

To do that, a coding agent may scan repositories, build indexes, retrieve related files, and send selected context to an AI model.

That makes codebase indexing an important security boundary.

When an indexing system is exposed, misconfigured, or compromised, the impact can extend beyond a single source file.

The recent ZCode codebase indexing incident is a useful reason for developers to look more closely at what their AI coding tools can access, where indexed data is stored, and which services can retrieve it.

The broader lesson is not about one product. It is about understanding the data flow created when an AI coding tool indexes a repository.

What Does Codebase Indexing Actually Do?

An AI coding tool needs relevant context to answer questions such as:

Where is authentication implemented?

Which service calls this API?

Where is this database model used?

What tests cover this class?

Reading only the current file is often insufficient.

A coding tool may therefore build an index:

Repository
    |
    v
File Scanner
    |
    v
Code Index
    |
    v
Search / Retrieval
    |
    v
Relevant Context
    |
    v
AI Model

The index may contain information derived from many files.

Depending on the implementation, it can include source text, file paths, symbols, metadata, embeddings, or other representations of repository content.

That makes the index itself sensitive.

Why a Codebase Index Can Be Sensitive

Consider a repository containing:

/src
/tests
/infrastructure
/config
/scripts
/docs

A developer might think only the files explicitly opened in the editor are being processed.

An indexing system may instead inspect a much larger portion of the repository.

That could include:

Internal APIs
Database schemas
Security configuration
Infrastructure definitions
Business logic
Private documentation

Even if an AI model receives only selected snippets for a particular request, the indexing layer may have already processed a much broader set of files.

The ZCode Incident and the Broader Lesson

The ZCode incident highlighted why developers should not treat codebase indexing as an invisible implementation detail.

When an AI coding tool indexes a repository, several questions become important:

  1. Which files are indexed?

  2. Where is the index stored?

  3. Who can access the index?

  4. How is the index protected?

  5. How long is indexed information retained?

  6. Can another user or workspace access it?

  7. Is repository data sent to an external service?

  8. Can administrators inspect or retrieve indexed data?

  9. What happens when a repository is removed?

  10. Are sensitive files excluded?

The specific answers depend on the tool and its configuration.

Developers should verify them instead of assuming that repository indexing follows the same security model as normal source control.

Indexing Is Different From Sending a Prompt

These two operations are often confused.

A traditional AI request might look like:

Developer
   |
   v
Select Code
   |
   v
AI Model

An agentic coding tool may work more like:

Repository
   |
   v
Indexing
   |
   v
Search
   |
   v
Relevant Code
   |
   v
Model Request

The second architecture creates additional data-processing stages.

The security review therefore needs to include the indexing system.

What Developers Should Check First

The first step is to determine what the tool can actually read.

Check whether it indexes:

Source files
Configuration files
Documentation
Test files
Generated files
Hidden files
Dependency metadata
Git history

Do not assume that .gitignore alone defines what an AI coding tool can access.

Different tools can implement their own indexing and exclusion rules.

Check Repository Exclusions

A good AI coding setup should provide a way to exclude files or directories that the agent does not need.

For example:

Repository
|
+-- src/             Indexed
+-- tests/            Indexed
+-- docs/             Indexed
+-- secrets/          Excluded
+-- deployment-keys/  Excluded

The exact configuration mechanism depends on the tool.

The important principle is:

Do not give an AI coding tool access to sensitive files simply because they happen to exist inside the repository.

Do Not Put Secrets in the Repository

This is a basic software-security rule that becomes even more important with AI coding tools.

Avoid storing secrets such as:

Database passwords
API keys
Private certificates
Cloud credentials
SSH private keys
Access tokens

inside source-controlled files.

A coding agent that can read the repository can potentially process anything stored there.

Use appropriate secret-management mechanisms instead.

Check What the Index Contains

Knowing that a tool creates an index is not enough.

Determine what is actually stored.

An index could contain:

File paths
Symbol names
Source snippets
Embeddings
Metadata
Repository relationships

Different implementations expose different information.

If the index is stored outside the developer's machine, the storage location and access controls become particularly important.

Understand Where the Index Lives

Ask:

Is the index local?

or:

Is the index stored on an internal server?

or:

Is the index stored by an external service?

These architectures have different security implications.

Local Index

Repository
   |
   v
Developer Machine
   |
   v
Local Index

The organization has direct control over the local environment.

Internal Index

Developer
   |
   v
Internal Service
   |
   v
Internal Index

The organization controls the infrastructure and access policies.

External Index

Developer
   |
   v
External Service
   |
   v
Hosted Index

The organization's source-code data is now processed outside its direct infrastructure boundary.

None of these models is automatically safe or unsafe. The relevant question is whether the model matches the organization's security requirements.

Check Access Control

Suppose multiple developers use the same AI coding platform.

The index must not accidentally allow:

Developer A
     |
     X
Developer B's Repository

Repository isolation should be explicitly enforced.

Check whether the platform separates data by:

  • User

  • Organization

  • Repository

  • Workspace

  • Project

  • Tenant

The exact isolation model varies between products.

Check What Happens When Access Is Removed

Consider this sequence:

Repository Connected
      |
      v
Index Created
      |
      v
Repository Access Removed

What happens to the existing index?

A security review should ask:

  • Is the index deleted?

  • How quickly is it deleted?

  • Are backups also affected?

  • Can the data still be queried?

  • Is it retained for diagnostics?

  • Does removing a repository remove derived index data?

Retention behavior should be documented and verified for the specific tool.

Review Git History Exposure

Repositories often contain more information than the current working tree.

For example:

Current Source
      +
Git History
      +
Deleted Files
      +
Previous Configuration

A coding tool that processes repository history may encounter information that developers thought was no longer present.

This is another reason to avoid committing secrets in the first place.

Removing a secret from the latest commit does not necessarily remove it from repository history.

AI Context Retrieval Needs Its Own Security Boundary

Suppose the index contains:

customers.cs
payments.cs
internal-api.cs
security-config.cs

The agent receives a question:

How does authentication work?

The retrieval system determines which files to provide to the model.

That creates another control point:

Index
  |
  v
Retriever
  |
  v
Access Check
  |
  v
Relevant Context
  |
  v
Model

The retrieval layer should respect the permissions of the user and workspace.

It should not assume that because information exists in the index, every agent request can retrieve it.

Avoid Treating Embeddings as Harmless

Some teams assume that embeddings are not sensitive because they are not plain source code.

That assumption can be dangerous.

Embeddings are derived from source material.

Whether they can be reconstructed or used to infer sensitive information depends on the specific implementation and threat model.

Therefore, embeddings and other derived representations should still receive appropriate protection.

What About Private Repositories?

Private repository status does not automatically mean an AI coding tool can safely access the repository.

The developer should separately review:

Repository permissions
AI tool permissions
Index permissions
Model access
Storage location
Retention
Telemetry

A private Git repository and an external AI indexing service can have completely different access boundaries.

A Practical Security Review

Before enabling codebase indexing, walk through the following flow:

1. Repository
      |
      v
2. Indexing
      |
      v
3. Index Storage
      |
      v
4. Retrieval
      |
      v
5. Model Request
      |
      v
6. Generated Response

For each stage, ask:

What data is processed?
Who can access it?
Where is it stored?
How long is it retained?
Can it leave the environment?
How is access revoked?

This provides a much better security picture than simply asking whether the AI tool is "private."

What Developers Can Do in Existing Projects

If your team already uses an AI coding tool, start with a repository review.

Step 1 - Identify Sensitive Files

Find files containing:

Credentials
Private keys
Connection strings
Customer data
Internal configuration
Security policies

Step 2 - Check Indexing Rules

Determine which directories the tool indexes.

Step 3 - Check Data Location

Find out where indexes and related metadata are stored.

Step 4 - Review Permissions

Verify that users only retrieve code they are authorized to access.

Step 5 - Review Retention

Understand how long indexed data remains available.

Step 6 - Test Removal

Remove a test repository or revoke access and verify what happens to its index.

A Safer Repository Layout

A development environment can separate sensitive information from the source tree:

Project
|
+-- src/
+-- tests/
+-- docs/
+-- scripts/
|
+-- secrets
    |
    X Not stored in repository

Application secrets should be injected through appropriate environment or secret-management mechanisms.

This reduces the amount of sensitive information available to repository-based tools.

Common Mistakes

Assuming Only Open Files Are Read

Codebase-aware agents often need broader repository context.

Assuming .gitignore Is an AI Security Boundary

Different tools use different indexing rules.

Ignoring Derived Data

Indexes, embeddings, metadata, and caches can also contain sensitive information.

Forgetting Deleted Files

Git history can contain information that is no longer visible in the current tree.

Giving Every Developer Broad Index Access

Repository and workspace permissions should apply to retrieval as well.

Ignoring Data Retention

Removing a repository does not necessarily answer what happens to previously generated index data.

Putting Secrets in Source Code

An AI coding tool can only protect what the surrounding system prevents it from accessing.

Best Practices for AI Codebase Indexing

Use Least Privilege

Give the tool access only to repositories and directories required for development.

Exclude Sensitive Data

Do not index credentials, private keys, production exports, or other unnecessary sensitive material.

Understand the Full Data Flow

Review:

Repository
Index
Storage
Retriever
Model
Logs
Telemetry

Separate Users and Workspaces

Make sure indexes cannot cross organizational or repository boundaries.

Review Retention

Understand how long indexes and derived data remain available.

Audit Access

Monitor who can connect repositories and retrieve indexed information.

Test Revocation

Verify that removing access actually prevents further retrieval.

Keep Secrets Out of Git

This remains important regardless of which AI coding tool is being used.

Advantages and Disadvantages of Codebase Indexing

Advantages

  • Gives coding agents broader repository context

  • Improves code navigation and dependency understanding

  • Enables questions about relationships across files

  • Supports larger refactoring workflows

  • Reduces the need to manually provide every relevant file

Disadvantages

  • Increases the amount of repository data processed by the AI tool

  • Creates additional sensitive data stores

  • Requires index access controls

  • Creates retention and deletion concerns

  • Can expand the attack surface of the development environment

  • Derived data may require its own security controls

Troubleshooting an Unexpected Indexing Problem

If you discover that an AI coding tool is accessing files it should not:

  1. Identify the repository and workspace involved.

  2. Check the tool's indexing configuration.

  3. Determine which files were indexed.

  4. Review repository permissions.

  5. Check index access controls.

  6. Review retrieval logs if available.

  7. Determine whether the information was sent to an external model.

  8. Remove unnecessary sensitive files from the repository.

  9. Rotate exposed credentials if secrets were involved.

  10. Revoke and recreate access according to the organization's incident-response process.

If sensitive information may have been exposed, treat it as a security incident and follow the organization's established response procedures.

Summary of the Article

Codebase indexing is one of the most important security considerations when using AI coding tools. An agent that understands an entire repository may need to scan and index much more information than the developer explicitly provides in a prompt.

The ZCode codebase indexing incident is a useful reminder to examine the complete data flow rather than focusing only on the AI model. Developers should understand what files are indexed, where the index is stored, who can retrieve it, how long derived data is retained, and what happens when repository access is revoked.

The safest approach is to apply least privilege throughout the workflow. Keep secrets out of repositories, exclude unnecessary sensitive files, protect indexes and derived data, isolate repositories between users and organizations, and verify the actual behavior of the AI coding tool.

The main lesson is simple: when an AI tool indexes your codebase, the index becomes part of your security boundary. Protect it accordingly.