Search through code files in the project directory for specific terms.
btw_tool_files_code_search(
term,
limit = 100,
case_sensitive = TRUE,
use_regex = FALSE,
show_lines = FALSE,
`_intent` = ""
)The term to search for in the code files.
Maximum number of matching lines to return (between 1 and 1000, default 100).
Whether the search should be case-sensitive (default is
FALSE).
Whether to interpret the search term as a regular expression
(default is FALSE).
Whether to show the matching lines in the results. Defaults
to FALSE, which means only the file names and count of matching lines
are returned.
An optional string describing the intent of the tool use. When the tool is used by an LLM, the model will use this argument to explain why it called the tool.
Returns a tool result with a data frame of search results, with
columns for filename, size, last_modified, content and line.
You can configure which file extensions are included and which paths are excluded from code search by using two options:
btw.files_code_search.extensions: A character vector of file extensions
to search in (default includes R, Python, JavaScript, TypeScript, Markdown,
SCSS, and CSS files).
btw.files_code_search.exclusions: A character vector of gitignore-style
patterns to exclude paths and directories from the search. The default
value includes a set of common version control, IDE, and cache folders.
Alternatively, you can also set these options in your btw.md file under the
options section, like this:
---
client:
provider: anthropic
tools: [files_code_search]
options:
files_code_search:
extensions: ["R", "Rmd", "py", "qmd"]
exclusions: ["DEFAULT", ".quarto/"]
---Include "DEFAULT" in the exclusions option to use btw's default
exclusions, which cover common directories like .git/, .vscode/.
If the gert package is installed and the project is a Git repository,
the tool will also respect the .gitignore file and exclude any ignored
paths, regardless of the btw.files_code_search.exclusions option.
Other Tools:
btw_tool_docs_package_news(),
btw_tool_env_describe_data_frame(),
btw_tool_env_describe_environment(),
btw_tool_files_list_files(),
btw_tool_files_read_text_file(),
btw_tool_files_write_text_file(),
btw_tool_ide_read_current_editor(),
btw_tool_package_docs,
btw_tool_search_packages(),
btw_tool_session_package_info(),
btw_tool_session_platform_info(),
btw_tool_web_read_url(),
btw_tools()
withr::with_tempdir({
writeLines(state.name[1:25], "state_names_1.md")
writeLines(state.name[26:50], "state_names_2.md")
tools <- btw_tools("files_code_search")
tools$btw_tool_files_code_search(
term = "kentucky",
case_sensitive = FALSE,
show_lines = TRUE
)
})
#> ℹ Indexing files in /tmp/RtmpHZLvWj/file3eb88c36d330f5 for code search
#> Error in duckdb_result(connection = conn, stmt_lst = stmt_lst, arrow = arrow): Invalid Error: HTTP Error: Failed to download extension "fts" at URL "http://extensions.duckdb.org/v1.4.1/linux_amd64/fts.duckdb_extension.gz" (HTTP 500)
#> Extension "fts" is an existing extension.
#>
#> For more info, visit https://duckdb.org/docs/stable/extensions/troubleshooting?version=v1.4.1&platform=linux_amd64&extension=fts
#> ℹ Context: rapi_execute
#> ℹ Error type: INVALID
#> ℹ Raw message: HTTP Error: Failed to download extension "fts" at URL "http://extensions.duckdb.org/v1.4.1/linux_amd64/fts.duckdb_extension.gz" (HTTP 500)
#> Extension "fts" is an existing extension.
#>
#> For more info, visit https://duckdb.org/docs/stable/extensions/troubleshooting?version=v1.4.1&platform=linux_amd64&extension=fts
#> ✖ Indexing files in /tmp/RtmpHZLvWj/file3eb88c36d330f5 for code search [1.2s]
#>