Skip to content

API Reference

Quick Reference

  • SDK Package: @codebuff/sdk (npm)
  • Auth Method: API Key (Bearer token)
  • Response Format: JSON
  • SDK Version: 0.10.7

The primary entry point for programmatic use.

import { CodebuffClient } from '@codebuff/sdk'
const client = new CodebuffClient({
apiKey: string, // Required: API key
cwd: string, // Required: Working directory
onError?: (error) => void, // Optional: Error handler
})

(sdk/src/client.ts)

Execute an agent run.

ParameterTypeRequiredDescription
agentstringAgent ID to run (base, base-max, custom)
promptstringNatural language instruction
agentDefinitionsAgentDefinition[]Custom agent definitions
customToolDefinitionsToolDefinition[]Custom tool definitions
handleEvent(event) => voidProgress event handler

(sdk/src/run.ts)

TypeScript Example
const result = await client.run({
agent: 'base',
prompt: 'Add error handling to all API endpoints',
handleEvent: (event) => {
console.log('Progress:', event)
},
})

Define a custom agent.

FieldTypeRequiredDescription
idstringUnique agent identifier
displayNamestringHuman-readable name
modelstringLLM model identifier (OpenRouter format)
toolNamesstring[]Allowed tools
instructionsPromptstringSystem prompt
handleStepsAsyncGeneratorProgrammatic step generator

(sdk/src/types/)

CommandDescriptionUsage
codebuffStart interactive chatcodebuff [prompt]
codebuff loginAuthenticate via GitHubcodebuff login
codebuff publishPublish agents to Storecodebuff publish [agent-ids]
codebuff --agent <id>Run specific agentcodebuff --agent git-committer
codebuff --continueResume conversationcodebuff --continue [id]
codebuff --freeFree (cost-optimized) modecodebuff --free
codebuff --maxMax (high-capability) modecodebuff --max
codebuff --planPlanning modecodebuff --plan
codebuff --cwd <dir>Set working directorycodebuff --cwd ./project
codebuff --versionPrint versioncodebuff -v

(cli/src/index.tsx:100-127)

CommandDescription
/initInitialize agent infrastructure
/helpShow help information
/imageAnalyze an image
/referralView referral code
/usageCheck credit usage

(cli/src/commands/command-registry.ts)

All 33 built-in tools available to agents:

ToolParametersDescription
read_filespaths: string[]Read contents of multiple files
write_filepath: string, content: stringCreate or overwrite a file
str_replacepath: string, old: string, new: stringReplace text in a file
apply_patchpatch: stringApply a unified diff patch
find_filesquery: stringFind files by name or pattern
globpattern: stringGlob pattern file search
list_directorypath: stringList directory contents
read_subtreepath: stringRead directory tree structure
ToolParametersDescription
code_searchquery: stringSemantic code search
read_docssource: stringRead documentation
web_searchquery: stringSearch the web
ToolParametersDescription
run_terminal_commandcommand: stringExecute shell command
browser_logsCapture browser console logs
ToolParametersDescription
spawn_agentsconfigs: AgentConfig[]Spawn sub-agents
spawn_agent_inlineconfig: AgentConfigSpawn inline sub-agent
end_turnEnd current agent turn
task_completedsummary: stringMark task as complete
ToolParametersDescription
create_planplan: stringCreate execution plan
think_deeplythought: stringDeep reasoning step
add_subgoalgoal: stringAdd a subgoal
update_subgoalid: string, status: stringUpdate subgoal status
write_todostodos: string[]Write todo list
ToolParametersDescription
ask_userquestion: stringAsk user a question
add_messagemessage: stringAdd to conversation
set_messagesmessages: Message[]Set conversation messages
suggest_followupssuggestions: string[]Suggest follow-up actions
set_outputoutput: stringSet agent output
ToolParametersDescription
skillname: stringExecute a skill
lookup_agent_infoid: stringLook up agent details
propose_str_replace...Propose a code change
propose_write_file...Propose file creation
run_file_change_hooks...Run post-change hooks

(common/src/tools/list.ts, common/src/tools/params/tool/)

CodeNameDescription
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid API key
403ForbiddenInsufficient permissions
402Payment RequiredInsufficient credits
429Too Many RequestsRate limit exceeded
500Server ErrorInternal server error

API keys should never be exposed in client-side code. Use server-side proxying or environment variables.