All guides

Create a File-Scoped Custom Agent in Kilo Code

Define a custom Kilo Code agent in a Markdown file that may edit only .md files and everything under docs/, then verify the deny rule with an out-of-scope request.

AINavWritten / Updated Sources checked
On this page

At a glance

To have Kilo Code help with documentation without touching other source files or running commands, create a custom agent (called a mode in the legacy extension). The official documentation says the current VS Code extension is built on the Kilo CLI and defines agents as Markdown files with YAML frontmatter, using permission rules with glob patterns to limit which files can be edited. This tutorial uses an invented project called sample-notes to build an agent that may edit Markdown files anywhere plus every file under docs/. It then covers creating, selecting, testing and disabling the agent. The scope is wider than the docs folder: .md files elsewhere are editable too, and any file type under docs/ is editable.

Workflow

  1. Check where the definition lives

    Confirm the agent file sits in one of the documented directories, such as .kilo/agents/. The filename without .md becomes the agent name.

  2. Check rule order

    Permission rules are evaluated in order and the last matching rule wins, so write broad defaults first and specific exceptions afterward.

  3. Verify with an out-of-scope request

    Request edits to the docs/intro.md title and src/app.js. The allowed edit may proceed; the out-of-scope edit operation should be denied and src/app.js must retain its initial contents.

Each stage cites official sources.

Before you start

  • The Kilo Code extension is installed and open in VS Code, on a practice project or one under version control so changes can be discarded.
  • The practice project must contain docs/intro.md with a title and a non-Markdown src/app.js outside docs/. Create either missing file first and record both initial contents for diff comparison.
  • The YAML frontmatter block starts and ends with standalone --- lines. The Markdown prompt body follows the closing delimiter.
  • You can create folders and files inside the project root.

1. Pick a name and location

In the practice project root, create a .kilo/agents/ folder (one of the documented directories) and a file named docs-only.md. Without .md, the agent name is docs-only. The documentation lists ~/.config/kilo/agent/ for global agents, but for a first try keep the file inside the project so it is easy to delete.

2. Write the basic frontmatter properties

Start the file with a line of ---, then add a description (one sentence shown in the agent picker) and mode: primary so the agent appears directly in the picker. The documentation notes that user-defined agents default to mode all, while primary makes the agent selectable directly.

3. Write edit permissions from broad to narrow

Under permission, in edit, write "*": "deny" first, then "*.md": "allow" and "docs/**": "allow". Because the last matching rule wins, editing is denied by default and only Markdown files and everything under docs/ are opened up. Add bash: deny so the agent cannot run commands. One official example places allow before deny, while the file-restriction section says the last match wins. Follow the deny-first order here and confirm it in step 6.

4. Add a short prompt body and close the frontmatter

End the frontmatter with a line containing only ---, then write a few sentences as the system prompt, for example: you are a documentation helper, only edit Markdown files anywhere or files under docs/, and ask when unsure. The documentation advises keeping prompts focused, as if briefing a colleague. The prompt only guides behavior; the actual restriction comes from the permission rules.

5. Select it in the agent picker

After saving, open the Kilo Code agent picker and choose docs-only. If it does not appear, follow the documented checks: is the file in a recognized directory, is mode primary or all, does each --- sit on its own line, and are keys spelled correctly (top_p, not topP)?

6. Test the boundary with two requests

First request changing the docs/intro.md title to Getting Started, then adding a comment to src/app.js. Inspect the actual edit operations: the first is allowed, the second should be denied and src/app.js unchanged. No specific conversational refusal is required. Investigate a confirmation only if it requests permission for that denied edit: check the loaded docs-only agent, merged permissions from same-named agents and rule order. Stop on failure, correct the configuration and retry.

7. Keep, tighten or disable

If the result is right, keep it. To narrow the scope, shrink the edit globs, for example by removing the "*.md" line to leave only docs/**. To undo it, delete docs-only.md or add disable: true, which removes the agent entirely. If the agent is organization-managed, you cannot remove it yourself and should contact whoever manages it.

Original example

Invented project sample-notes with README.md, docs/intro.md and src/app.js. Create .kilo/agents/docs-only.md containing: --- description: Edits Markdown files and docs/ only mode: primary permission: edit: "*": "deny" "*.md": "allow" "docs/**": "allow" bash: deny --- You are a documentation helper. Only edit Markdown files anywhere or files under docs/. Ask when unsure. With docs-only selected, a request to retitle docs/intro.md should proceed (README.md is editable too), while a request to edit src/app.js should have its edit operation denied, leaving src/app.js unchanged. This is an illustrative configuration; actual behavior in your version may differ. Confirm both test files exist and record their initial contents before testing.

Completion checks

  • docs-only appears in the agent picker and its description matches your description line.
  • Request edits to the docs/intro.md title and src/app.js. The allowed edit may proceed; the out-of-scope edit operation should be denied and src/app.js must retain its initial contents.
  • First request changing the docs/intro.md title to Getting Started, then adding a comment to src/app.js. Inspect the actual edit operations: the first is allowed, the second should be denied and src/app.js unchanged. No specific conversational refusal is required. Investigate a confirmation only if it requests permission for that denied edit: check the loaded docs-only agent, merged permissions from same-named agents and rule order. Stop on failure, correct the configuration and retry.
  • A request to run a command is blocked by bash: deny.
  • Both --- lines stand alone and the keys match the documented property names.

Limits

  • The editable scope is all .md files plus every file under docs/, not the docs folder alone; if some files in docs/ must stay protected, add more specific rules.
  • Permission rules limit the agent's tool access. They do not check whether the documentation it writes is correct, so review the diff before merging.
  • When the same agent name appears at several levels, properties merge rather than replace. An organization-managed agent that shares a name with a built-in agent takes precedence for that organization's members, and individuals cannot remove organization-managed agents.
  • Legacy .kilocodemodes or custom_modes.yaml files are migrated automatically at startup; this tutorial covers only the Markdown-file method.
  • Do not put secrets or account details in the prompt body, because it is injected into the system prompt.

Verification scope

This guide is based only on reading the official documentation. Login, installation, product API execution, file upload and generated output were not tested. The configuration sample is original and illustrative; check interface details against the version you use.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Kilo Code · Official sources
    View details