Overview
Global flags (also called persistent flags) are available to allhc commands. They control authentication, API endpoints, and output formatting. These flags override values from your saved configuration file and environment variables.
Configuration Precedence
Configuration values are resolved in the following order (highest precedence first):- Command-line flags - Flags passed directly to the command
- Environment variables - Shell environment variables
- Config file - Saved authentication configuration (
~/.harness/auth.json)
Command-line flags always take precedence. Use them to temporarily override your saved configuration without modifying the config file.
Available Global Flags
Authentication Flags
Base URL for the Harness API. This is typically
https://app.harness.io for SaaS or your self-hosted Harness URL.Environment variable: HARNESS_API_URLConfig file field: base_urlDon’t include a trailing slash in the URL.
Authentication token (API key) for authenticating with Harness. You can generate an API key in the Harness UI under Account Settings → Access Control → API Keys.Environment variable:
HARNESS_API_KEYConfig file field: tokenHarness account identifier. This is automatically extracted from your authentication token when you run
hc auth login, but you can override it with this flag.Environment variable: None (automatically derived from token)Config file field: account_idScope Flags
Organization identifier. Required for operations that are scoped to an organization. Some commands (like IACM) have a separate
--org-id flag that takes precedence.Environment variable: HARNESS_ORG_IDConfig file field: org_idProject identifier. Required for operations that are scoped to a project. Some commands (like IACM) have a separate
--project-id flag that takes precedence.Environment variable: HARNESS_PROJECT_IDConfig file field: project_idOutput Flags
Format for command output. Determines how results are displayed.Supported values:
table- Human-readable table format (default)json- JSON output for parsing- Other formats may be supported by specific commands
table)Use
--format json when piping output to other tools like jq for processing.Enable verbose logging to console. Shows detailed debug information including HTTP requests, responses, and timing information.Config file field: None (always defaults to
false)Verbose output is sent to stderr, while normal output goes to stdout. This allows you to redirect results while still seeing debug logs.
Examples
Using Saved Configuration
After runninghc auth login, your configuration is saved:
Overriding with Flags
Using Environment Variables
Combining Methods
Different Environments
Debugging with Verbose Mode
JSON Output for Automation
Configuration File
The configuration file is stored at~/.harness/auth.json:
Creating Config File
The easiest way to create the config file is withhc auth login:
Updating Config File
You can update the config file in several ways:- Run
hc auth loginagain - Re-authenticates and updates the file - Edit manually - Open
~/.harness/auth.jsonin a text editor - Use environment variables - Override without modifying the file
Environment Variables Reference
Overrides
base_url from config file. Sets the API base URL.Overrides
token from config file. Sets the authentication token.Overrides
org_id from config file. Sets the default organization.Overrides
project_id from config file. Sets the default project.Resolution Examples
Here’s how different configuration methods interact:Example 1: Flag Overrides Everything
Example 2: Environment Overrides Config
Example 3: Config as Fallback
Example 4: Partial Override
Best Practices
Security
- Use config file for development: Store credentials securely in
~/.harness/auth.json - Use environment variables for CI/CD: Set
HARNESS_API_KEYand other vars in your CI system - Never commit tokens: Add
auth.jsonto.gitignore - Rotate tokens regularly: Generate new API keys periodically
- Use service accounts: Create dedicated service accounts for automation
Organization
- Set defaults in config: Put your most-used org/project in the config file
- Override with flags when needed: Use flags for one-off commands in different scopes
- Use environment variables for scripts: Set env vars at the top of scripts for clarity
Debugging
- Enable verbose mode: Use
--verbosewhen troubleshooting API issues - Check precedence: Remember flags > env vars > config file
- Verify config file: Check
~/.harness/auth.jsonif authentication fails
Troubleshooting
Not logged in. Please run 'hc auth login' first
Not logged in. Please run 'hc auth login' first
Your config file is missing or empty. Run:Or provide credentials via flags:
Authentication failed / Invalid token
Authentication failed / Invalid token
Your token may have expired or been revoked:
- Generate a new API key in Harness UI
- Run
hc auth loginwith the new token - Or update
~/.harness/auth.jsonmanually
Organization/Project not found
Organization/Project not found
Verify the org/project identifiers are correct:Identifiers are case-sensitive and must match exactly.
Config file not being used
Config file not being used
Check that:
- File exists:
ls -la ~/.harness/auth.json - File is valid JSON:
cat ~/.harness/auth.json | jq - Environment variables aren’t overriding it:
env | grep HARNESS
Environment variable not working
Environment variable not working
Make sure the variable is exported:
See Also
- Authentication - Setting up authentication with Harness
- IACM Commands - Using IACM commands
- Registry Commands - Using registry commands