这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@K-Mistele
Copy link
Contributor

@K-Mistele K-Mistele commented Oct 18, 2025

What problem(s) was I solving?

The humanlayer claude init command had several issues that needed addressing (ENG-2321):

  1. Couldn't configure Claude Code's thinking mode settings during initialization
  2. Missing critical environment variable CLAUDE_BASH_MAINTAIN_WORKING_DIR for proper bash session handling
  3. Path resolution bug causing failure when installed via npm - command looked for /.claude instead of proper location

What user-facing changes did I ship?

New CLI Flags

Added three new CLI flags to humanlayer claude init:

  • --model <model> - Choose default model: haiku, sonnet, or opus (default: opus)
  • --always-thinking / --no-always-thinking - Enable/disable thinking mode (default: enabled)
  • --max-thinking-tokens <number> - Set maximum thinking tokens (default: 32000)

Environment Configuration

The generated .claude/settings.json now includes:

  • alwaysThinkingEnabled: true (configurable)
  • env.MAX_THINKING_TOKENS: "32000" (configurable)
  • env.CLAUDE_BASH_MAINTAIN_WORKING_DIR: "1" (always set)
  • model: "opus" (configurable)

Bug Fixes

  • Fixed path resolution for npm-installed packages - command now correctly finds .claude directory
  • Improved error messages showing all searched paths when .claude directory cannot be found

How I implemented it

  1. Extended CLI interface (hlyr/src/commands/claude.ts):

    • Added model, thinking mode, and max tokens flags to the init command
    • Added validation for model values (must be haiku/sonnet/opus)
  2. Updated init command logic (hlyr/src/commands/claude/init.ts):

    • Added ModelType type and extended InitOptions interface
    • Implemented interactive prompts for settings when not in --all mode
    • Modified settings.json writing to merge user configuration
    • Added CLAUDE_BASH_MAINTAIN_WORKING_DIR=1 to environment variables
    • Fixed path resolution to check multiple locations:
      • node_modules/humanlayer/.claude (npm install)
      • Repository root .claude (development)
  3. Comprehensive test coverage (hlyr/tests/claudeInit.e2e.test.ts):

    • Added 12 new e2e tests for thinking settings
    • Added 10 new e2e tests for model configuration
    • Updated tests to verify CLAUDE_BASH_MAINTAIN_WORKING_DIR is set
    • Total: 22 tests passing, covering all scenarios

How to verify it

Test npm installation fix

# Create test directory
mkdir /tmp/test-claude-init && cd /tmp/test-claude-init
npm init -y
npm install humanlayer

# This should now work (previously failed)
npx humanlayer claude init --all

Test configuration flags

# Build locally
cd hlyr && npm run build

# Test defaults
./dist/index.js claude init --all
# Verify settings.json has: opus, 32000 tokens, thinking enabled, CLAUDE_BASH_MAINTAIN_WORKING_DIR=1

# Test custom settings
./dist/index.js claude init --all --model sonnet --no-always-thinking --max-thinking-tokens 100000

Verify environment variables

cat .claude/settings.json | jq '.env'
# Should show:
# {
#   "MAX_THINKING_TOKENS": "32000",
#   "CLAUDE_BASH_MAINTAIN_WORKING_DIR": "1"
# }

Automated Testing

  • All 22 e2e tests pass
  • Build completes successfully
  • TypeScript compilation has no errors
  • Path resolution works for both npm and repository contexts

Description for the changelog

  • Added --model, --always-thinking, and --max-thinking-tokens flags to humanlayer claude init for configuring Claude Code thinking mode settings
  • Fixed path resolution bug preventing claude init from working when installed via npm
  • Added CLAUDE_BASH_MAINTAIN_WORKING_DIR environment variable to maintain working directory across bash commands
  • Improved error messages when .claude directory cannot be found

Important

Enhances claude init with new CLI flags for model and thinking mode, fixes path resolution, and updates environment configuration with comprehensive tests.

  • Behavior:
    • Added --model, --always-thinking, and --max-thinking-tokens flags to claude init in claude.ts for model selection and thinking mode configuration.
    • Fixed path resolution in init.ts to correctly locate .claude directory for npm installations.
    • Updated .claude/settings.json to include alwaysThinkingEnabled, MAX_THINKING_TOKENS, and CLAUDE_BASH_MAINTAIN_WORKING_DIR.
  • Implementation:
    • Extended claudeInitCommand in init.ts to handle new flags and update settings.json accordingly.
    • Added validation for model values and interactive prompts for settings.
  • Testing:
    • Added 22 e2e tests in claudeInit.e2e.test.ts for new CLI flags and path resolution.
    • Tests cover model configuration, thinking settings, and environment variable updates.

This description was created by Ellipsis for 309fdd7. You can customize this summary. It will automatically update as commits are pushed.

Adds CLI flags to configure MAX_THINKING_TOKENS, alwaysThinkingEnabled,
and default model when running 'humanlayer claude init'. Defaults to
opus model with 32000 max thinking tokens and thinking mode enabled.

- Add --model, --always-thinking, --max-thinking-tokens flags
- Implement settings.json configuration with user preferences
- Add 22 comprehensive e2e tests
- Update gitignore for local settings

Addresses ENG-2321
@K-Mistele K-Mistele requested a review from dexhorthy October 18, 2025 00:08
@K-Mistele K-Mistele marked this pull request as draft October 18, 2025 00:42
Set CLAUDE_BASH_MAINTAIN_WORKING_DIR=1 in the generated settings.json
to maintain working directory context across bash commands in Claude Code
sessions. This addresses the requirement from ENG-2321 to ensure proper
bash session handling.
Fix path resolution bug where 'humanlayer claude init' was looking
for /.claude instead of ./.claude when installed via npm. The command
now checks multiple possible locations:
- node_modules/humanlayer/.claude (npm install)
- repo_root/.claude (development)

Also improves error messages to show all searched paths when the
.claude directory cannot be found.

Addresses feedback from ENG-2321 where users had to manually copy
the commands directory because init was failing.
@K-Mistele K-Mistele changed the title feat: add thinking mode and model configuration to claude init command feat: enhance claude init with thinking mode, env vars, and npm path fix Oct 18, 2025
@K-Mistele K-Mistele marked this pull request as ready for review October 18, 2025 04:06
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Changes requested ❌

Reviewed everything up to 309fdd7 in 1 minute and 44 seconds. Click for details.
  • Reviewed 386 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. hlyr/src/commands/claude/init.ts:55
  • Draft comment:
    Multiple calls to process.exit are used for error handling and cancellation. Consider refactoring to throw errors instead of directly exiting. This can improve testability and allow for centralized error handling.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_SxKJJiOJ1frxpyqL

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

.option('--always-thinking', 'Enable always-on thinking mode (default: true)')
.option('--no-always-thinking', 'Disable always-on thinking mode')
.option('--max-thinking-tokens <number>', 'Maximum thinking tokens (default: 32000)', value =>
parseInt(value, 10),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider validating the parsed value for --max-thinking-tokens. Using parseInt without a check might allow NaN values to slip through. A check ensuring the value is numeric (and meets the minimum) would be beneficial.

settings.alwaysThinkingEnabled = alwaysThinking
}
if (maxThinkingTokens !== undefined) {
if (!settings.env) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant settings.env initialization: the code checks and assigns settings.env before setting MAX_THINKING_TOKENS and again before setting CLAUDE_BASH_MAINTAIN_WORKING_DIR. Consolidate these checks into one initialization for clarity.

@K-Mistele K-Mistele merged commit 08ff607 into main Oct 21, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants