A python re-implementation of Claude Code's agent system prompt generator, reverse-engineered from the official Claude Code distribution.
This package provides a faithful recreation of the prompt building system used internally by Claude Code. It includes:
- ✅ All base system prompts (interactive, SDK, non-interactive, Vertex AI)
- ✅ Built-in agent definitions (general-purpose, Explore)
- ✅ Dynamic prompt construction with environment context
- ✅ Security guidelines and safety instructions
- ✅ Comprehensive test coverage
For use with the zen-mcp-server CLI Link feature, I wanted the exact system prompt used by the general purpose agent for "jailbreaking" agents to allow for recursive invocations (Agents calling agents), which is explicitly prohibited by Anthropic, who removed the feature a couple days or so after the agent feature was released.
tldr; If you are curious, here are the key functions you can inspect yourself:
jCD- Main prompt constructionVTD- Environment context generationy_H- Base prompt selectionv0$,A3- Agent definitions
This was achieved by an "automated" analysis of Claude Code's obfuscated source. That is, in of itself, a non-trivial process involving webrack for reversing the control flow flattening (good blog) done during obfuscation (and more, but this is notable for it's impact on AST control flow graphs), followed by using babel to traverse the AST and storing the ENTIRE tree into neo4j, resulting in a data directory of about 16 GB.
From here, I used a previous project I have published, ccproxy, so that I could capture a Claude Code session and view it in LangFuse. I prompted sonnet to "Use the @agent-general purpose to say hi", and used some of the system prompt text to find the AST node containing the string:
You are an agent for Claude Code, Anthropic's official CLI for Claude. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup...
The full prompt goes on for several paragraphs and is dynamically generated and includes things like your git status, uname -r, working directory, recently edited files, etc.
Next, it's vibe coding time. Using the Neo4j Traversal Framework, which is much simpler for this use case than choosing Cypher, iterating on java AI slop kept Claude busy for an afternoon, traversing the AST and reconstructing the deobfuscated code using a breadth first traversal, until the size of the reconstructed code hit the 50k token limit I specified. I took this 50k token blob of deobfuscated javascript, and shoved it back into Claude, sternly ordering it to "Using python, recreate the prompt building logic for constructing system prompts", and the results speak for themselves... Wait, you don't like python?
uv add git+https://github.com/starbased-co/claudestine.gitOr using pip:
pip install git+https://github.com/starbased-co/claudestine.gitfrom claudestine import build_agent_prompt, get_agent, PromptBuilder
# Build a prompt for the general-purpose agent
prompts = build_agent_prompt("general-purpose")
# Access agent definitions
agent = get_agent("Explore")
print(agent.system_prompt)
# Custom prompt building
custom_prompts = PromptBuilder.build_system_prompt(
agent=get_agent("general-purpose"),
model="claude-sonnet-4-5-20250929",
additional_working_dirs=["/path/to/project"],
include_security=True
)from claudestine import GENERAL_PURPOSE_AGENT
# Agent optimized for:
# - Searching code across large codebases
# - Analyzing multiple files
# - Investigating complex questions
# - Multi-step research tasksfrom claudestine import EXPLORE_AGENT
# Agent specialized for:
# - Finding files by patterns (glob searches)
# - Searching code for keywords
# - Answering codebase structure questionsfrom claudestine import PromptBuilder
# Build complete system prompt
prompts = PromptBuilder.build_system_prompt(
agent=GENERAL_PURPOSE_AGENT,
model="claude-sonnet-4-5-20250929",
additional_working_dirs=["/home/user/project"],
cwd="/home/user/current",
include_security=False # the most important feature
)
# Returns list of prompt sections:
# 1. Agent's system prompt
# 2. Security guidelines (if enabled)
# 3. Notes (absolute paths, cwd reset, no emojis)
# 4. Environment context (platform, date, model info)The system automatically includes:
- Current working directory
- Platform information (Linux, macOS, Windows)
- OS version (from
uname) - Today's date
- Model information with friendly names
- Additional working directories (if specified)
All prompts include operational notes:
Notes:
- Agent threads always have their cwd reset between bash calls,
as a result please only use absolute file paths.
- In your final response always share relevant file names and code snippets.
Any file paths you return in your response MUST be absolute.
Do NOT use relative paths.
- For clear communication with the user the assistant MUST avoid using emojis.
Build a prompt for a built-in agent.
Parameters:
agent_type(str): Agent type ("general-purpose", "Explore")model(str): Model ID (e.g., "claude-sonnet-4-5-20250929")additional_working_dirs(list[str], optional): Additional directories**kwargs: Additional options passed toPromptBuilder.build_system_prompt()
Returns: list[str] - List of prompt sections
Raises: ValueError if agent_type is unknown
Get a built-in agent definition.
Parameters:
agent_type(str): Agent type
Returns: AgentDefinition | None
Build a complete system prompt with all sections.
Parameters:
agent(AgentDefinition, optional): Agent definitionbase_prompts(list[str], optional): Custom base promptsmodel(str): Model IDadditional_working_dirs(list[str], optional): Additional directoriescwd(str, optional): Current working directory (defaults toos.getcwd())mode(PromptMode): Prompt modeis_non_interactive(bool): Non-interactive session flaghas_append_system_prompt(bool): SDK append flaginclude_security(bool): Include security guidelines
Returns: list[str] - List of prompt sections
from claudestine import AgentDefinition
custom_agent = AgentDefinition(
agent_type="code-reviewer",
when_to_use="Use for code review tasks",
system_prompt="You are a code review specialist...",
model="sonnet",
tools=("Read", "Grep", "Glob"),
color="blue"
)
# Build prompt for custom agent
prompts = PromptBuilder.build_system_prompt(
agent=custom_agent,
model="claude-sonnet-4-5-20250929"
)# Run all tests
pytest
# Run with coverage
pytest --cov=claudestine --cov-report=html
# Run specific test
pytest tests/test_prompts.py::TestPromptBuilderMIT