Manage Cody Context

You can control and manage what context from your codebase is used by Cody. You can do this by using Cody Context Filters.

Cody Context Filters is available only for Enterprise users on all supported clients.

Context Filters

Admins on the Sourcegraph Enterprise instance can use the Cody Context Filters to determine which repositories Cody can use as the context in its requests to third-party LLMs. You can use Context Filters if you have:

  • A valid Cody Enterprise license running on Sourcegraph instance version >=5.4.0
  • Running the supported Cody client versions: VS Code >=1.20.0 and JetBrains >=6.0.0
  • Setting the cody-context-filters-enabled feature flag to true

Site admins can customize the cody.contextFilters field in the site configuration to specify which repositories Cody should include or exclude, using the following structure:

JSON
{ // Optional. If defined, it must have at least one // field set (either `include` or `exclude`). "cody.contextFilters": { // Optional. If defined, it must have at least one item. "include": [ { // Required. Should follow the RE2 syntax. "repoNamePattern": "^github\\.com\\/sourcegraph\\/.*" } ], // Optional. If defined, it must have at least one item. "exclude": [ { // Required. Should follow the RE2 syntax. "repoNamePattern": ".*analytics.*" } ] } }

How include and exclude rules work

The include and exclude rules define the repositories Cody can use as context. The rules can be defined in the following combination:

cody.contextFilters field is not defined

By default, Cody can access all repositories for context when making requests to third-party LLMs, with no restrictions on inclusion or exclusion.

Only include rules are specified

Cody is restricted to using content only from repositories whose names match the patterns specified in the include field. No repositories are explicitly excluded if no exclude rules are defined.

The include field can also contain a catch-all pattern (e.g., a regexp that matches any string), allowing Cody to access content from all repositories. A single match in the include rules is enough for a repository to be included. For example:

JSON
{ "cody.contextFilters": { // Only repositories whose names either start with "github.com/sourcegraph/" // or contain "cody" are allowed. "include": [ { "repoNamePattern": "^github\\.com\\/sourcegraph\\/.+" }, { "repoNamePattern": ".*cody.*" } ] } }

These include rules allow Cody only to utilize the repository matching the regexp with full access to fetch context.

Only exclude rules are specified

By default, all repositories are included unless specific include rules are defined. If only exclude rules are specified, Cody will not use content from any repository whose name matches at least one pattern in the exclude field.

The exclude field can also include a catch-all condition, such as a regexp that matches any string. When such a condition is present, Cody is entirely restricted from accessing content from any repository. For example:

JSON
{ "cody.contextFilters": { // All repositories are allowed except for "github.com/sourcegraph/cody-analytics" // or the ones containing "secret" in their name. "exclude": [ { "repoNamePattern": "^github\\.com\\/sourcegraph\\/cody-analytics$" }, { "repoNamePattern": ".*secret.*" } ] } }

Chat behavior when exclude rules are defined

Some Cody features, such as using Prompts, will not work if the exclude rules are defined. They appear to be disabled in the Cody chat interface. If you try running any of these, you'll be prompted with an error message. However, Cody chat will still work; you can use it to ask questions.

Both include and exclude rules are specified

When requesting third-party LLMs, Cody can use content from a repository if its name matches any of the include patterns and does not match any of the exclude patterns. Thus, the exclude rules filter only the repositories allowed by the include rules. For example,

JSON
{ "cody.contextFilters": { // All repositories starting with "github.com/sourcegraph/" are allowed "include": [ { repoNamePattern: "^github\\.com\\/sourcegraph\\/.+" } ], // except for "github.com/sourcegraph/cody-analytics" // and the ones containing "cody" in their name. "exclude": [ { "repoNamePattern": "^github\\.com\\/sourcegraph\\/cody-analytics$" }, { "repoNamePattern": ".*cody.*" } ] } }

In this case, Cody can access content from repositories whose names start with github.com/sourcegraph/. However, it excludes files from repositories with cody in their name.

Cody Context Filters Compatibility Matrix

Cody Context Filters work only on Sourcegraph versions >=5.4.0, VS Code >=1.20.0 and JetBrains >=6.0.0 for Enterprise users.

Depending on the client type, here's a breakdown of versions supported and the behavior for unsupported versions:

ClientClient versionSourcegraph v<5.4.0Sourcegraph v=5.4.0Sourcegraph v=5.4.12303Sourcegraph v>=5.4.0
VS Code< 1.16.XN/ACody not compatibleRespects policy, ask to upgradeNot affected
1.18.0 < and < 1.20.0N/ACody not compatibleRespects policy, ask to upgradeNot affected
>= 1.20.0N/ARespects policyRespects policyNot affected
JetBrains<= 5.5.9N/ACody not compatibleRespects policy, ask to upgradeNot affected
5.5.10 <= and < 6.0.0N/ACody not compatibleRespects policy, ask to upgradeNot affected
>= 6.0.0N/ARespects policyRespects policyNot affected
Previous
Debug Code