This guide covers how to configure code-forge environment variables in PyCharm. Three methods are available depending on whether you run code-forge from a Run Configuration, a terminal, or via a .env file.
- PyCharm (Community or Professional) installed
- code-forge installed:
pip install code-review-forge - Python interpreter configured in PyCharm
This method sets environment variables for a specific Run Configuration. It is the most precise option when you want separate configurations for different backends or models.
Steps:
- Open Run > Edit Configurations... (or click the run config dropdown at the top and choose Edit Configurations...)
- Select an existing configuration or click + to create a new one (e.g., Python or Shell Script)
- In the configuration editor, find the Environment variables field
- Click the folder icon next to the field to open the environment variables dialog
- Click + to add a variable:
- Name:
FORGE_LLM_MODEL - Value:
claude-opus-4-5
- Name:
- Add additional variables as needed:
FORGE_BACKEND=claude-apiANTHROPIC_API_KEY=sk-ant-api03-XXXXXXXXX
- Click OK to save
WARNING: PyCharm stores Run Configuration env vars in .idea/ XML files.
Do not commit .idea/workspace.xml or similar files that contain API keys
to version control. Add .idea/ to .gitignore, or use Option 2 (EnvFile
plugin) to keep secrets out of .idea/ entirely.
Example: Shell Script configuration for code-forge
- Script path:
code-forge(or full path fromwhich code-forge) - Script parameters:
review - Environment variables:
FORGE_LLM_MODEL=claude-opus-4-5
Click the green Run button to run the configuration.
The EnvFile plugin (available in the JetBrains Marketplace) lets you
attach a .env file to any Run Configuration. This keeps secrets out of
.idea/ XML files and is the recommended approach for teams.
Install the plugin:
- Open Settings > Plugins (Cmd+, on macOS, Ctrl+Alt+S on Linux/Windows)
- Search for EnvFile and install it
- Restart PyCharm
Create a .env file in your project root:
# .env -- do NOT commit this file
FORGE_LLM_MODEL=claude-opus-4-5
FORGE_BACKEND=claude-api
ANTHROPIC_API_KEY=sk-ant-api03-XXXXXXXXXAdd .env to .gitignore:
.env
Attach the .env file to a Run Configuration:
- Open Run > Edit Configurations...
- Select your configuration
- Click the EnvFile tab (appears after plugin installation)
- Check Enable EnvFile
- Click + and select your
.envfile - Click OK
The variables from .env are now available when the configuration runs.
If you run code-forge from PyCharm's built-in terminal rather than a Run Configuration, set environment variables at the terminal level.
Method A: System shell RC file (recommended)
Configure variables in your shell's startup file so PyCharm's terminal inherits them automatically. This is the same as VS Code Option 1.
For bash (~/.bashrc):
# code-forge configuration
export FORGE_LLM_MODEL=claude-opus-4-5
export ANTHROPIC_API_KEY=sk-ant-api03-XXXXXXXXXFor zsh (~/.zshrc):
export FORGE_LLM_MODEL=claude-opus-4-5
export ANTHROPIC_API_KEY=sk-ant-api03-XXXXXXXXXRestart PyCharm to pick up the new shell environment.
Method B: PyCharm terminal environment settings
- Open Settings > Tools > Terminal
- In the Environment variables field, add:
FORGE_LLM_MODEL=claude-opus-4-5;FORGE_BACKEND=claude-api(separate multiple variables with semicolons) - Click OK and reopen the terminal
WARNING: Do not store API keys in PyCharm's terminal environment settings if they are synced to JetBrains settings storage or a shared settings repository.
From the PyCharm terminal:
code-forge reviewFrom a Shell Script Run Configuration:
Set up a configuration as described in Option 1 and click the green Run button.
Verify the configuration:
echo $FORGE_LLM_MODEL
echo $FORGE_BACKEND
code-forge --versionIf you installed the code-forge Git hooks (code-forge install-hooks),
they run on every commit -- PyCharm's commit dialog shells out to git,
so the hooks fire there too, with no IDE bypass. Non-code commits skip
review by file extension; code commits run receipts, linters, and the
test gate; and every commit message is checked for non-ASCII and
AI-vocabulary. See the VS Code guide's
commit section
for the full behavior and how to respond when a commit is blocked.
PyCharm Run Configurations may use a different PATH than your shell. Specify the full path to code-forge in the script path field:
which code-forge # in the terminal, find the full pathThen use that path in the Run Configuration (e.g., /home/user/.local/bin/code-forge).
PyCharm's terminal may not source ~/.bashrc automatically on some
systems. Open Settings > Tools > Terminal and check the Shell path
setting. For bash, use:
/bin/bash --login
The --login flag forces bash to read ~/.bash_profile (which typically
sources ~/.bashrc).
- Verify Enable EnvFile is checked in the Run Configuration
- Verify the
.envfile path is correct (absolute paths are safer) - Restart PyCharm after installing the plugin
- Check that the
.envfile has no syntax errors (each line:KEY=VALUE)
If you used Option 1 and the key is now in a .idea/ file:
- Remove the variable from the Run Configuration environment fields
- Switch to Option 2 (EnvFile plugin) with a
.envfile - Revoke and rotate the exposed key
- Full configuration reference -- all env vars and gate.yaml
- Claude Code setup -- for Claude Code CLI
- VS Code setup -- for VS Code
- Cursor setup -- for Cursor
- docs/configuration.md -- full environment variable and backend reference,
including the
gate.yamlbackends block and field tables. - The
gate.schema.jsonschema file (written bycode-forge initalongsidegate.yaml) enables IDE tooling that reads yaml-language-server directives. PyCharm ignores the$schemadirective and requires manual schema registration via Settings -> Languages -> JSON Schema Mappings.