Hooks and Permissions
Hooks execute custom commands at specific points in the agent lifecycle and tool execution. For example, you can collect environment info when an agent starts, or inject formatting instructions on each prompt.
Kiro CLI supports five hook types, each defined in the hooks section of the agent configuration file.
Hook Types
Section titled “Hook Types”| Hook | Trigger point | Use case |
|---|---|---|
agentSpawn | Once at session start | Collect environment info |
userPromptSubmit | On each prompt submission | Change tone, add instructions |
preToolUse | Before tool execution | Execution logging, blocking |
postToolUse | After tool execution | Post-processing results |
stop | On response completion | Post-processing, notifications |
Step 1: agentSpawn Hook
Section titled “Step 1: agentSpawn Hook”Add the hooks section to the agent JSON (above "model": null):
vi ~/.kiro/agents/cloud-ops.json"hooks": { "agentSpawn": [ { "command": "aws sts get-caller-identity" } ]}Restart the agent:
kiro-cli chat --agent cloud-opsAfter restarting, AWS account information is automatically included in context at session start. Verify:
Tell me the current AWS account infoIf the hook executed successfully, the AI should already know the account ID, ARN, and other information.
Step 2: userPromptSubmit Hook
Section titled “Step 2: userPromptSubmit Hook”Create a structured response instruction file:
mkdir -p ~/kiro-cli-workshopcat << 'EOF' > ~/kiro-cli-workshop/structured-response.mdAlways respond in the following format:1. One-sentence summary2. Key details as bullet points3. Security considerations (if applicable)EOFAdd userPromptSubmit below agentSpawn in the agent JSON:
"userPromptSubmit": [ { "command": "cat ~/kiro-cli-workshop/structured-response.md" }]Test:
What is Amazon VPC?Verify the response follows the structured format (summary → bullet points → security considerations) instead of a free-form answer.
Step 3: Verify Hooks
Section titled “Step 3: Verify Hooks”/hooksStep 4: toolsSettings — File Access Control
Section titled “Step 4: toolsSettings — File Access Control”toolsSettings provides fine-grained per-agent tool permission control. Add above "model": null:
"toolsSettings": { "fs_read": { "allowedPaths": ["./**"], "deniedPaths": ["/tmp/*", "~/.ssh/*"] }}Restart Kiro CLI and test:
echo "test" > ~/kiro-cli-workshop/test.txtecho "secret" > /tmp/secret.txtRead test.txt file→ Works normally.
Read /tmp/secret.txt file→ Blocked: Command fs_read is rejected because it matches one or more rules on the denied list
Step 5: toolsSettings — Dangerous Command Blocking
Section titled “Step 5: toolsSettings — Dangerous Command Blocking”Add shell command blocking inside toolsSettings (below fs_read):
"shell": { "deniedCommands": [ "rm -rf( .*)?", "git push( .*)?", "git reset --hard( .*)?" ]}deniedCommands uses regex patterns as a safety mechanism to prevent the AI from accidentally executing dangerous commands.
Restart and test:
What directory am I in?Delete ~/mcp-prompts with rm -rfThe execution is blocked because it matches the rm -rf pattern.
Final Agent JSON
Section titled “Final Agent JSON”This is the final form of the cloud-ops agent configured throughout the Kiro CLI section. The optional MyPromptServer from AWS MCP Integration Step 4 is excluded:
cat > ~/.kiro/agents/cloud-ops.json << 'EOF'{ "name": "cloud-ops", "description": "AWS cloud operations dedicated agent", "prompt": "You are an AWS cloud operations expert.", "mcpServers": { "awslabs.aws-documentation-mcp-server": { "command": "uvx", "args": ["awslabs.aws-documentation-mcp-server@latest"], "env": { "FASTMCP_LOG_LEVEL": "ERROR", "AWS_DOCUMENTATION_PARTITION": "aws" } } }, "tools": ["*"], "allowedTools": [ "fs_read", "fs_write", "execute_bash", "use_aws", "web_fetch", "web_search", "@awslabs.aws-documentation-mcp-server/read_documentation", "@awslabs.aws-documentation-mcp-server/search_documentation", "@awslabs.aws-documentation-mcp-server/recommend", "@awslabs.aws-documentation-mcp-server/read_sections" ], "hooks": { "agentSpawn": [ { "command": "aws sts get-caller-identity" } ], "userPromptSubmit": [ { "command": "cat ~/kiro-cli-workshop/structured-response.md" } ] }, "toolsSettings": { "fs_read": { "allowedPaths": ["./**"], "deniedPaths": ["/tmp/*", "~/.ssh/*"] }, "shell": { "deniedCommands": [ "rm -rf( .*)?", "git push( .*)?", "git reset --hard( .*)?" ] } }, "resources": [], "model": null}EOFCheckpoint
Section titled “Checkpoint”You have completed this step if you have confirmed all of the following:
- Verified hook status with
/hooks - AWS account info available at session start via
agentSpawn - Structured response format applied via
userPromptSubmit /tmp/secret.txtaccess blocked viatoolsSettingsrm -rfcommand blocked viadeniedCommands
For cloud operations labs using pre-built workshop infrastructure (VPCs, Transit Gateway, Steampipe), see What to Do Next.