Skip to content

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.

lua
local claude_code = require("rootbeer.claude_code")

Configure Claude Code

lua
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

lua
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:

lua
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:

bash
# 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-lsp

Pass { 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.

Parameterscfg: claude_code.Config

auto_updates_channel"latest"|"stable"optional
Release channel for auto-updates.
cleanup_period_daysnumberoptional
Session cleanup period in days.
enabled_pluginstable<string, boolean>optional
Explicitly enable or disable plugins by "name@marketplace" key.
envtable<string, string>optional
Environment variables for Claude Code sessions.
hookstable<string, any>optional
Lifecycle hook configurations.
languagestringoptional
Claude's preferred response language.
lspstring[]optional
LSP plugins to enable (e.g. {"pyright-lsp", "typescript-lsp"}). Automatically sets ENABLE_LSP_TOOL=1 in env and adds entries to enabledPlugins.
modelstringoptional
Override default model (e.g. "opus", "sonnet").
pathstringoptional
Where to write settings. Defaults to "~/.claude/settings.json".
permissionsclaude_code.Permissionsoptional
Tool permission rules.

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

contentstring
The markdown content for the instructions file.

claude_code.Permissions

additional_directoriesstring[]optional
Extra directories Claude can access.
allowstring[]optional
Tool patterns to auto-allow (e.g. "Bash(npm run *)").
default_mode"acceptEdits"|"askEdits"|"default"|"plan"|"viewOnly"optional
Default permission mode.
denystring[]optional
Tool patterns to deny (e.g. "Read(.env)").

claude_code.PromptOpts

lspbooleanoptional
Append LSP code navigation guidance to the prompt. Tells Claude to prefer LSP over grep for definitions, references, and type info.
pathstringoptional
Where to write the file. Defaults to "~/.claude/CLAUDE.md".