feat: add TASKMASTER_DOTENV support for custom .env paths #703
+302
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add TASKMASTER_DOTENV support for custom .env file paths
Description
This PR adds support for the
TASKMASTER_DOTENVenvironment variable, allowing users to specify a custom path to their.envfile instead of being limited to the default project root location. This enables better credential management and cost separation between TaskMaster usage and project runtime environments.Motivation
Users often want to manage TaskMaster API keys separately from their project's environment variables to:
Type of Change
Changes Made
Core Implementation
scripts/modules/utils.js: Enhanced theresolveEnvVariablefunction to supportTASKMASTER_DOTENVwith the following precedence order:session.env[key](direct variable lookup in MCP session).envfile fromsession.env.TASKMASTER_DOTENV(MCP session configuration).envfile fromprocess.env.TASKMASTER_DOTENV(shell environment).envfile at project rootprocess.env[key](fallback to system environment)Comprehensive Test Coverage
tests/unit/utils.test.jscovering:Documentation Updates
docs/configuration.md: Added comprehensive documentation including:TASKMASTER_DOTENVfeature in the main configuration section.cursor/mcp.jsonand VS Code.vscode/mcp.json.envfile locationsUsage Examples
CLI Usage
MCP Usage
{ "mcpServers": { "taskmaster-ai": { "command": "npx", "args": ["-y", "--package=task-master-ai", "task-master-ai"], "env": { "TASKMASTER_DOTENV": "/path/to/your/custom/.env" } } } }Testing
Changeset
Backward Compatibility
✅ Fully backward compatible - When TASKMASTER_DOTENV is not set, the system behaves exactly as before, using the project root .env file.
Additional Notes
This implementation provides a clean, flexible solution for credential management that works seamlessly across both CLI and MCP usage patterns. The precedence order ensures that MCP session configurations take priority over system environment
variables, allowing for fine-grained control in multi-session scenarios.
The comprehensive test suite ensures robustness across all edge cases and follows the project's established testing patterns, providing confidence in the feature's reliability.