System Prompts
Book supports customizing the agent’s system prompt through SYSTEM.md files, AGENTS.md files, and CLI flags. This allows you to define custom behaviors, rules, and context that persist across sessions.
Quick Setup with /init
Run /init in the TUI (or start fresh) to bootstrap a project automatically. The wizard:
-
Detects the project language from root files (
build.gradle.ktsโ Kotlin,package.jsonโ TypeScript,Cargo.tomlโ Rust,go.modโ Go,pyproject.toml/requirements.txtโ Python,pom.xmlโ Java, etc.) -
Creates
.bk/SYSTEM.mdโ a language-appropriate system prompt template with code standards and a project structure placeholder -
Creates
.bk/tools/โ the directory where you drop.bk.ktsextension scripts -
Creates
AGENTS.mdโ a project instructions file with the detected build command pre-filled
Edit the generated files to refine Book’s behaviour for your project. If a file already exists, /init skips it and reports โ already exists.
File-Based System Prompts
Book automatically discovers and loads system prompts from:
-
~/.bk/SYSTEM.mdโ Global prompt applied to all sessions -
.bk/SYSTEM.mdโ Project-local prompt for the current directory
These files are merged in order (global first, then local), with each file’s content appended with newline separators.
AGENTS.md โ Agent Instructions (per agents.md spec)
Book also automatically loads AGENTS.md files, which follow the community agents.md standard for giving AI agents instructions about a project or user preferences.
Book loads AGENTS.md from:
-
~/.bk/AGENTS.mdโ Global agent instructions applied to all sessions -
<projectDir>/AGENTS.mdโ Project-root agent instructions (the file at the root of your project, not inside.bk/)
Key behaviour: AGENTS.md files are always loaded into context โ even when --system-prompt is used to override SYSTEM.md content. This ensures your project’s AI instructions are never silently dropped.
Example: Create a Project AGENTS.md
Place an AGENTS.md at your project root (alongside README.md, build.gradle.kts, etc.):
cat > AGENTS.md << 'EOF'
# Project AI Instructions
## Mandatory Constraints
- MUST use MockK without annotations (no @MockK)
- MUST use AssertK for assertions
- MUST follow TDD red-green-refactor cycle
## Architecture Rules
- Do NOT introduce dependencies between :domain and :infrastructure
- All filesystem access MUST go through SandboxedOkioFileSystem
EOF
Example: Create a Global AGENTS.md
mkdir -p ~/.bk
cat > ~/.bk/AGENTS.md << 'EOF'
# Global Agent Instructions
- Always ask before deleting files
- Prefer Kotlin idiomatic code over Java-style patterns
- Default to functional programming patterns
EOF
Example: Create a Global System Prompt
mkdir -p ~/.bk
cat > ~/.bk/SYSTEM.md << 'EOF'
# My Global Assistant Rules
- Always provide code examples when explaining concepts
- Prefer functional programming patterns in Kotlin
- Keep responses concise (under 3 paragraphs when possible)
EOF
Example: Create a Project-Local System Prompt
mkdir -p .bk
cat > .bk/SYSTEM.md << 'EOF'
# Project Context
This is a Kotlin-based CLI application using Clean Architecture.
When making changes, respect the module boundaries:
- `:domain` โ Pure business logic (no framework dependencies)
- `:infrastructure` โ Implementations using external libraries
- `:cli` โ User interface and DI wiring
EOF
CLI Flags for System Prompts
You can override or append to the file-based prompts using CLI flags.
--system-prompt <file>
Replaces all SYSTEM.md file content with the content from the specified file. AGENTS.md files are still loaded.
echo "You are a helpful code reviewer." > /tmp/reviewer-prompt.md
java -jar "$(ls -t jvm/cli/build/libs/cli-*.jar | grep -vE 'javadoc|sources' | head -1)" --system-prompt /tmp/reviewer-prompt.md "Review this function"
Note: If the specified file is missing or unreadable, Book will fail with an error and exit.
--system-prompt-append <file>
Appends the file content after all SYSTEM.md and AGENTS.md content.
echo "## Additional Context\n- Focus on performance optimization" > /tmp/extra.md
java -jar "$(ls -t jvm/cli/build/libs/cli-*.jar | grep -vE 'javadoc|sources' | head -1)" --system-prompt-append /tmp/extra.md "Optimize this code"
Note: If the specified file is missing or unreadable, Book will fail with an error and exit.
Merge Order & Priority
The final system prompt is constructed in this order:
-
Base prompt (empty by default)
-
~/.bk/SYSTEM.mdcontent (if exists) -
.bk/SYSTEM.mdcontent (if exists) -
--system-prompt FILE(if provided, replaces steps 2โ3; AGENTS.md still loads) -
~/.bk/AGENTS.mdcontent (if exists โ always loaded, even with--system-prompt) -
<projectDir>/AGENTS.mdcontent (if exists โ always loaded, even with--system-prompt) -
--system-prompt-append FILE(if provided, appends after all of the above) -
Extension
BeforeAgentStarthooks (can still modify the final prompt)
Error Handling
-
Auto-discovered files: If
~/.bk/SYSTEM.md,.bk/SYSTEM.md,~/.bk/AGENTS.md, or<projectDir>/AGENTS.mdare missing or unreadable, Book logs a warning and continues (fail-safe). -
CLI-specified files: If
--system-promptor--system-prompt-appendpoint to a missing or unreadable file, Book prints an error and exits (fail-loud).
Working with Extensions
Extensions registered via .bk.kts scripts can still modify the system prompt through the BeforeAgentStart interceptor. They receive the fully-merged prompt (after all SYSTEM.md files and CLI flags are applied) and can override or append to it.
See the Extension API Guide for details on the BeforeAgentStart interceptor.