claude_code
The Claude Code module manages ~/.claude/settings.json and CLAUDE.md from Lua. Use it for permissions, environment variables, hooks, model preferences, and project instructions.
local claude_code = require("rootbeer.claude_code")Configure Claude Code
claude_code.config({
model = "sonnet",
lsp = { "typescript-lsp", "pyright-lsp" },
permissions = {
allow = {
"Bash(npm run *)",
"Bash(cargo *)",
"Edit(*)",
},
deny = {
"Read(.env)",
"Read(.env.*)",
"Bash(curl *)",
},
},
env = {
CLAUDE_CODE_ENABLE_TELEMETRY = "0",
},
})Write Instructions
claude_code.prompt([[
## Conventions
- Use TypeScript with strict mode
- Prefer functional patterns over classes
- Always run tests before committing
- Use conventional commit messages
]], { lsp = true })LSP Support
Claude Code can use Language Server Protocol for semantic code navigation — go-to-definition, find-references, hover types, and real-time diagnostics.
The lsp field enables Claude Code's LSP tool and registers the plugins you want to use:
claude_code.config({
lsp = { "typescript-lsp", "pyright-lsp", "rust-analyzer-lsp" },
})You still need to install both the language server binaries and the Claude Code plugins manually. Rootbeer manages the settings, not the installation:
# 1. Install the language server binary
npm i -g pyright
# 2. Update the plugin catalog and install
claude plugin marketplace update claude-plugins-official
claude plugin install pyright-lspPass { lsp = true } to prompt() and Rootbeer will append a short Code Intelligence section to your CLAUDE.md that tells Claude to prefer LSP over grep for definitions, references, and type info.
API Reference
claude_code.config(cfg)
Writes Claude Code settings to cfg.path as JSON.
Parameters — cfg: claude_code.Config
auto_updates_channel"latest"|"stable"optionalcleanup_period_daysnumberoptionalenabled_pluginstable<string, boolean>optional"name@marketplace" key.envtable<string, string>optionalhookstable<string, any>optionallanguagestringoptionallspstring[]optional{"pyright-lsp", "typescript-lsp"}). Automatically sets ENABLE_LSP_TOOL=1 in env and adds entries to enabledPlugins.modelstringoptional"opus", "sonnet").pathstringoptional"~/.claude/settings.json".claude_code.prompt(content, opts)
Writes the global CLAUDE.md instructions file. This file is loaded by Claude Code at the start of every session and applies across all projects. Use it for personal coding conventions, preferred tools, and project-agnostic guidance. When opts.lsp is true, appends guidance telling Claude to prefer LSP for code navigation.
Parameters
contentstringclaude_code.Permissions
additional_directoriesstring[]optionalallowstring[]optional"Bash(npm run *)").default_mode"acceptEdits"|"askEdits"|"default"|"plan"|"viewOnly"optionaldenystring[]optional"Read(.env)").claude_code.PromptOpts
lspbooleanoptionalpathstringoptional"~/.claude/CLAUDE.md".