# Codemode default activation specification

This document specifies when pi-dent activates the host's `codemode` tool in a session it
loads in. The `codemode` tool itself, its modes, and the `codemode` and `defaultTools`
settings are the host's; pi-dent only turns the tool on when the host left it off by default.
Child sessions inherit `codemode` through the tool cap
([agent-tool.md, tools](agent-tool.md#tools)); this document adds no child-session rule.

## 1. Default activation {#default-activation}

At each `session_start` of the main session, the extension MUST add `codemode` to the
session's active tools (`setActiveTools`, preserving the order of the current active tools and
appending `codemode` last) when all of the following hold:

- The host has the `codemode` tool registered (`pi.getAllTools()` names it).
- `codemode` is not already active.
- The effective settings set no `defaultTools`.
- The effective settings set no `codemode.mode`.

When any condition fails, the extension MUST NOT change the active tools.

> Note (non-normative): a `defaultTools` or `codemode.mode` setting is the user's explicit
> choice; the host applies it, and pi-dent steps out of the way. Without either, the host
> registers `codemode` inactive, and pi-dent's default turns it on.

## 2. Specification gaps {#gaps}

- A tool selection made only on the command line (`--tools`, `--exclude-tools`, `--no-tools`)
  is invisible to the extension, so pi-dent cannot honor it here and still adds `codemode`
  when the settings leave it to the default. A user who selects tools on the command line and
  wants `codemode` off sets `defaultTools` or `codemode.mode`.
