codeforge-dev 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/.devcontainer/.env +22 -0
  2. package/.devcontainer/CHANGELOG.md +197 -0
  3. package/.devcontainer/CLAUDE.md +117 -0
  4. package/.devcontainer/README.md +222 -0
  5. package/.devcontainer/config/main-system-prompt.md +502 -0
  6. package/.devcontainer/config/settings.json +47 -0
  7. package/.devcontainer/devcontainer.json +94 -0
  8. package/.devcontainer/features/README.md +113 -0
  9. package/.devcontainer/features/agent-browser/README.md +65 -0
  10. package/.devcontainer/features/agent-browser/devcontainer-feature.json +23 -0
  11. package/.devcontainer/features/agent-browser/install.sh +79 -0
  12. package/.devcontainer/features/ast-grep/README.md +24 -0
  13. package/.devcontainer/features/ast-grep/devcontainer-feature.json +24 -0
  14. package/.devcontainer/features/ast-grep/install.sh +51 -0
  15. package/.devcontainer/features/ccstatusline/README.md +296 -0
  16. package/.devcontainer/features/ccstatusline/devcontainer-feature.json +19 -0
  17. package/.devcontainer/features/ccstatusline/install.sh +290 -0
  18. package/.devcontainer/features/ccusage/README.md +205 -0
  19. package/.devcontainer/features/ccusage/devcontainer-feature.json +38 -0
  20. package/.devcontainer/features/ccusage/install.sh +132 -0
  21. package/.devcontainer/features/claude-code/README.md +498 -0
  22. package/.devcontainer/features/claude-code/config/settings.json +36 -0
  23. package/.devcontainer/features/claude-code/config/system-prompt.md +118 -0
  24. package/.devcontainer/features/claude-code/config/world-building-sp.md +1432 -0
  25. package/.devcontainer/features/claude-code/devcontainer-feature.json +42 -0
  26. package/.devcontainer/features/claude-code/install.sh +466 -0
  27. package/.devcontainer/features/claude-monitor/README.md +74 -0
  28. package/.devcontainer/features/claude-monitor/devcontainer-feature.json +38 -0
  29. package/.devcontainer/features/claude-monitor/install.sh +99 -0
  30. package/.devcontainer/features/lsp-servers/README.md +85 -0
  31. package/.devcontainer/features/lsp-servers/devcontainer-feature.json +40 -0
  32. package/.devcontainer/features/lsp-servers/install.sh +116 -0
  33. package/.devcontainer/features/mcp-qdrant/CHANGES.md +399 -0
  34. package/.devcontainer/features/mcp-qdrant/README.md +474 -0
  35. package/.devcontainer/features/mcp-qdrant/devcontainer-feature.json +57 -0
  36. package/.devcontainer/features/mcp-qdrant/install.sh +295 -0
  37. package/.devcontainer/features/mcp-qdrant/poststart-hook.sh +129 -0
  38. package/.devcontainer/features/mcp-reasoner/README.md +177 -0
  39. package/.devcontainer/features/mcp-reasoner/devcontainer-feature.json +20 -0
  40. package/.devcontainer/features/mcp-reasoner/install.sh +177 -0
  41. package/.devcontainer/features/mcp-reasoner/poststart-hook.sh +67 -0
  42. package/.devcontainer/features/notify-hook/README.md +86 -0
  43. package/.devcontainer/features/notify-hook/devcontainer-feature.json +23 -0
  44. package/.devcontainer/features/notify-hook/install.sh +38 -0
  45. package/.devcontainer/features/splitrail/README.md +140 -0
  46. package/.devcontainer/features/splitrail/devcontainer-feature.json +34 -0
  47. package/.devcontainer/features/splitrail/install.sh +129 -0
  48. package/.devcontainer/features/tree-sitter/README.md +138 -0
  49. package/.devcontainer/features/tree-sitter/devcontainer-feature.json +52 -0
  50. package/.devcontainer/features/tree-sitter/install.sh +173 -0
  51. package/.devcontainer/plugins/devs-marketplace/.claude-plugin/marketplace.json +106 -0
  52. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/.claude-plugin/plugin.json +7 -0
  53. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/hooks/hooks.json +17 -0
  54. package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/scripts/format-file.py +101 -0
  55. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/.claude-plugin/plugin.json +7 -0
  56. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/hooks/hooks.json +17 -0
  57. package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/scripts/lint-file.py +137 -0
  58. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/.claude-plugin/plugin.json +8 -0
  59. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/SKILL.md +387 -0
  60. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/references/cli-flags-and-output.md +312 -0
  61. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/references/sdk-and-mcp.md +569 -0
  62. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/SKILL.md +309 -0
  63. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/references/compose-services.md +438 -0
  64. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/references/dockerfile-patterns.md +340 -0
  65. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/SKILL.md +412 -0
  66. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/references/container-lifecycle.md +388 -0
  67. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/references/resources-and-security.md +444 -0
  68. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/SKILL.md +344 -0
  69. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/middleware-and-lifespan.md +254 -0
  70. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/pydantic-models.md +245 -0
  71. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/routing-and-dependencies.md +255 -0
  72. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/sse-and-streaming.md +318 -0
  73. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/SKILL.md +345 -0
  74. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/references/agents-and-tools.md +271 -0
  75. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/references/models-and-streaming.md +422 -0
  76. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/SKILL.md +220 -0
  77. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/cross-vendor-principles.md +139 -0
  78. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/patterns-and-antipatterns.md +376 -0
  79. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/skill-authoring-patterns.md +356 -0
  80. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/SKILL.md +329 -0
  81. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/advanced-queries.md +314 -0
  82. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/javascript-patterns.md +323 -0
  83. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/python-patterns.md +354 -0
  84. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/schema-and-pragmas.md +326 -0
  85. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/SKILL.md +356 -0
  86. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/ai-sdk-svelte.md +128 -0
  87. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/component-patterns.md +332 -0
  88. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/layercake.md +203 -0
  89. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/migration-guide.md +350 -0
  90. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/runes-and-reactivity.md +328 -0
  91. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/spa-and-routing.md +262 -0
  92. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/svelte-dnd-action.md +181 -0
  93. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/SKILL.md +414 -0
  94. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/references/fastapi-testing.md +411 -0
  95. package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/references/svelte-testing.md +538 -0
  96. package/.devcontainer/plugins/devs-marketplace/plugins/codeforge-lsp/.claude-plugin/plugin.json +7 -0
  97. package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/.claude-plugin/plugin.json +7 -0
  98. package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/hooks/hooks.json +17 -0
  99. package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/scripts/block-dangerous.py +110 -0
  100. package/.devcontainer/plugins/devs-marketplace/plugins/notify-hook/.claude-plugin/plugin.json +7 -0
  101. package/.devcontainer/plugins/devs-marketplace/plugins/notify-hook/hooks/hooks.json +17 -0
  102. package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/.claude-plugin/plugin.json +7 -0
  103. package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/hooks/hooks.json +17 -0
  104. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/.claude-plugin/plugin.json +7 -0
  105. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/hooks/hooks.json +17 -0
  106. package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/scripts/guard-protected.py +108 -0
  107. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272create-pr.md +337 -0
  108. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272new.md +166 -0
  109. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272review-commit.md +290 -0
  110. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272work.md +257 -0
  111. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/plugin.json +8 -0
  112. package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/system-prompt.md +184 -0
  113. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/.claude-plugin/plugin.json +6 -0
  114. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/config/planning-instructions.md +14 -0
  115. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/functional-conjuring-map.md +989 -0
  116. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/hooks/hooks.json +33 -0
  117. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/__pycache__/post-enhance-task.cpython-314.pyc +0 -0
  118. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhance-planning.py +71 -0
  119. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-plan.sh +68 -0
  120. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-task.sh +120 -0
  121. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-plan.py +133 -0
  122. package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-task.py +253 -0
  123. package/.devcontainer/scripts/setup-aliases.sh +80 -0
  124. package/.devcontainer/scripts/setup-config.sh +28 -0
  125. package/.devcontainer/scripts/setup-irie-claude.sh +32 -0
  126. package/.devcontainer/scripts/setup-plugins.sh +80 -0
  127. package/.devcontainer/scripts/setup.sh +58 -0
  128. package/LICENSE.txt +674 -0
  129. package/README.md +267 -0
  130. package/package.json +44 -0
  131. package/setup.js +83 -0
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Auto-lint files after editing.
4
+
5
+ Reads tool input from stdin, detects file type by extension,
6
+ runs appropriate linter if available.
7
+ Outputs JSON with additionalContext containing lint warnings.
8
+ Non-blocking: exit 0 regardless of lint result.
9
+ """
10
+
11
+ import json
12
+ import os
13
+ import subprocess
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ # Linter configuration: extension -> (command, args, name, parser)
18
+ PYTHON_EXTENSIONS = {".py", ".pyi"}
19
+
20
+
21
+ def lint_python(file_path: str) -> tuple[bool, str]:
22
+ """Run pyright on a Python file.
23
+
24
+ Returns:
25
+ (success, message)
26
+ """
27
+ pyright_cmd = "pyright"
28
+
29
+ # Check if pyright is available
30
+ try:
31
+ subprocess.run(
32
+ ["which", pyright_cmd],
33
+ capture_output=True,
34
+ check=True
35
+ )
36
+ except subprocess.CalledProcessError:
37
+ return True, "" # Pyright not available
38
+
39
+ try:
40
+ result = subprocess.run(
41
+ [pyright_cmd, "--outputjson", file_path],
42
+ capture_output=True,
43
+ text=True,
44
+ timeout=55
45
+ )
46
+
47
+ # Parse pyright JSON output
48
+ try:
49
+ output = json.loads(result.stdout)
50
+ diagnostics = output.get("generalDiagnostics", [])
51
+
52
+ if not diagnostics:
53
+ return True, "[Auto-linter] Pyright: No issues found"
54
+
55
+ # Format diagnostics
56
+ issues = []
57
+ for diag in diagnostics[:5]: # Limit to first 5 issues
58
+ severity = diag.get("severity", "info")
59
+ message = diag.get("message", "")
60
+ line = diag.get("range", {}).get("start", {}).get("line", 0) + 1
61
+
62
+ if severity == "error":
63
+ icon = "✗"
64
+ elif severity == "warning":
65
+ icon = "!"
66
+ else:
67
+ icon = "•"
68
+
69
+ issues.append(f" {icon} Line {line}: {message}")
70
+
71
+ total = len(diagnostics)
72
+ shown = min(5, total)
73
+ header = f"[Auto-linter] Pyright: {total} issue(s)"
74
+ if total > shown:
75
+ header += f" (showing first {shown})"
76
+
77
+ return True, header + "\n" + "\n".join(issues)
78
+
79
+ except json.JSONDecodeError:
80
+ # Pyright output not JSON, might be an error
81
+ if result.stderr:
82
+ return True, f"[Auto-linter] Pyright error: {result.stderr.strip()[:100]}"
83
+ return True, ""
84
+
85
+ except subprocess.TimeoutExpired:
86
+ return True, "[Auto-linter] Pyright timed out"
87
+ except Exception as e:
88
+ return True, f"[Auto-linter] Error: {e}"
89
+
90
+
91
+ def lint_file(file_path: str) -> tuple[bool, str]:
92
+ """Run appropriate linter for file.
93
+
94
+ Returns:
95
+ (success, message)
96
+ """
97
+ ext = Path(file_path).suffix.lower()
98
+
99
+ if ext in PYTHON_EXTENSIONS:
100
+ return lint_python(file_path)
101
+
102
+ # No linter available for this file type
103
+ return True, ""
104
+
105
+
106
+ def main():
107
+ try:
108
+ input_data = json.load(sys.stdin)
109
+ tool_input = input_data.get("tool_input", {})
110
+ file_path = tool_input.get("file_path", "")
111
+
112
+ if not file_path:
113
+ sys.exit(0)
114
+
115
+ # Check if file exists
116
+ if not os.path.exists(file_path):
117
+ sys.exit(0)
118
+
119
+ _, message = lint_file(file_path)
120
+
121
+ if message:
122
+ # Output context for Claude
123
+ print(json.dumps({
124
+ "additionalContext": message
125
+ }))
126
+
127
+ sys.exit(0)
128
+
129
+ except json.JSONDecodeError:
130
+ sys.exit(0)
131
+ except Exception as e:
132
+ print(f"Hook error: {e}", file=sys.stderr)
133
+ sys.exit(0)
134
+
135
+
136
+ if __name__ == "__main__":
137
+ main()
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "codedirective-skills",
3
+ "description": "Coding standards and skills for the CodeDirective project",
4
+ "version": "1.0.0",
5
+ "author": {
6
+ "name": "AnExiledDev"
7
+ }
8
+ }
@@ -0,0 +1,387 @@
1
+ ---
2
+ name: claude-code-headless
3
+ description: >-
4
+ This skill should be used when the user asks to "run Claude Code in headless mode",
5
+ "use claude -p for automation", "parse stream-json output from Claude Code",
6
+ "use the Claude Agent SDK", "run Claude Code in CI/CD",
7
+ "configure MCP servers for headless Claude",
8
+ "set up Claude Code permissions for scripts",
9
+ "track Claude Code costs programmatically", or discusses Claude Code
10
+ print mode, non-interactive pipelines, SDK integration in TypeScript or Python,
11
+ structured output with json-schema, or session management for automation.
12
+ version: 0.1.0
13
+ ---
14
+
15
+ # Claude Code Headless
16
+
17
+ ## Mental Model
18
+
19
+ Claude Code is a programmable coding agent. The `-p` (print) flag converts the interactive REPL into a single-shot pipeline tool. The same agentic loop runs — reading files, executing commands, editing code — but the interface is a non-interactive stream rather than a terminal UI.
20
+
21
+ Three output formats control how results are delivered:
22
+ - **`text`** — plain text for human consumption (default)
23
+ - **`json`** — a single JSON object with the result and metadata, emitted after completion
24
+ - **`stream-json`** — newline-delimited JSON events emitted in real time as the agent works
25
+
26
+ The `-p` flag is the foundation. Everything else — output format, permission mode, tool restrictions, session continuation — layers on top to control what the agent can do, what it produces, and how it interacts with the environment.
27
+
28
+ ---
29
+
30
+ ## Print Mode Basics
31
+
32
+ The core invocation is `claude -p "prompt"`. Input can also be piped via stdin:
33
+
34
+ ```bash
35
+ # Direct prompt
36
+ claude -p "Explain the authentication flow in this project"
37
+
38
+ # Piped input
39
+ cat error.log | claude -p "Diagnose the root cause of these errors"
40
+
41
+ # File content as context
42
+ claude -p "Review this code for security issues" < src/auth.py
43
+ ```
44
+
45
+ ### Key Flags
46
+
47
+ | Flag | Description | Example |
48
+ |------|-------------|---------|
49
+ | `--model` | Model selection (alias or full name) | `--model sonnet` |
50
+ | `--max-turns` | Limit agentic turns; exits with error at limit | `--max-turns 10` |
51
+ | `--max-budget-usd` | Maximum dollar spend for the invocation | `--max-budget-usd 5.00` |
52
+ | `--output-format` | Output format: `text`, `json`, `stream-json` | `--output-format json` |
53
+ | `--verbose` | Full turn-by-turn output to stderr | `--verbose` |
54
+ | `--allowedTools` | Auto-approve specific tools (glob patterns) | `--allowedTools "Read" "Bash(git *)"` |
55
+ | `--disallowedTools` | Remove tools from model context entirely | `--disallowedTools "Write" "Edit"` |
56
+ | `--permission-mode` | Permission behavior preset | `--permission-mode acceptEdits` |
57
+
58
+ ### System Prompt Flags
59
+
60
+ | Flag | Behavior | Recommendation |
61
+ |------|----------|----------------|
62
+ | `--system-prompt` | Replaces the entire default system prompt | Full control, but loses built-in capabilities |
63
+ | `--append-system-prompt` | Appends to the default system prompt | Preferred — adds instructions while preserving defaults |
64
+ | `--system-prompt-file` | Replaces with file contents (print mode only) | For version-controlled prompts |
65
+ | `--append-system-prompt-file` | Appends file contents (print mode only) | For version-controlled additions |
66
+
67
+ `--append-system-prompt` is the recommended approach for most automation. It preserves Claude Code's built-in tool usage patterns and project awareness while adding custom instructions.
68
+
69
+ > **Deep dive:** See `references/cli-flags-and-output.md` for the complete flag reference, environment variables, `--debug` categories, `--input-format stream-json` for chaining, and `--fallback-model` for overload resilience.
70
+
71
+ ---
72
+
73
+ ## Output Formats
74
+
75
+ ### text (Default)
76
+
77
+ Plain text output. Suitable for human-readable results and simple shell pipelines:
78
+
79
+ ```bash
80
+ claude -p "What does the main function do?" --output-format text
81
+ ```
82
+
83
+ ### json
84
+
85
+ A single JSON object emitted after the agent completes. Contains the result, cost, usage, and session metadata:
86
+
87
+ ```bash
88
+ result=$(claude -p "Fix the type error in utils.ts" --output-format json)
89
+ echo "$result" | jq '.result'
90
+ echo "$result" | jq '.total_cost_usd'
91
+ ```
92
+
93
+ The JSON output includes `result` (text), `session_id`, `is_error`, `total_cost_usd`, `num_turns`, `duration_ms`, and `usage` fields.
94
+
95
+ ### stream-json
96
+
97
+ Newline-delimited JSON events emitted in real time. Each line is a JSON object with a `type` field. The event sequence is:
98
+
99
+ ```text
100
+ system (init) → assistant/user messages (interleaved) → result (final)
101
+ ```
102
+
103
+ ```bash
104
+ claude -p "Refactor the database module" --output-format stream-json | while IFS= read -r line; do
105
+ type=$(echo "$line" | jq -r '.type')
106
+ case "$type" in
107
+ system) echo "Session: $(echo "$line" | jq -r '.session_id')" ;;
108
+ assistant) echo "$line" | jq -r '.message.content[]? | select(.type == "text") | .text' ;;
109
+ result) echo "Cost: $(echo "$line" | jq -r '.total_cost_usd')" ;;
110
+ esac
111
+ done
112
+ ```
113
+
114
+ ### jq Filtering Recipes
115
+
116
+ ```bash
117
+ # Extract only text output from assistant messages
118
+ claude -p "query" --output-format stream-json \
119
+ | jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "text") | .text'
120
+
121
+ # Extract tool usage
122
+ claude -p "query" --output-format stream-json \
123
+ | jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | "\(.name): \(.input | tostring)"'
124
+
125
+ # Get final cost
126
+ claude -p "query" --output-format stream-json \
127
+ | jq -r 'select(.type == "result") | "Cost: $\(.total_cost_usd) | Turns: \(.num_turns)"'
128
+ ```
129
+
130
+ ### Structured Output with --json-schema
131
+
132
+ Force the final response to conform to a JSON Schema:
133
+
134
+ ```bash
135
+ claude -p "Extract all API endpoints from this project" \
136
+ --output-format json \
137
+ --json-schema '{
138
+ "type": "object",
139
+ "properties": {
140
+ "endpoints": {
141
+ "type": "array",
142
+ "items": {
143
+ "type": "object",
144
+ "properties": {
145
+ "method": {"type": "string"},
146
+ "path": {"type": "string"},
147
+ "description": {"type": "string"}
148
+ },
149
+ "required": ["method", "path"]
150
+ }
151
+ }
152
+ },
153
+ "required": ["endpoints"]
154
+ }'
155
+ ```
156
+
157
+ The `structured_output` field in the result contains the validated JSON. Validation failures trigger retries up to a configurable limit.
158
+
159
+ > **Deep dive:** See `references/cli-flags-and-output.md` for the complete `stream-json` event type catalog with TypeScript type definitions, the full JSON output schema, and `--input-format stream-json` for pipeline chaining.
160
+
161
+ ---
162
+
163
+ ## Permissions and Tools
164
+
165
+ ### Tool Control
166
+
167
+ Three flags control tool availability:
168
+
169
+ | Flag | Effect |
170
+ |------|--------|
171
+ | `--allowedTools` | Auto-approve matching tools (no permission prompt). Supports prefix/glob matching |
172
+ | `--disallowedTools` | Remove tools from model context entirely — the model cannot see or use them |
173
+ | `--tools` | Restrict the set of available tools. `""` = none, `"default"` = all built-in |
174
+
175
+ ```bash
176
+ # Read-only analysis — no file modifications
177
+ claude -p "Analyze code quality" \
178
+ --allowedTools "Read" "Glob" "Grep" "Bash(git log *)" \
179
+ --disallowedTools "Write" "Edit"
180
+
181
+ # Full automation — approve all edits
182
+ claude -p "Fix all lint errors" \
183
+ --allowedTools "Read" "Write" "Edit" "Bash"
184
+ ```
185
+
186
+ ### Permission Modes
187
+
188
+ | Mode | Behavior |
189
+ |------|----------|
190
+ | `default` | Standard prompting for sensitive operations |
191
+ | `acceptEdits` | Auto-accept file edits; prompt for bash commands |
192
+ | `plan` | Planning mode — read-only, no execution |
193
+ | `bypassPermissions` | Skip all permission checks (requires `--dangerously-skip-permissions`) |
194
+
195
+ For trusted automation pipelines, `--permission-mode acceptEdits` combined with `--allowedTools` for specific bash commands provides a safe middle ground.
196
+
197
+ ---
198
+
199
+ ## Agent SDK
200
+
201
+ The Claude Agent SDK provides programmatic access to the Claude Code agentic loop from TypeScript and Python.
202
+
203
+ ### TypeScript
204
+
205
+ ```typescript
206
+ import { query } from "@anthropic-ai/claude-agent-sdk";
207
+
208
+ const messages = query({
209
+ prompt: "Find and fix the bug in auth.py",
210
+ options: {
211
+ allowedTools: ["Read", "Edit", "Bash"],
212
+ permissionMode: "acceptEdits",
213
+ model: "sonnet",
214
+ maxTurns: 20,
215
+ maxBudgetUsd: 2.0,
216
+ systemPrompt: {
217
+ type: "preset",
218
+ preset: "claude_code",
219
+ append: "Focus on security best practices.",
220
+ },
221
+ },
222
+ });
223
+
224
+ for await (const message of messages) {
225
+ if (message.type === "assistant") {
226
+ for (const block of message.message.content) {
227
+ if ("text" in block) process.stdout.write(block.text);
228
+ }
229
+ } else if (message.type === "result") {
230
+ console.log(`\nDone: ${message.subtype} | Cost: $${message.total_cost_usd}`);
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### Python
236
+
237
+ ```python
238
+ import asyncio
239
+ from claude_agent_sdk import query, ClaudeAgentOptions
240
+
241
+ async def main():
242
+ async for message in query(
243
+ prompt="Find and fix the bug in auth.py",
244
+ options=ClaudeAgentOptions(
245
+ allowed_tools=["Read", "Edit", "Bash"],
246
+ permission_mode="acceptEdits",
247
+ model="sonnet",
248
+ max_turns=20,
249
+ max_budget_usd=2.0,
250
+ system_prompt={"type": "preset", "preset": "claude_code", "append": "Focus on security."},
251
+ ),
252
+ ):
253
+ if hasattr(message, "content"):
254
+ for block in message.content:
255
+ if hasattr(block, "text"):
256
+ print(block.text, end="")
257
+ elif hasattr(message, "total_cost_usd"):
258
+ print(f"\nDone: {message.subtype} | Cost: ${message.total_cost_usd}")
259
+
260
+ asyncio.run(main())
261
+ ```
262
+
263
+ The `query()` function returns an async iterator of SDK messages. The `systemPrompt` preset `"claude_code"` preserves the default system prompt; the `append` field adds custom instructions.
264
+
265
+ > **Deep dive:** See `references/sdk-and-mcp.md` for the full SDK options reference, `canUseTool` callback patterns, `ClaudeSDKClient` for multi-turn sessions, custom MCP tools with `createSdkMcpServer`, and `--permission-prompt-tool` for non-interactive permission handling.
266
+
267
+ ---
268
+
269
+ ## Session Management
270
+
271
+ Sessions persist conversation context across invocations. Capture the session ID from JSON output and use it to continue work:
272
+
273
+ ```bash
274
+ # First invocation — capture session ID
275
+ session_id=$(claude -p "Read the auth module and identify issues" \
276
+ --output-format json | jq -r '.session_id')
277
+
278
+ # Continue with the same context
279
+ claude -p "Now fix the issues identified" \
280
+ --resume "$session_id" \
281
+ --output-format json
282
+ ```
283
+
284
+ | Flag | Behavior |
285
+ |------|----------|
286
+ | `--continue`, `-c` | Resume the most recent session in the current directory |
287
+ | `--resume`, `-r` | Resume a specific session by ID or name |
288
+ | `--session-id` | Use a specific UUID as the session ID |
289
+ | `--fork-session` | Create a new session ID when resuming (preserves context, diverges history) |
290
+ | `--no-session-persistence` | Do not save the session to disk (ephemeral, print mode only) |
291
+
292
+ For automation scripts that do not need session replay, `--no-session-persistence` avoids accumulating session files.
293
+
294
+ ---
295
+
296
+ ## CI/CD Patterns
297
+
298
+ ### Basic CI Invocation
299
+
300
+ ```bash
301
+ #!/bin/bash
302
+ set -euo pipefail
303
+
304
+ result=$(claude -p "Review the changes in this PR for bugs and security issues" \
305
+ --output-format json \
306
+ --model sonnet \
307
+ --max-turns 15 \
308
+ --max-budget-usd 3.00 \
309
+ --permission-mode plan \
310
+ --allowedTools "Read" "Glob" "Grep" "Bash(git diff *)" "Bash(git log *)" \
311
+ --no-session-persistence)
312
+
313
+ is_error=$(echo "$result" | jq -r '.is_error')
314
+ cost=$(echo "$result" | jq -r '.total_cost_usd')
315
+ review=$(echo "$result" | jq -r '.result')
316
+
317
+ echo "Cost: \$${cost}"
318
+ if [ "$is_error" = "true" ]; then
319
+ echo "Error during review"
320
+ exit 1
321
+ fi
322
+ echo "$review"
323
+ ```
324
+
325
+ ### Environment Variables
326
+
327
+ | Variable | Purpose |
328
+ |----------|---------|
329
+ | `ANTHROPIC_API_KEY` | API key for authentication |
330
+ | `ANTHROPIC_MODEL` | Default model (overridden by `--model`) |
331
+ | `CLAUDE_CODE_USE_BEDROCK` | Set to `1` for Amazon Bedrock provider |
332
+ | `CLAUDE_CODE_USE_VERTEX` | Set to `1` for Google Vertex AI provider |
333
+
334
+ ### Cost Tracking
335
+
336
+ The `result` message (both JSON and stream-json) includes cost fields:
337
+
338
+ ```json
339
+ {
340
+ "total_cost_usd": 0.042,
341
+ "duration_ms": 15230,
342
+ "duration_api_ms": 12100,
343
+ "num_turns": 5,
344
+ "usage": {
345
+ "inputTokens": 12500,
346
+ "outputTokens": 3200,
347
+ "cacheReadInputTokens": 8000,
348
+ "cacheCreationInputTokens": 4500
349
+ }
350
+ }
351
+ ```
352
+
353
+ The `modelUsage` field (stream-json) breaks down cost per model when fallback models are used. Track `total_cost_usd` across invocations for budget monitoring.
354
+
355
+ ### Error Handling
356
+
357
+ | Exit Condition | `is_error` | `subtype` |
358
+ |---------------|-----------|-----------|
359
+ | Successful completion | `false` | `success` |
360
+ | Max turns reached | `true` | `error_max_turns` |
361
+ | Budget exceeded | `true` | `error_max_budget_usd` |
362
+ | Runtime error | `true` | `error_during_execution` |
363
+ | Schema validation retries exhausted | `true` | `error_max_structured_output_retries` |
364
+
365
+ Check `is_error` and `subtype` to determine whether the invocation completed successfully and route failures appropriately.
366
+
367
+ ---
368
+
369
+ ## Ambiguity Policy
370
+
371
+ These defaults apply when the user does not specify a preference. State the assumption when applying a default:
372
+
373
+ - **System prompt:** `--append-system-prompt` over `--system-prompt` to preserve built-in behaviors
374
+ - **Output format:** `--output-format json` for scripts; `stream-json` when real-time display is needed
375
+ - **Model:** `sonnet` for automation tasks (balanced cost and capability)
376
+ - **Permission mode:** `--permission-mode acceptEdits` for trusted pipelines; `plan` for read-only analysis
377
+ - **Session persistence:** `--no-session-persistence` in CI/CD unless session continuation is required
378
+ - **SDK system prompt:** `{ type: "preset", preset: "claude_code", append: "..." }` to preserve defaults
379
+
380
+ ---
381
+
382
+ ## Reference Files
383
+
384
+ | File | Contents |
385
+ |------|----------|
386
+ | `references/cli-flags-and-output.md` | Complete flag reference, `stream-json` event type catalog with TypeScript types, JSON output schema, jq recipes, `--input-format stream-json` chaining, environment variables, `--verbose` and `--debug` flags |
387
+ | `references/sdk-and-mcp.md` | TypeScript and Python SDK full options, `canUseTool` callback, `ClaudeSDKClient` multi-turn, `createSdkMcpServer` custom tools, `--mcp-config`, `--permission-prompt-tool`, `--agents` subagent definitions, session continuation patterns |