Skip to content

feat: add env configuration option and fix vim.notify scheduling #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

totalolage
Copy link

@totalolage totalolage commented Jun 7, 2025

Summary

This PR adds environment variable configuration support to claudecode.nvim and fixes a critical error with vim.notify calls in fast event contexts.

Changes

1. Environment Variable Configuration

  • Add env field to config for passing custom environment variables to Claude CLI
  • Update init.lua to pass env variables when spawning Claude terminal
  • Update terminal.lua to merge custom env variables into the terminal process
  • Allows users to set custom environment variables like ANTHROPIC_API_KEY

2. Fix vim.notify Scheduling Error

  • Wrap all vim.notify and nvim_echo calls in vim.schedule() to prevent "E5560: nvim_echo must not be called in a fast event context" errors
  • This error occurred when logger functions were called from libuv callbacks

3. Code Cleanup

  • Remove trailing newlines from files
  • Support CLAUDE_TERMINAL_CMD environment variable for terminal command configuration

Usage Example

require('claudecode').setup({
  env = {
    ANTHROPIC_API_KEY = 'your-api-key',
    CLAUDE_MODEL = 'claude-3-opus-20240229',
    -- any other environment variables
  }
})

Testing

  • Tested environment variable passing with various configurations
  • Verified vim.notify scheduling fix resolves the fast event context error
  • Ensured backward compatibility with existing configurations

Copy link
Member

@ThomasK33 ThomasK33 left a comment

Choose a reason for hiding this comment

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

Looks good, I'd personally remove the vim.fn.getenv for the CLAUDE_TERMINAL_CMD and mention it in the docs if someone has that use case.

@ThomasK33
Copy link
Member

Hey @totalolage, you'll have to rebase onto main, as there's a merge conflict.

Could you also investigate the failing tests from the CI run?
You can run those tests locally using make test

@totalolage totalolage changed the title feat: add env configuration option feat: add env configuration option and fix vim.notify scheduling Jun 18, 2025
totalolage and others added 3 commits June 18, 2025 09:21
- Add env field to config for passing environment variables to Claude CLI
- Update init.lua to pass env variables when spawning Claude terminal
- Allows users to set custom environment like ANTHROPIC_API_KEY

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants