.agents/skills/cline-sdk/references/clinecore/gotchas.md
ClineCore holds resources (file watchers, database connections, hub connections). Failing to call dispose() can leave orphan processes and file locks.
const cline = await ClineCore.create({ clientName: "my-app" })
try {
// ... use cline
} finally {
await cline.dispose()
}
ClineCore and @cline/core require Node.js 22 or later. If you're on an older version, you'll get runtime errors. Check with node --version.
Tool policies can be set at two levels:
ClineCore.create({ toolPolicies }) -- applies to all sessionscline.start({ toolPolicies }) -- overrides global for that sessionPer-session policies take precedence.
Built-in tools (bash, editor, read_files, etc.) are not available unless you set enableTools: true in the session config:
await cline.start({
prompt: "Read package.json",
config: {
providerId: "anthropic",
modelId: "claude-sonnet-4-6",
enableTools: true, // required for built-in tools
},
})
Without this, the agent only has access to custom tools you provide via config.tools.
Built-in tools like bash, editor, and read_files operate relative to config.cwd. If not set, they use the process working directory. Always set it explicitly for predictable behavior:
config: {
cwd: "/absolute/path/to/project",
// ...
}
With backendMode: "auto", the first session may be slow if a hub daemon needs to be spawned. For immediate responsiveness:
backendMode: "local" for in-process execution (fastest startup)cline hub ensure CLI commandSessions are stored at ~/.cline/data/sessions/. This includes:
sessions.db - SQLite database with session metadata[session-id].json - Individual message history filesIf you're running in a container or ephemeral environment, these paths may not persist across restarts.
When a tool policy has autoApprove: false and you provide a requestToolApproval callback, the agent loop blocks until your callback resolves. If your callback never resolves (e.g., waiting for user input that never comes), the session hangs.
For automated pipelines, either:
autoApprove: trueClineCore discovers plugins from:
~/.cline/plugins/.cline/plugins/For SDK consumers, pass plugins via extensions: [plugin] or pluginPaths: ["./path"] in the session config.
If a plugin isn't loading, verify:
extensions/pluginPathsmanifest.capabilities arrayapi.register* call in setup() has a matching capability declaredhooks is present on the plugin, "hooks" is in capabilitiesIf your plugins use ctx.workspaceInfo (e.g., to resolve workspace paths), you must set extensionContext.workspace in the session config. Without it, ctx.workspaceInfo is undefined:
await cline.start({
config: {
extensions: [myPlugin],
extensionContext: {
workspace: { rootPath: process.cwd(), cwd: process.cwd() },
},
},
})
The CLI sets this automatically, but SDK consumers must set it explicitly.
cline.send() only works on sessions that are still active. If a session has already completed, send() may return undefined or fail. Check session status with cline.get(sessionId) first.
session.result can be undefined if the session was started but hasn't completed yet (e.g., in a non-blocking hub mode). Check for this:
const session = await cline.start({ ... })
if (session.result) {
console.log(session.result.text)
} else {
console.log("Session started but not yet complete")
}
For long-running sessions, message history grows and eventually exceeds the model's context window. ClineCore handles this via compaction, which summarizes older messages. Configure it via compactionConfig:
config: {
compactionConfig: {
strategy: "summarize",
// ...
},
}
The default strategy works for most cases, but extremely long sessions may benefit from tuning.
api.md - Full API referencepatterns.md - Common patterns../agent/gotchas.md - Agent-level gotchas../tools/REFERENCE.md - Tool troubleshooting../providers/REFERENCE.md - Provider troubleshooting