Code Mode
Code Mode is a built-in tool in Hawa Code that allows the model to invoke configured MCP server capabilities through a piece of JavaScript code and return the execution result to the model for further processing.
- Supports tens of thousands of MCP tools, discovered progressively on demand through Search, without consuming context window space.
- Chains multiple MCP tool calls through code, reducing the back-and-forth transmission of MCP tool call results and lowering token usage.
- Common code logic can be saved and automatically reused, enabling business functionality to self-evolve.

Quick Start
1. Configuration File
Code Mode uses .codemode.json to configure MCP servers; the format is the same as .mcp.json.
The configuration file supports two levels:
- Global configuration:
~/.hcode/.codemode.json - Project configuration:
{project directory}/.codemode.json
Project configuration overrides global configuration.
Example .codemode.json:
{ |
Tip: If
.codemode.jsonis not configured separately, Code Mode will also reuse Hawa Code’s existing MCP configuration (global configuration, project configuration, and.mcp.json).
2. How to Use
Ask Hawa Code to enter Code Mode during a conversation, and the model will automatically generate and execute JavaScript code. You don’t need to manually install plugins or run additional commands.
Typical use cases:
- Invoke an MCP tool to query data
- Combine multiple MCP tools to complete multi-step tasks
- Search for available tools and discover capabilities automatically
Code Format
Code Mode receives an asynchronous JavaScript arrow function and executes it.
You can write the full arrow function directly:
async () => { |
Or you can write only the function body, and the system will wrap it automatically:
const result = await codemode.supabase.list_tables(); |
Invoking MCP Tools
Configured MCP servers are exposed as JavaScript functions in the form codemode.<server>.<tool>.
For example, if a server named supabase has a tool called list_tables, you can call it like this:
async () => { |
If server or tool names contain special characters, they are automatically converted into valid JavaScript identifiers. For example, my-server becomes codemode.my_server.
Discovering Available Tools
Search Tools
If you’re not sure where a capability is located, you can use codemode.search():
async () => { |
The returned results include the tool path, owning server, method name, description, and match score to help you quickly locate the tool you need.
View Tool Details
Use codemode.describe() to view a tool’s type definition and parameter description:
async () => { |
You can also describe an entire server:
async () => { |
Saving and Reusing Code Snippets
You can save frequently used code as a snippet for later invocation:
async () => { |
Snippets are saved in the .codemode-snippets.json file in the project directory and, like MCP tools, can be found through codemode.search() and codemode.describe().
Combining Multiple Tools
The real value of Code Mode lies in its ability to combine multiple MCP tools to accomplish complex tasks.
For example:
async () => { |
Execution Environment Notes
- Code Mode executes code in an isolated Node child process, communicating with Hawa Code through IPC.
- The execution environment does not include Node.js APIs such as
fs,require, orprocess; all I/O must be done through configured MCP tools. - The default timeout for a single execution is 60 seconds; execution will be automatically terminated if it times out.
- Standard JavaScript syntax is supported, but TypeScript type annotations are not supported.
Permissions and Confirmation
Code Mode is a tool that requires user confirmation. It will ask for your permission before executing, and will only run the code after confirmation. If you have enabled automatic permission mode, you may not need to confirm each time when conditions are met.
Common Scenarios
| Scenario | Example |
|---|---|
| Query database | codemode.supabase.query({ sql: "SELECT * FROM users" }) |
| Query GitHub information | codemode.github.search_issues({ query: "repo:owner/repo is:open" }) |
| Combine multiple tools | List tables first, then query each table’s schema |
| Reuse logic | Save frequently used queries as snippets |