文件操作
文件操作是 OpenCode 的核心功能之一,支持读取、写入、编辑和搜索文件。
read
读取文件内容
read(filePath="/path/to/file", offset=0, limit=2000)
write
创建或写入文件
write(filePath="/path/to/file", content="file content")
edit
编辑文件内容
edit(filePath="/path", oldString="xxx", newString="yyy")
glob
模式匹配文件
glob(pattern="**/*.ts", path="/project")
grep
内容搜索
grep(pattern="function_name", include="*.{ts,js,py}")
系统操作
执行 Shell 命令和系统操作。
bash
执行 Shell 命令
bash(command="ls -la", description="List files")
interactive_bash
交互式终端
interactive_bash(tmux_command="session-name")
代码分析
使用 LSP 工具进行代码分析、导航和重构。
lsp_diagnostics
代码诊断
lsp_diagnostics(filePath="/path/to/file")
lsp_goto_definition
跳转到定义
lsp_goto_definition(filePath, line, character)
lsp_find_references
查找引用
lsp_find_references(filePath, line, character)
lsp_rename
重命名符号
lsp_rename(filePath, line, character, newName="newName")
lsp_code_actions
代码操作
lsp_code_actions(filePath, startLine, startCharacter, endLine, endCharacter)
会话管理
管理 OpenCode 会话历史和搜索。
session_list
列出所有会话
session_list(from_date="2026-01-01", limit=10)
session_read
读取会话详情
session_read(session_id="ses_xxx", include_todos=true)
session_search
搜索会话内容
session_search(query="关键词", case_sensitive=false)
session_info
获取会话信息
session_info(session_id="ses_xxx")
Web 工具
网页获取、搜索和分析。
webfetch
获取网页内容
webfetch(url="https://example.com", format="markdown")
websearch
网络搜索
websearch(query="OpenCode AI", numResults=10)
look_at
分析媒体文件
look_at(file_path="/path/to/image.pdf", goal="分析内容")
代理命令
启动和管理后台代理任务。
background_task
启动后台任务
background_task(agent="explore", prompt="搜索代码", run_in_background=true)
background_output
获取任务结果
background_output(task_id="bg_xxx", block=false)
background_cancel
取消任务
background_cancel(taskId="bg_xxx")