Configuration Structure
The CLI maintains global configuration that applies to all commands:Configuration File Location
Authentication and default settings are stored in:0755 permissions when you first run hc auth login.
Configuration File Format
The
org_id and project_id fields are optional. If not specified, you can provide them via flags or environment variables when needed.Configuration Precedence
Configuration values are loaded in this order (later sources override earlier ones):Precedence Example
Given this configuration file:~/.harness/auth.json
account_id:override_account(from flag)org_id:env_org(from environment)project_id:env_project(from environment)base_url:https://app.harness.io(from config file)
Global Flags
These flags are available on all commands (exceptauth, version, and upgrade):
| Flag | Type | Description | Default |
|---|---|---|---|
--api-url | string | Base URL for the API | https://app.harness.io |
--token | string | Authentication token | - |
--account | string | Account identifier | - |
--org | string | Organization identifier | - |
--project | string | Project identifier | - |
--format | string | Output format (table or json) | table |
--verbose, -v | boolean | Enable verbose logging | false |
Flag Binding
The CLI binds persistent flags directly to the global configuration:Environment Variables
The CLI checks these environment variables during startup:Core Configuration
- API Configuration
- Authentication
- Scope
Environment Variable Loading
The CLI loads environment variables after the config file:Scope Configuration
Harness resources are organized hierarchically:Account-level Resources
For account-level operations, onlyaccount_id is required:
Organization-level Resources
For org-level operations, provide bothaccount_id and org_id:
Project-level Resources
For project-level operations, provide all three identifiers:You can save default scope in the config file during
hc auth login to avoid repeating these flags.Output Format Configuration
Control output format globally or per-command:Global Setting
Format Options
Table Format
Human-readable boxed tables (default)
JSON Format
Machine-readable JSON output
Configuration Loading Flow
Configuration for Different Environments
- Development
- Production
- Europe
Verbose Logging
Enable detailed logging for troubleshooting:- Logs are written to stderr in console format
- HTTP requests and responses are logged
- Timestamps are included (RFC3339 format)
- Errors include stack traces
Command-specific Configuration
Some commands have additional configuration stored in the global config:Best Practices
Use Config File for Defaults
Save your most common settings in
~/.harness/auth.json to avoid repetitive flags.Use Environment Variables for CI/CD
Set credentials and settings via environment variables in automated pipelines.
Use Flags for Overrides
Use command-line flags when you need to temporarily override settings.
Separate Environments
Use different environment variable sets or config files for different Harness environments.
Troubleshooting
Which configuration is being used?
Which configuration is being used?
Run any command with
--verbose to see the configuration values being used:Configuration file not found
Configuration file not found
If the config file doesn’t exist, run:This creates
~/.harness/auth.json with your credentials.Settings not taking effect
Settings not taking effect
Remember the precedence order:
- Flags (highest)
- Environment variables
- Config file
- Defaults (lowest)
How to reset configuration?
How to reset configuration?
Remove the configuration file:Then run
hc auth login to create a fresh configuration.