documentation/docs/guides/managing-tools/code-mode.md
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Code Mode is a method of interacting with MCP tools programmatically instead of calling them directly. Code Mode is particularly useful when working with many enabled extensions, as it can help manage context window usage more efficiently.
:::info This functionality requires the built-in Code Mode extension to be enabled. :::
Code Mode controls how tools are discovered and called:
The Code Mode extension is an MCP server that uses the MCP protocol to expose three foundational meta-tools. When Code Mode is enabled, goose switches to Code Mode. For every request, the LLM writes JavaScript code that goose executes using pctx (Port of Context) (GitHub), a custom Deno-based runtime, to:
Traditional MCP tool calling and Code Mode are two different approaches to the same goal: giving goose access to tools.
| Aspect | Traditional | Code Mode |
|---|---|---|
| Tool Discovery | All tools from enabled extensions, for example: | |
• developer.shell | ||
• developer.text_editor | ||
• github.list_issues | ||
• github.get_pull_request | ||
• slack.send_message | ||
| • ... potentially many more | Code Mode extension's meta-tools: | |
• list_functions | ||
• get_function_details | ||
• execute_typescript |
The LLM uses these tools to discover tools from other enabled extensions as needed | | Tool Calling | • Sequential tool calls • Each result sent to the LLM before the next call | • May require tool discovery calls • Multiple tool calls batched in one execution • Intermediate results are chained and processed locally | | Context Window | Every LLM call includes all tool definitions from enabled extensions | Every LLM call includes the 3 meta-tool definitions, plus any tool definitions previously discovered in the session | | Best For | • 1-3 enabled extensions • Simple tasks using 1-2 tools | • 5+ extensions • Well-defined multi-step workflows |
:::info Text-Only Results Code Mode only supports text content from tool results. Images, binary data, and other content types are ignored. :::
import ContentCardCarousel from '@site/src/components/ContentCardCarousel'; import gooseCodeMode from '@site/blog/2025-12-15-code-mode-mcp/header-image.jpg'; import notMcpReplacement from '@site/blog/2025-12-21-code-mode-doesnt-replace-mcp/header-image.png';
<ContentCardCarousel items={[ { type: 'blog', title: 'Code Mode for MCP', description: 'Learn about the code execution approach to MCP tool calling.', thumbnailUrl: gooseCodeMode, linkUrl: '/blog/2025/12/15/code-mode-mcp', date: '2025-12-15', duration: '5 min read' }, { type: 'blog', title: 'Code Mode Doesn't Replace MCP', description: 'Understanding how Code Mode and MCP work together.', thumbnailUrl: notMcpReplacement, linkUrl: '/blog/2025/12/21/code-mode-doesnt-replace-mcp', date: '2025-12-21', duration: '8 min read' } ]} />