New to FORGE? Start a free 30-day trial

Context Configuration

Updated on Oct 1, 2026

Context tells the AI agent which repository files and directories are relevant to a workflow. It also covers the current issue, pull request, ticket, and service that Forge commands work on. This page shows how to configure both.

Prerequisites

  • Forge is initialized in the repository. See Project Setup.
  • The files and directories you reference exist inside the repository.

Context sources

A context source is a file or a directory:

PropertyRequiredDescription
typeYesfile adds one file. directory adds eligible files under the directory, recursively.
pathYesPath that resolves inside the repository
descriptionNoWhy the source matters, up to 500 characters

Scopes

ScopeWhere to configureApplies to
Project[[project.context]] in .forge/config/project.tomlEvery workflow command
Target[[commands.context]] in .forge/config/commands.tomlAll operations of one target, such as code
Operation[[commands.operations.context]] in .forge/config/commands.tomlOne operation, such as code review
Job.forge/work/job_<id>/context/One job, when the directory exists
Command line-c/--context-file <FILE> and --context-dir <DIR>One invocation

For how the scopes merge, deduplicate, and appear in the prompt, see Context Merging Reference.

Configure project context

Add one [[project.context]] entry per source in project.toml:

toml
[[project.context]]
type = "file"
path = "docs/architecture.md"
description = "System architecture and design decisions"

[[project.context]]
type = "directory"
path = "docs/adr"
description = "Architecture decision records"

Configure target and operation context

Add context to a command target and its operations in commands.toml:

toml
schema_version = "2.1.0"

[metadata]
name = "Project Commands"
version = "1.0.0"
author = "Development Team"

[[commands]]
target = "code"
description = "Code generation and review"

[[commands.context]]
type = "directory"
path = "docs/code-patterns"
description = "Reusable code patterns"

[[commands.operations]]
name = "review"
description = "Review code changes"

[[commands.operations.context]]
type = "file"
path = "docs/review-checklist.md"
description = "Required code review checks"

Forge also accepts the legacy [[workflows]] and [[workflows.context]] table names. Use [[commands]] for new configuration.

Add context for one command

Workflow commands accept -c/--context-file and --context-dir. Repeat either flag to add several sources:

bash
frg code review --context-file docs/hotfix-notes.md
frg issue draft --context-file requirements.md --context-dir docs/specs

Utility commands such as frg config validate do not accept these flags.

Validate and inspect context

  1. Validate the configuration:

    bash
    frg config validate

    Validation rejects an unsupported type and a description longer than 500 characters. Forge checks that paths exist and stay inside the repository when a workflow runs.

  2. To see the generated prompt, use the workflow's --print-prompt option:

    bash
    frg code review --print-prompt

    The output can contain paths and project details. Review it before sharing.

How Forge resolves context

  • Forge canonicalizes each path and rejects paths that resolve outside the repository, including through .. or symlinks.
  • Directory sources skip hidden entries, dependency and build directories (such as node_modules and target), binary files, and files over 1 MB. Each directory source collects at most 100 files.
  • Project context is kept separate from target, operation, job, and command-line context. Within the target-operation group, each file appears once.

See Context Merging Reference for the full rules.

Warning: Context paths tell the agent where to look, but they do not limit what the agent can read. Never reference credentials, .env files, or keys. See Agent File System Access.

Set the current issue, PR, ticket, and service

Workflow commands read the current work item from .forge/context.toml or from environment variables. Environment variables take precedence.

CommandEffectEnvironment variable
frg config set-issue <ISSUE_ID>Set the issue ID, such as 123, PROJ-456, or AB#789FORGE_ISSUE_ID
frg config set-pr <PR_ID>Set the pull request numberFORGE_PR_ID
frg config set-ticket <TICKET_ID>Set the ticket ID, such as 123456 or INC0012345FORGE_TICKET_ID
frg config set-service <SERVICE_NAME>Select a monorepo service—
frg config show-contextShow current values and where each value comes from—
frg config clear-issue / clear-pr / clear-ticket / clear-serviceClear one value—
frg config clear-contextClear the issue ID and PR ID—
frg config user --email <EMAIL> [--name <NAME>]Set the user identity for OpenSearch reportingFORGE_USER_EMAIL, FORGE_USER_NAME

The clear-* commands change only .forge/context.toml. Unset environment variables yourself. The user identity persists across frg config clear-context.

For example:

bash
frg config set-issue 42
frg config show-context

Troubleshooting

Context file not found: orContext directory not found:

Cause: The configured path does not exist, or the command runs from a different repository.

Solution:

  1. Check the spelling and case of path.
  2. Use a path relative to the repository root.
  3. Run the command from the intended repository.

resolves outside repository boundary

Cause: The path uses .., an absolute location, or a symlink that resolves outside the repository.

Solution:

  1. Move the file inside the repository.
  2. Update path to a location below the repository root.

unknown variant ..., expected file or directory

Cause: A context entry has an unsupported type.

Solution:

  1. Set type = "file" or type = "directory".
  2. Run frg config validate.

description exceeds 500 character limit

Cause: A context description is longer than 500 characters.

Solution:

  1. Shorten the description.
  2. Run frg config validate.

A directory contributes fewer files than expected

Cause: Forge skips hidden, dependency, build, binary, and oversized files, and stops at 100 files per directory source.

Solution:

  1. Point the source at a narrower directory.
  2. Add important files individually with type = "file" or --context-file.

Context is missing from a command

Cause: The source is configured at a scope that does not apply to the command.

Solution:

  1. Put shared references in [[project.context]].
  2. Put target references in [[commands.context]] and operation references in [[commands.operations.context]].
  3. Inspect the prompt with --print-prompt.

A workflow uses the wrong issue or PR

Cause: An environment variable overrides .forge/context.toml.

Solution:

  1. Run frg config show-context to see the source of each value.
  2. Unset the environment variable, for example unset FORGE_ISSUE_ID.

See Also